9 ms·
Zsh is your friend.
- jfmercer 15y agobash's spy equivalent in Jason Bourne. zsh can't compete with that.
- steder 15y ago+1 for actually giving me a couple reasons to try zsh. Of course I'd be surprised if many of these features aren't already hacked into some bash guru's dotfiles but, that said, more autocompletions without writing them myself is always nice.
- LeafStorm 15y agoWhile from what I have read about it zsh is a nice shell, it doesn't deal with what I find to be the biggest problem with bash, sh, and just about every shell that isn't fish: the horribly ugly and inconsistent syntax. And I think it's rather sad that on what is supposedly the most advanced shell of our generation, you still have to deal with a thousand ridiculous redirections and quoting styles, different delimiter keywords for every control structure ("fi?" "done?" "esac?" Why not just freaking "end?"), and rules for expanding variables that come back to bite you in the rear whenever you have spaces, quote characters, or anything besides a run of letters, numbers, and a select few punctuation marks in your filenames or other variables.
- googletron 15y agoI think your complaining more about shell scripting rather than the terminal use itself.
- ismarc 15y agoI think you're underestimating how frequently some folks do things like: for x in 'seq 1 100'; do echo "something with $x"; done (Please forgive lack of backticks on my cellphone keyboard) Or many variations, like every line in a file, or result of a command piped to sed or awk and then processed. Init scripts are about the only shell scripts I write anymore, but I use frequently use it from the commandline, typically on remote terminals.
- fluidcruft 15y agoJust forget backticks even exist. I now always use $(cmd) instead of `cmd`. Much easier to read and it fits in better with process substitution <(cmd). More importantly it all nests sanely $(cmd1 $(cmd2)) and works well in quotes "Blah: $(cmd1 $(cmd2))".
- deleted 15y ago[deleted]
- kruhft 15y agoOnce you learn the zen of shell script, like any programming language, those problems pretty much go away. Shell script is a tiny language packed with features and can be learned through constant use in a week, but like any language, it takes time to master. It's incredibly powerful for interactive use and data manipulation combined with the standard Unix tools and sometimes pulling out perl or python is more work than just banging out a pipeline on the command line. Quoting does take some time, but just remember that when in double to quote your variable expansions with double quotes. There's more too it, but that's a good rule to start with.
- jlebar 15y agoMaybe I lack the proper zen, but I haven't found this to be true at all. Here's a good bash FAQ. It contains questions like "how do I use associative arrays", with answers like "this is a complex question." I don't even have to ask in any half-decent scripting language. http://mywiki.wooledge.org/BashFAQ/ http://mywiki.wooledge.org/BashFAQ/
- kruhft 15y agoI reccommend ksh over bash. That's all I use these days. It was sh done right, although it does have a bit of history to it for compatibility. To use associative arrays in ksh: typeset -A table column="name" table[$column]="value" echo ${table[$column]} ksh is much more decent than bash, although I reccommend using in an emacs M-x shell buffer for better command line editing. Edit: forgot to dereference column when setting value in table.
- Lewisham 15y agoThe thing I like about fish is the easy history nav. I type "git" and press Up, and I get to go through my history of anything that started with "git" very quickly. I'll often remember I typed an svn command three weeks ago, but forget the parameters, and I'll have it back within 15 seconds. It's like magic!
- CJefferson 15y agoThis is indeed a lovely feature I couldn't live without. In bash, you can get it by adding the following to your .inputrc (at least on mac terminal) "\e[B": history-search-forward "\e[A": history-search-backward
- deleted 15y ago[deleted]
- ohgodthecat 15y agoI believe in bash and zsh the default is ^R and ^S
- shabble 15y agoexcept a huge number of terminal emulators still reserve ^S/^Q for XON/XOFF software flow-control[1]. stty -ixon lives in my init scripts for that reason. [1] https://en.wikipedia.org/wiki/Software_flow_control https://en.wikipedia.org/wiki/Software_flow_control
- sandGorgon 15y agoin zsh you get it by adding bindkey "^[[A" history-beginning-search-backward bindkey "^[[B" history-beginning-search-forward
- gkop 15y agoI add these lines so the left- and right-arrows still work correctly: "\e[C": forward-char "\e[D": backward-char
- deleted 15y ago
- ramLlama 15y agoI have been using fish for several years now. It's community is a fraction of zsh, bash, and others, and I've tried to go back to them, mostly out of misplaced "everyone else is doing it" mindset Fish is a great shell. It's a modern shell, that uses colors, UTF, and processing power that didn't exist when the others were designed. I feel the best thing about it is the sane defaults and large number of prebuilt completions. For any other shell, I have to dive into bashrc's and esoteric commands to get what I want. Fish just does what I want. It's made me far more productive, and for that, it gets my best shell award. Its scripting support is good, very similar to other shells. Yes, the syntax is non-compatible, and not even POSIX. But, it makes more sense. Besides, for anything except the simplest of scripts, I use lua. I doubt you'd want to use bash to do something very complicated. Some people want their shell scripts to be compatible and do a lot of cool things. I feel that the days of a shell being used for scripting are past. For me, a shell is a way of interacting with the system. Fish does this really well. Scripting is a slight afterthought, as it should be.
- mixmastamyk 15y agoSame here, the syntax highlighting rocks (I couldn't go back now), and I do like the shared history. For simple non-interactive scripts I still use bash because of its ubiquity, python for complex needs.
- pyre 15y ago> I do like the shared history. Maybe the implementation is different, but ZShell has shared history. (Just noting that this is not a 'fish rocks other shells because of X' feature)
- mixmastamyk 15y agoYep, this thread is currently under several comments talking/complaining about zsh shared history. I'm in the "appreciate" camp.
- andrewflnr 15y agoDo you have to do anything weird to Lua to make it work as a system scripting language? Do you just use the built in OS interfaces?
- jff 15y agoTry Plan 9's "rc". It has a more C-like syntax, so you write things like "for (i in `{seq 1 100}) { echo $i }"; I really enjoy writing in rc.
- naner 15y agoHow is that better than bash or zsh: for i in `seq 1 100`; do echo $i; done zsh: for i in `seq 1 100`; echo $i
- nimrody 15y agoIt's sort of ok when its `do... done`. But what about `if`..`fi` or `case`..`esac`. +1 for rc.
- wonderzombie 15y agoHonestly, I find that stuff pretty easy to remember. And is it that ugly, in the grand scheme of ugly shell syntax? :) I mean, what about [[ ]] vs. (( )) vs. [ ]? Or the beginning of a case statement? Those always get me since I don't use them often enough for them to stick.
- pyre 15y ago[ ] is easy. It's just the 'test' command.[1] % which \[ /usr/bin/[ All of the other syntax is shell-specific (run via built-ins), so that can vary, and be a little more obtuse. [1] Albiet with some minor differences: % if [ -d /tmp ]; then echo "TRUE"; fi TRUE % if test -d /tmp ]; then echo "TRUE"; fi test: too many arguments % if test -d /tmp; then echo "TRUE"; fi TRUE % diff /usr/bin/{test,\[} Binary files /usr/bin/test and /usr/bin/[ differ % man \[ No manual entry for [
- ori_b 15y agoYes. rc has less of it, fewer edge cases, etc. Even though it still has lists implemented sanely, a full set of redirects, etc: $ 9 man rc | wc -l 496 $ man bash | wc -l 4890 Fewer interactive features as well, unfortunately. But it's small enough to keep in your head, and I find that makes it far more pleasant to use.
- adavies42 15y agothe problem is there are really two things that most shells are trying to simultaneously optimize for--interactive and scripted use. sometimes these conflict in annoying ways--i think the main reason arrays are so obnoxious to use in bash is that their syntax collides badly with glob syntax. some shells that make excellent script languages are terrible for interactive use--a stock ksh, even ksh93, is pure torture for someone who grew up on bash and zsh and expects completion, history, a nice prompt, decent command editing, etc. (i'm not sure if the reverse is precisely true, though certainly there are interesting programming features in ksh that are absent in zsh--discipline functions and so on.)
- bwarp 15y agoYou've obviously never used PowerShell then if you think *sh are horrible ugly and inconsistent!
- Wilya 15y agoFunnily enough, I find that the autocorrection tends to get in my way more often than not. Being prompted if I meant 'git' when I type 'gut' interrups my thinking flow, while 'command not found' doesn't. And the autocorrect is very bad for cp/mv ('mv test test1' will likely ask me if I meant 'test' instead of 'test1'). That being said, I'm a happy zsh user, for all it provides. Autocorrection is just one of the only things that, in my opinion, don't work well, so it's strange to market them.
- deleted 15y ago[deleted]
- sjs 15y agosetopt correct # try to correct spelling... setopt no_correctall # ...only for commands, not filenames https://github.com/samsonjs/config/blob/master/zsh/zshrc#L111-112 https://github.com/samsonjs/config/blob/master/zsh/zshrc#L11... [...] alias cp='nocorrect cp' # don't correct spelling for 'cp' alias mkdir='nocorrect mkdir' # don't correct spelling for 'mkdir' alias mv='nocorrect mv' # don't correct spelling for 'mv' https://github.com/samsonjs/config/blob/master/zsh/zshrc#L202-213 https://github.com/samsonjs/config/blob/master/zsh/zshrc#L20...
- dbbo 15y agoDue to the poor spelling and grammar, gross oversimplification of zsh's advantages, and the inclusion of oh-my-zsh as a reason to switch, I found this post insulting (as a long time zsh user). And I actually want more people to use zsh, because that would mean more collaboration, more tips, and better script compatibility.
- mgrouchy 15y agoIf my grammer is shitty, thats fine, never said my grammar/spelling/etc was amazing, just Zsh. This post was intended as a nice introductory shoutout to Zsh. Oh-my-zsh is a great way for someone to get started with zsh if they wanted to try it out. It was never meant to be a complete guide to Zsh, and I wasn't going to list all the features, just a few that people who don't know anything about Zsh might be interested in. But Hey, thanks for trying to give me a hard time. Stay classy.
- dbbo 15y agoWhen you submit an article that you wrote to HN you could at least have the decency to spend 5 minutes proofreading it, couldn't you? oh-my-zsh is a great way for lazy people to get fancy features without having to look at the easily accessible manual ( http://zsh.sourceforge.net/Doc/ http://zsh.sourceforge.net/Doc/ ) or even the user friendly guide ( http://zsh.sourceforge.net/Guide/ http://zsh.sourceforge.net/Guide/ ). I never said I expected you to list every feature. That's a pretty ridiculous hyperbole on your part. I also wasn't "trying to give [you] a hard time". I was merely expressing my opinion. I'm sorry that you can't handle any criticism.
- richardlblair 15y agoDue to the major douchebaggery, gross misunderstanding of the purpose of this article, and inclusion of your "long time user" status, I can't take you comment seriously. Perhaps the purpose of this article is too complicated for your oversimplified brain. As a "long time" computer user I appreciate Mr. Grouchy taking the time to outline some of the finer things zsh has to offer. If you REALLY wanted people to adopt zsh, and grow the community, you should probably try to list some other things that you enjoy. But Hey, thanks for trying to integrate yourself. Stay Classy.
- jgrahamc 15y agoI like zsh. Probably my favorite feature is that it will autocomplete paths/filenames in an scp command on the remote end if authentication is done with keys. Also you can do stuff like /u/l/b and hit TAB.
- riobard 15y agoProbably my favorite feature is that it will autocomplete paths/filenames in an scp command on the remote end if authentication is done with keys. This is possible in Bash too with bash-completion.
- bryanlarsen 15y ago- I'm using bash on Ubuntu. When I type "kill <tab>" I get a list of process numbers, not the list of files in my current directory as you imply. - shared history sounds like a bug, not a feature. I have long lived terminals open, each dedicated to a specific purpose. Shared history would intermingle them. - typing `gut` in bash gives me: No command 'gut' found, did you mean: Command 'cut' from package 'coreutils' (main) Command 'get' from package 'code-aster-run' (universe) Command 'gout' from package 'scotch' (universe) Command 'git' from package 'git' (main) Command 'gpt' from package 'gpt' (universe) Command 'gst' from package 'gnu-smalltalk' (universe) You're batting 0/3. Certainly there must be some advantages to ZSH, but you haven't listed any yet. (Note that I didn't have to configure any of this. Ubuntu probably did, but I didn't).
- ohgodthecat 15y agoShared history can be either a burden or a godsend, I like it but I usually just end up using whatever basic bash shell I'm on without a custom config as most of the things I do are remote. The zsh autocorrect works much differently than what you have given. You have shown a feature of ubuntu (and probably debian) that looks for packages matching/close to your given command but what zsh does is give you, depending on your chosen settings, full autocorrect. Where you may be able to type gut status and get No command found the setup in zsh would allow either for gut status to be autocorrected to git status or would ask you if you meant git status while waiting for a confirmation.
- 0xABADC0DA 15y agoZsh has knobs for shared history. You can configure all terminals to have the same history at the same time, but I have it set to add history to the .zsh_history file immediately, but each shell gets it's own history. So ctrl-r in a shell lists commands entered into that shell (or preexisting when it started), and opening a new terminal starts with the shared history from all terminals. This is really the best of both worlds. Also there's a knob to only add a command if it isn't in the history, so no scrolling back over a dozen "cd .." or whatever. Zsh has floating point math, for instance $((1.0/2)) is 0.5 instead of an error. This comes in handy sometimes in simple scripts. Zsh is significantly faster. Zsh autocomplete is much more advanced. Bash may have copied the pid completion and some other easy ones, but zsh has all sorts of completion hooks, for instance "svn help ch<tab>" expands to "changelist". It also runs --help and parses out GNU style help text for completing options. Zsh completion also has optional Windows-style cycle mode, so you can do "prefix<tab><tab>"... and cycle through the matches instead of prefix<tab>a<tab><tab>b<tab>-<tab>" like in bash. I think you can actually make bash do this but it's some obscure key binding. ...basically zsh is just a bit better at everything. {edit: oops meant to reply to grandparent}
- babs474 15y agoIs anybody else addicted to shell mode within emacs? I love having the shell as just another buffer right in the editor. Easy history searchability, copy and paste between code and various repls or SQL prompts, and all the other full editor features available at the prompt.
- drothlis 15y agoI like the idea, but I'm too used to bash's autocompletion (the Emacs-provided autocompletion is similar but not quite the same), the autocd option, CDPATH, etc. And changing directories in the shell with anything other than cd (pushd, or an alias or script) confuses Emacs's directory completion. The last couple of days I've been trying terminal-mode rather than shell-mode, and it works much better. Many standard Emacs keybindings get remapped though.
- drothlis 15y agoEdit: I meant term-mode (M-x term), not terminal-mode (M-x terminal-emulator). No idea why there are two different terminal emulators in Emacs, but 'M-x term' seems the better of the two, or at least the keybindings make more sense to me. There is also 'M-x serial-term' should you ever need it.
- prakashk 15y agoThere are M-x shell and M-x eshell to run shells within emacs. See http://www.masteringemacs.org/articles/2010/11/01/running-shells-in-emacs-overview/ http://www.masteringemacs.org/articles/2010/11/01/running-sh... for comparison.
- drothlis 15y agoYes. My original comment (the grandparent to your comment) attempted to explain why I prefer term-mode over shell-mode.
- RyanMcGreal 15y agoThe supremacy of bash over zsh &c. seems to be an excellent case study in the "Worse is Better" hypothesis. http://www.jwz.org/doc/worse-is-better.html http://www.jwz.org/doc/worse-is-better.html
- Symmetry 15y agoNot really, you're not seeing bash have many more features because its simpler on the inside at the cost of sometimes breaking. Rather, it seems an example of " the most dangerous enemy of a better solution is an existing codebase that is just good enough"
- justincormack 15y agoNot sure that is the real reason. Zsh was not free software in the Linux formative years. It lost its chance, and mindshare, like so much commercial Unix
- recoil 15y agoZsh was never part of a commercial Unix, so I suspect you are thinking of Ksh. As far as I can tell, Zsh has always been free software: the earliest version I could find used the GPL, but it now uses something more MIT-like. Bash is probably more widely used because it was available earlier than Zsh, and because it was the "official" shell of the GNU project (better marketing).
- deleted 15y ago[deleted]
- tlvince 15y agoIf you're looking for the "keyboard navigable completion list", this what you want: zstyle ':completion:*' menu select
- ilaksh 15y agoI tried that and about a million other things in Ubuntu. When I hit tab I see options, but nothing I put in my .zshrc will allow me to use the arrow keys or anything else to navigate the completion list. I am using oh my zsh but I tried turning it off and it didn't seem to matter. Maybe only Mac users use zsh?
- adavies42 15y agomy favorite zsh feature is advanced globbing--i'd far rather type ls -d ***/*(/) than find . -follow -type d -exec ls -d {} \;
- graywh 15y agoFYI, the (/) is called a glob qualifier.
- adavies42 15y agomy favorite zsh feature is advanced globbing--i'd far rather type ls -d ***/*(/) than find . -follow -type d -exec ls -d {} \;
- nickolai 15y agoI used to use a lot of zsh at work, and one thing that drove me nuts was overzealous wildcard expansion. >scp server2:~/folder/* . zsh: no matches found: server2:~/folder/* nothing in current work dir matches 'server2:~/folder/ * ', so zsh helpfully yells at me. yeah I know use single quotes to avoid expansion, and backslash should work too. It makes total sense because * is a reserved character, but still, bash got it. surely Zsh could've too ? It probably got fixed since then, but this raw frustration is my most vivid memory from zsh usage.
- satiani 15y agoThis behavior can be turned off by adding this to .zshrc: setopt no_nomatch # if there are no matches for globs, leave them alone and execute the command zsh also tries to autocomplete directory names using variables in global namespace that point to directories. I found that behavior maddening and can be turned off with: setopt no_cdable_vars # don't use named directories in cd autocompletion
- deleted 15y ago[deleted]
- heresy 15y agoI agree, though I'd probably suggest working from a simple zshrc for starters ("man zshall" is also your friend). I just spent a bit of time yesterday tweaking information in my prompt just so: http://imgur.com/OSEB3 http://imgur.com/OSEB3 And it's made a huge quality of life difference to what I had before. Worth spending a bit of time making your shell environment optimized for yourself though, and not just copying someone else's setup, in my opinion. You spend a lot of time there, programming for UNIX, why not make it rock?
- bsagert 15y agoThanks mgrouchy for another site that breaks pgdn. The header that never moves hides some lines on the next page. Reading becomes an annoying series of page downs then scroll up a bit to read the hidden sentences. Does this annoy anyone else?
- mgrouchy 15y agoHey, thanks for the feedback, I just recently changed the look of the blog after about a year of neglect. Its actually just Twitter Bootstrap(1.4). I never use page down or up so I completely missed the problem. I will see if I can find a workaround. Thanks again!
- jroes 15y agoI used to use oh-my-zsh but gave up on it after a few months because it took almost 20 seconds to open up a Terminal tab. I switched back to bash with some really basic git completion and was happy enough, enjoying < 2 second opening times.
- arghnoname 15y agomy tabs open up immediately but it does take a little while to log in, which really is annoying. I think depending on how you configure things you can move where and how often the wait occurs and by disabling certain things, how long it is.
- xegroeg 15y agoBash can also do shared history: export HISTCONTROL=ignoredups export HISTCONTROL=ignoreboth HISTSIZE=50000 shopt -s histappend PROMPT_COMMAND='history -a' #history search inline #bind '"\e[A": history-search-backward' #bind '"\e[B": history-search-forward'
- tux1968 15y agoThis article inspired me to give zsh a spin. The pre configured setup of oh-my-zsh is a nice starting point. But am really missing the Bash "help" command, and the combined (easily searchable) man page. Thus far I have not been able to figure out which feature or config option to disable to stop this annoyance: $ grep vim zsh: correct 'vim' to '.vim' [nyae]? Please don't "help me", i typed exactly what I wanted.
- mgrouchy 15y agounsetopt correct_all in your .zshrc also run-help , I believe is the zsh equivalent to the Bash help builtin.
- tux1968 15y agoNot sure what is lost with "unsetopt correct_all", but it fixes this annoyance. "run-help" doesn't seem to do the trick. As an example, in Bash, "help for" will describe the for loop construct. "run-help" seems to just be an alias for "man" and on my system calls up the Tcl for man page. Thanks for the article and your response here.
- skeletonjelly 15y agoCare to post your .zshrc? Edit: I have setopt correctcall and I do not get this behaviour. On an unrelated not, this is a classic example of complaining about why a product doesn't work and having users jump at the chance to fix your issue to prove it's worth. But how to monitize this... :)
- tux1968 15y agolol, guilty.... where do I send my micro-payment ;o)
- skeletonjelly 15y agoWoah. Micro? I'm playing the big numbers game with small amounts of customers ;)
- skeletonjelly 15y agoI wish the author had put the settings used to get those effects. Unless they are default? It's probably just formatting?
- mgrouchy 15y agosome of them are the built in oh-my-zsh things, but I added some of the settings in the posts comments for people who asked. Is there something particular you are looking for?
- skeletonjelly 15y agoI was wondering how you got this so pretty? http://mikegrouchy.com/media/images/2012/01/zshkillcompletion.jpg http://mikegrouchy.com/media/images/2012/01/zshkillcompletio... I don't get the username either.
- mobjedgar 15y agoThis is incredible. I'm converted!