Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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 #).


Oh look! Magic!

I think if bash had some interactive help with this magic when it appears then it would be a lot more helpful and a lot less magical.


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.

bind -P | grep '\\e'

https://www.gnu.org/software/bash/manual/

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.


If you use && instead of ; then you won't have the typo problem.


True, but that means typing another character and I am lazy :p


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 do the same but with a # to comment it out


Not to mention:

- Oh-my-zsh has a lot of plugins for auto-completion

- FZF (fuzzy finder), for command history is a big hit (supports bash too)


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.

(Now I use magit so the need is lessened.)


> - Oh-my-zsh has a lot of plugins for auto-completion

As does bash-completion, which is available in many (but not all :-/) Linux distros and via Homebrew on MacOS and [pre-dates](https://github.com/scop/bash-completion/tree/09b07d57a7031d9...) [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh/tree/5da20b9dddb1f7a91106...) by about 6 years.

But, zsh users and oh-my-zsh fan-boys seem to be entirely ignorant of bash-completion.


I never understand comments like these. Why do you have to twist this to be about "ignorant fan boys"?

Not enough drama in the world already?


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


Sorry, but I've read too many posts that say "bash sucks, it doesn't do <thing that bash has done for years before zsh did it> like zsh does".


And there's a constructive way to respond to those posts, if you must absolutely respond.

Yours ain't it.


Ironic response.


Fair point


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.


Instead of home+#+enter try alt-#


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.


> No way to pause a command and view the man.

^A, ^K, m, a, n, space, ^Y, enter. Upon exit, ^Y.

> No way to set a command aside.

^A, ^K. Grab it again with ^Y.

(Yes, these are all readline shortcuts. If you think they’re a bit long, bind them to something shorter in your inputrc.)


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 comment you are responding to talks about Bash.


It talks about bash workarounds for zsh features.


At the end of the day, whatever shell best suits you basically boils down to usage, habits and how much willing you are to tweak it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: