I think the move of Kali Linux from bash to zsh is sane. I sometimes have to use the default shell of Linux distribution, especially on servers, and my main pain points with bash are:
- The history is editable by default. If I move to a previous history line and change it, the old line disappears. Hitting Ctrl-c will remove it from the history.
- If I use simultaneous shells (screen, tmux, or several ssh connections), the history saved will be the one of the last shell to quit. The bash config `histappend` should be the default, IMO.
- Most of the time, I search the history by the beginning of the command I just typed, which zsh maps to alt-p and which bash does not map by default. I rarely use the ctrl-r search.
- No way to pause a command and view the man. With zsh, `git clone<alt-h>` will display `man git-clone`, then return to the incomplete command line.
- No way to set a command aside. E.g. if I realise while typing that I'm not in the right directory, `git clone<alt-q>cd src<return>`.
> - The history is editable by default. If I move to a previous history line and change it, the old line disappears.
Press M-r to revert back to the original command.
> - No way to set a command aside. E.g. if I realise while typing that I'm not in the right directory, `git clone<alt-q>cd src<return>`.
Press M-# to comment out the current command and go to a new prompt, then up to get the commented command back, and M-3 M-# to uncomment it and run it (any number works, but 3 is the same key as #).
I don't think bash really fits the type of program to have interactive tutorials. If you are serious about your command-line-fu its worth giving the manual a good read.
My favorite by far is '\e.' or 'M-.' which inserts the last arg from your previous command. Discovering this led me down the bash rabbit-hole of finding new commands, creating my own and really enjoying the bash shell. Did you know you can execute arbitrary code as one of these commands? I had one that ran 'docker ps' so I could list my containers in the middle of typing a command.
> E.g. if I realise while typing that I'm not in the right directory, `git clone<alt-q>cd src<return>`.
With bash I’d just Ctrl+a and type “cd src ;” and then press ctrl+e and continue typing what I was typing.
I got so used to doing it that way, that even after switching to zsh I still do it this way.
The disadvantage of my way of doing it is if you typo the path. But I tab complete pretty much always, so in practice I don’t have the problem of typoing directory names without noticing.
I probably should learn those zsh ways of doing things. Will try to remember to do it the zsh way next time I need to do something like the things you mentioned.
This may be an old fashioned way to do it, but I set aside a command by using ^A (or Home) and the entering : and space:
$ : Command that has an error
I can then cd to the right directory, or fix whatever other problem I had, then use up-arrow to get back to the command, remove the : and space and run it.
The : (no op) command is fairly obscure and some of the other suggestions here are probably better.
I tried using ZSH. My first experience was using a bunch of plugins like zsh spaceship and having the shell slow to a complete halt.
I then used "stock zsh" and running commands was fine except some autocompletes like git-autocomplete were terribly slow and, for example, did not support `git switch`. This broke my workflow and it was easier to just go back to bash than to figure out how zsh works. I found that autocomplete in zsh is a lot more opaque than in bash. I'm sure there are ways to fix it. My way was to switch to bash.
Actually, maybe it's more the fact that at a prominent tech company:
* zsh is the default shell on a large proportion of servers that have read-only /home, so you can't easily change to your preferred shell
* a training guide that many new developers follows states incorrectly that:
> If you are using Bash and you have the option of using ZSH, you should switch to it. ZSH has additional auto-complete and history features that Bash doesn’t have (but don't worry - those features will not be relevant to this tutorial.)
oh-my-zsh seems to be recommended by a lot of developers in this company, even though:
* the default mechanism to install is curl|sh (there is no Homebrew package) on developer machines which have privileged access to a lot of resources
* installing it via its recommended installation procedure on dev machines would violate company policies, whereas installing bash-completion wouldn't
Pause command - I usually hit home, insert a # then enter then man then get the command back and continue. Or tmux it. Didn't realise zsh had that shortcut.
I usually append \, hit enter, then ctrl-c. Run the new command, then up arrow, backspace, enter. You can get closer to the zsh workflow with ctrl-z instead, but that doesn't work if the new command is cd.
Do you actually use zsh? C-o and M-q and M-a and M-h and all the others are really nice, and as far as I know bash has nothing similar (correct me if I'm wrong). You don't NEED any of these niceties but they're very nice.
- The history is editable by default. If I move to a previous history line and change it, the old line disappears. Hitting Ctrl-c will remove it from the history.
- If I use simultaneous shells (screen, tmux, or several ssh connections), the history saved will be the one of the last shell to quit. The bash config `histappend` should be the default, IMO.
- Most of the time, I search the history by the beginning of the command I just typed, which zsh maps to alt-p and which bash does not map by default. I rarely use the ctrl-r search.
- No way to pause a command and view the man. With zsh, `git clone<alt-h>` will display `man git-clone`, then return to the incomplete command line.
- No way to set a command aside. E.g. if I realise while typing that I'm not in the right directory, `git clone<alt-q>cd src<return>`.