6 ms·
For reasons like this, I almost wish software came with a "list of unexpected side-effects of using this software". Take bash, for instance - each time you run
by don-code 5y ago
For reasons like this, I almost wish software came with a "list of unexpected side-effects of using this software".
Take bash, for instance - each time you run a command (this list is nonexhaustive; I'd love to know others):
1. If you have a `PROMPT_COMMAND`, it'll be run.
2. The command will be echoed to your history file.
3. If you hit <TAB>, arbitrary functions might run (for completion).
I don't know what zsh may do on top of this, but my guess is that it's significantly more than bash. That's not a demerit to zsh - that's exactly what it should do - but visibility would be nice.
- eyelidlessness 5y agoFor that matter, it would be nice if software with side effects of this sort disclosed them at runtime by default. For all its faults, this is something npm gets (partly) right. Partly, in this case, because it does print the commands it runs and their output, but it doesn’t tell you why. I’m sure this would be overly verbose for most users, who would likely turn it off, but it would still be educational in terms of the huge set of implicit side effects normal every day software produces.
- eiginn 5y agoIn Zsh setting '-x' on an interactive shell will also show you what is executed for prompts, completion, and any hooks (probably other things too)
- gryn 5y agosame for bash
- 0xcde4c3db 5y ago> 2. The command will be echoed to your history file. Important caveat: this goes into an in-memory history buffer; the history file is written when bash exits. This means that if you have multiple shells open, you will lose the history from all but the last shell to exit.
- theli0nheart 5y agoThis is the default, but you can get around this behavior by writing to history immediately.
- pabs3 5y agoHow do you do that?
- jefftk 5y agoYes! If you want to maintain a full history (and you should!), you can make bash consistently log it: promptFunc() { # right before prompting for the next command, save the previous # command in a file. echo "$(date +%Y-%m-%d--%H-%M-%S) $(hostname) $PWD $(history 1)" \ >> ~/.full_history } PROMPT_COMMAND=promptFunc
- pabs3 5y agoInstead of using that echo, you can tell bash to append the history: history -a Setting the histappend option does the append thing on exit: shopt -s histappend Instead of the ~/.full_history file you can just set your normal history to infinite: HISTFILESIZE=-1 HISTSIZE=-1
- jefftk 5y agoUnfortunately, with this approach it only takes one invocation of bash without your .bashrc (or otherwise without HISTFILESIZE=-1) to truncate your history to 500 lines: $ man bash /HISTFILESIZE The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is 500. The history file is also truncated to this size after writing it when an interactive shell exits. (I also like that with my approach I also get the timestamp and current direct rate.)