Archive for December, 2013

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
"\e[A":history-search-backward
"\e[B":history-search-forward

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 →

Update 80: 凌晨2点的门铃声

1. 本文系update系列之第八十回合,不是恐怖系列传说也不是名侦探柯南,所以亲们请放心阅读,今日并非愚人节抑或万圣节,楼主保证屏幕上不会突然跳出来个什么东西来吓你的:)

2. 自从楼主弄了个Google Chromecast之后,每每晚上要看啥视频的时候(有时候甚至是为了看视频而视频,人至贱则无敌吧…)总会把视频通过chromecast然后投到电视上看,但也就是自从那时开始,诡异的事情开始陆续发生了,某几天晚上看的真focus的时候,比如福尔摩斯精彩deduce的时候或者Homeland快要发现CIA卧底的时候,突然门口出现了叮咚一声的门铃声,只有一声且永远只有一声,不长不短,紧促中带有些许惶恐,间歇中含有略微犹豫,时间不定,不过大都在凌晨12点以后(lz睡觉很晚,12点属于夜上海刚刚开始的时候,虽然这里不是上海…),着实吓人,不过这还不是最吓人的……

3. 听到门铃声没反应是不可能的,每次听到,伴随着些许犹豫和不安的心情,楼主熟练的按下暂停开关,然后轻轻蹑手蹑脚的跑到门口对着门上那个小洞使劲窥探,毕竟这是楼主的优势,敌在明处我在暗处,孙子兵法告诉楼主要充分运用优势…… 但是吓人的事情发生了,亲敢信吗,门外什么都没有……(这怎么越写越有名侦探柯南什么什么神秘事件上集的节奏唉…… 哈哈),为了确保确实神马都没有,楼主有一次直接打开了门并扫视了一下四周……

4. 好了,恐怖故事就适可而止了,本来准备拖到下个update来发布神秘事件下集(因为我也是昨晚确切的说是今日凌晨刚刚发现的真相),不过一想有点不大厚道,哈哈,楼主又一次心慈手软了;和往常一样,无论你信不信宗教是无神还是有神论者,真相也永远只有一个,事实原来是自从我投到电视上看视频之后,有意识无意识地增加了视网膜和屏幕的距离,于是导致楼主有意识无意识的提高了电视的嗓门,于是楼上(我是楼主,应该没有楼上只有楼下才对哈哈……)的一位害羞但又不知道声音到底从哪里来的朋友就郁闷了,于是这位朋友广撒网之后展开了定点地毯式搜索,在凌晨2点仍旧孜孜不倦,想必其也深深沉浸在名侦探抑或神探的乐趣之中吧……
Continue reading →

ZSH Startup Issue

今天一早(其实也不早了,嘿嘿)打开iterm2,oh_my_zsh提示是否upgrade,一手贱于是几乎不假思索的敲了Yes,更新完毕reload完terminal顿时很吓人的给了我上百行如下错误:

/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秒,一朝被蛇咬十年怕井绳了……