TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

My favourite Zsh features

140 pointsby joejagover 10 years ago

15 comments

stormbrewover 10 years ago
Something I&#x27;ve noticed is that osx users believe bash to be less capable than it is because of the poor out of the box configuration of bash on that platform (in addition to the ancient version installed). Particularly the tab completion stuff. It doesn&#x27;t pop up menus and all that, but the ubuntu install of bash has a ton of context-sensitive tab completion stuff in it, and the git package properly installs __git_ps1 and very good tab completion (which even the homebrew git recipe on osx doesn&#x27;t manage to do).<p>This is not to say that zsh doesn&#x27;t have a lot more features, just that the comparison from the perspective of an osx user tends to be a lot more stark.
评论 #8612737 未加载
评论 #8612608 未加载
评论 #8612288 未加载
justinmayerover 10 years ago
While we&#x27;re on the topic of non-bash shells, I recommend taking a look at Fish: <a href="http://fishshell.com/" rel="nofollow">http:&#x2F;&#x2F;fishshell.com&#x2F;</a><p>I wrote a tutorial on how to install it on Mac OS X and Ubuntu: <a href="http://hackercodex.com/guide/install-fish-shell-mac-ubuntu/" rel="nofollow">http:&#x2F;&#x2F;hackercodex.com&#x2F;guide&#x2F;install-fish-shell-mac-ubuntu&#x2F;</a> For me, the chief advantage to Fish is that you get more functionality out-of-the-box than with most other shells, including zsh.<p>I also published two related projects for easily sharing Fish shell enhancements — Tacklebox <a href="https://github.com/justinmayer/tacklebox" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;justinmayer&#x2F;tacklebox</a> and Tackle <a href="https://github.com/justinmayer/tackle" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;justinmayer&#x2F;tackle</a>) — because I wanted a way for folks to be able to have access to multiple plugin repositories and easily share their favorite shell snippets.
kstockover 10 years ago
A killer feature not listed here is global aliases. These are aliases that can be anywhere in a line. The most use I get out of this is from having<p><pre><code> alias -g L=&#x27; | less &#x27; </code></pre> which allows me to simply append &quot;L&quot; to a line to pipe the output to less.<p><pre><code> ls L </code></pre> The pattern of short all-caps global aliases for &#x27; | command &#x27;s make building&#x2F;editing pipelines really easy&#x2F;fast.<p><pre><code> alias -g C=&#x27; | wc -l &#x27; alias -g A=&#x27; | ack-grep &#x27; alias -g S=&#x27; | sort &#x27; alias -g JQL=&#x27; | jq -C | less&#x27; ls **&#x2F;*png L ls **&#x2F;*png A -v regex C curl $site JQL </code></pre> putting<p>bindkey &#x27;^g&#x27; _expand_alias<p>in your zshrc allows you to expand aliases with &lt;C-g&gt;<p>You can find more global aliases and tips at: <a href="http://grml.org/zsh/zsh-lovers.html" rel="nofollow">http:&#x2F;&#x2F;grml.org&#x2F;zsh&#x2F;zsh-lovers.html</a>
评论 #8612427 未加载
jryan49over 10 years ago
One of my favorites instead of aliasing &quot;..&quot;&#x27;s is this function:<p><pre><code> rationalise-dot() { if [[ $LBUFFER = *.. ]]; then LBUFFER+=&#x2F;.. else LBUFFER+=. fi } zle -N rationalise-dot bindkey . rationalise-dot </code></pre> When you hit ... it will produce a slash and a ..&#x2F; for each . you type after that.
评论 #8613190 未加载
andrewstuart2over 10 years ago
The tab completion isn&#x27;t limited to the beginning of file names either. Useful when many of your file names start with the same pattern but then diverge.<p><pre><code> ls something&lt;TAB&gt; </code></pre> will complete to<p><pre><code> ls prefixSomething.sh </code></pre> if it&#x27;s unique enough. This is probably my single favorite zsh feature.
评论 #8612084 未加载
billiobover 10 years ago
One feature not listed there that use a lot is &quot;setopt autocd&quot;. Just type in a directory name and hit Enter and it will automatically &quot;cd&quot; to it. No need to alias &quot;..&quot; to &quot;cd ..&quot;.
seniorsassycatover 10 years ago
I love that if you have vi key bindings active you can update the prompt when you change modes. I never used vi bindings in bash because I would become confused when I entered normal mode without realizing it. In zsh it was easy to configure my prompt to change colors and symbols when outside insert mode.<p><a href="https://github.com/everett1992/dotfiles/blob/master/home/.zshrc#L91-L112" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;everett1992&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;home&#x2F;.zs...</a><p>I have noticed that zsh&#x27;s globbing is greedy.<p><pre><code> `grep ^foo *` tries to expand ^foo when bash would pass it as a string to grep.</code></pre>
rafaelnonatoover 10 years ago
It seems to me that the only two features I can&#x27;t get in my modern bash is completion of the kind cd &#x2F;firstletters&#x2F;firstletters&#x2F;&lt;tab&gt; ==&gt; &#x2F;fullname&#x2F;fullname and the keyboard navigable menus.
gcb0over 10 years ago
bash only needs better history manipulation. absolutely nothing else.<p>all those z shell features the only useful one (i.e. the only one that&#x27;s impossible on bash) is the <i></i>recursion (i typed star star, but hn hides it) hack.<p>and it&#x27;s awful. because now you just learned something that you can&#x27;t use anywhere else! and to search that same way in a shell script? though luck.<p>also it has less parameter then find. and find is available everywhere so you can use it in scripts.
评论 #8612378 未加载
评论 #8612364 未加载
jraddover 10 years ago
Any favorite command I reference is likely to be listed here: <a href="http://www.zzapper.co.uk/zshtips.html" rel="nofollow">http:&#x2F;&#x2F;www.zzapper.co.uk&#x2F;zshtips.html</a>
changsover 10 years ago
(Shameless self-promotion) I&#x27;d like to recommend a small and unobtrusive config for ZSH: <a href="https://github.com/changs/slimzsh" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;changs&#x2F;slimzsh</a> It is almost a default ZSH, but with small tweaks here and there to make it even nicer. I hope that you find it useful :)
arianvanpover 10 years ago
Clever history doesn&#x27;t really work for me when I use `sudo`<p>say I type<p><pre><code> $ sudo pacman -Syu $ sudo chown blah blah $ sudo pa &lt;UP&gt; </code></pre> I just get `sudo chown blah blah` instead of `sudo pacman -Syu`<p>Does anybody know how to fix this? :)
评论 #8613169 未加载
评论 #8621179 未加载
评论 #8614121 未加载
rnhmjojover 10 years ago
The up arrow to go back in history matching the partial command I typed is has become essential to me.<p>I feel lost without it, more than the tab completion.
评论 #8612647 未加载
评论 #8612384 未加载
评论 #8612446 未加载
krickover 10 years ago
&lt;CTRL&gt;+X &lt;CTRL&gt;+E works in bash as well.
zobzuover 10 years ago
interestingly you can s&#x2F;bash&#x2F;zsh&#x2F; and s&#x2F;zsh&#x2F;bash&#x2F; in this text and everything also works.
评论 #8613033 未加载