All posts in Zsh

Bash like history search functionality for Zsh

Bash uses readline to do its line editing and history search functionality, which works pretty well in the past for me. To enable this, just put these 2 lines of configurations in your ~/.inputrc (the config for your readline):

# Enabling History Search

After restart your terminal or shell, you can now use Up Arrow and Down Arrow to navigate your bash history, the beauty of this is it will match the thing you typed between the prompt and the cursor (if typed nothing, it will just use your last command of the history).

This solution works so well that it increases a lot of my productivity and efficiency in the past and now it becomes a must-have for my shell features. Once I switched to Zsh, I was looking for a similar solution since the first day of using Zsh.

Turns out oh-my-zsh includes a default history search functionality already (up-line-or-beginning-search, down-line-or-beginning-search), which works well for a lot of people, but unfortunately not for me.

The issue for this command is it only matches the command, not the entire thing before your cursor, for example, if I typed:

cd code

Then do a tab, it will only match the command starts from “cd”, not the entire “cd code”. You may still call this a history search functionality, but for me, it’s not working as I expected since I come from the bash/readline world.
Continue reading →

ZSH Startup Issue


/usr/local/etc/bash_completion: command not found: complete


fork: Resource temporarily unavailable

一下子让人菊花一紧,虎躯一震;这几乎是无法做事的节奏啊… 紧接着便发现chrome都无法正常工作了(事后证明这应该是心理作用),第一感觉是中毒了,再一想不会吧,应该大概可能是zsh upgrade干了啥好事吧,于是去check了下upgrade script,grep一下哪里call过bash completion,终于发现了事故原因;

原来~/.oh-my-zsh/tools/check_for_upgrade.sh的line 23加了一句:

[ -f ~/.profile ] && source ~/.profile

而我的~/.profile里恰巧有不应该在这里被调用的东西,解决方法便是把这一行注掉,然后再重启iterm2,世界终于清静了…… 把之前不应该存在在.profile里的东西移到.bashrc后,一切终于又恢复“正常”;虚惊一场,不过下次upgrade我肯定会多犹豫个2秒,一朝被蛇咬十年怕井绳了……

Switch From Bash to Zsh

Have used bash for 6+ years, I finally decided to switch to zsh. This is not my first time trying zsh tho, last time I tried zsh I believe oh-my-zsh is not out or very popular yet, somehow zsh seems doesn’t impressive me a lot. Probably at that time I still feel strong tied to bash somehow, habit, workflow, autocompletion style etc.

Yesterday I tried to give zsh one more chance, thanks to oh-my-zsh and peepcode, this time the exprience is much more better than last time, I managed to reuse most of my bash configuration when I can try the new features of zsh, which is pretty good for my transition and the habit I already get used to in bash in the past.

[Shell Prompt]
Zsh users love to share their prompt, to follow their tradition, I’m going to do that here as well, below is my Zsh prompt screenshot:

zsh prompt

The idea is mostly inspired from topfunky’s zsh-simple, except that I used the dark background and customized some of the colors.
Continue reading →