在Ubuntu上安装zsh

来源:互联网 发布:linux中telnet命令 编辑:程序博客网 时间:2024/04/28 18:52

文以Ubuntu 12.04 LTS为例,安装目前比较流行的zsh的配置oh-my-zsh。 oh-my-zsh最初是在OS X上供人使用,使用方法见此处。在Ubuntu上安装oh-my-zsh稍有不同。

安装

先安装zsh和Git,同时移除之前可能的oh-my-zsh的安装。

?
1
2
3
4
sudoapt-getinstallzsh git
if[ -d ~/.oh-my-zsh ]; then
    rm-r ~/.oh-my-zsh
fi

手动安装zsh是用于Ubuntu的 sh 比较诡异,不识别 source 这个指令。装好zsh后仿OS X

?
1
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh

然后把shell切换成zsh,并重启计算机。

?
1
2
chsh -s `whichzsh`
sudoshutdown-r 0

关于这个诡异问题的详细讨论见github上此issue

配置

oh-my-zsh有大量精美主题托管在项目中,可以在此预览 https://github.com/robbyrussell/oh-my-zsh/wiki/themes,我看中了其中最拉风的一款agnoster。把配置过程记录如下。

  • 为了能够显示诸如分支(branch)、闪电(这个符号应该指拿到root权限)、错误(红色叉叉)、后台(一个齿轮)的各种符号,必须使用一个patch过的字体,在ubuntu下默认是Ubuntu Mono,OS X下坐着配的是Menlo,很多常见的等宽字体都打好了patch,当然也可以自己手动打patch。
    ?
    1
    cd~/.fonts/ && git clone https://github.com/scotu/ubuntu-mono-powerline.git && cd~
  • 在 ~/.zshrc 把主题设置为 agnoster
  • 在 ~/.zshrc 设定 DEFAULT_USER 变量可以使得即使登陆在本机(即非SSH到远程)时也能显示“user@hostname”

这是我做的效果,Solarized Dark colorscheme这个配色没有适用于Ubuntu Terminal的。

以下是我的 .zshrc ,只开了git一个plugin,还有很多plugin在 ~/.oh-my-zsh/plugin/ 目录下,原来的sublime的plugin有点bug,我就放在我的.zshrc的配置文件里面了。
https://gist.github.com/4015090.js?file=.zshrc

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. # Path to your oh-my-zsh configuration.  
  2. ZSH=$HOME/.oh-my-zsh  
  3.   
  4. # Set name of the theme to load.  
  5. # Look in ~/.oh-my-zsh/themes/  
  6. # Optionally, if you set this to "random", it'll load a random theme each  
  7. # time that oh-my-zsh is loaded.  
  8. # ZSH_THEME="robbyrussell"  
  9. ZSH_THEME="agnoster"  
  10.   
  11. # Example aliases  
  12. # alias zshconfig="mate ~/.zshrc"  
  13. # alias ohmyzsh="mate ~/.oh-my-zsh"  
  14.   
  15. # Set to this to use case-sensitive completion  
  16. # CASE_SENSITIVE="true"  
  17.   
  18. # Comment this out to disable weekly auto-update checks  
  19. # DISABLE_AUTO_UPDATE="true"  
  20.   
  21. # Uncomment following line if you want to disable colors in ls  
  22. # DISABLE_LS_COLORS="true"  
  23.   
  24. # Uncomment following line if you want to disable autosetting terminal title.  
  25. # DISABLE_AUTO_TITLE="true"  
  26.   
  27. # Uncomment following line if you want red dots to be displayed while waiting for completion  
  28. # COMPLETION_WAITING_DOTS="true"  
  29.   
  30. # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)  
  31. # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/  
  32. # Example format: plugins=(rails git textmate ruby lighthouse)  
  33. plugins=(git)  
  34.   
  35. alias st='/usr/bin/sublime-text'  
  36.   
  37. source $ZSH/oh-my-zsh.sh  
  38.   
  39. # Customize to your needs...  
  40. export PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games  
  41.   
  42. # optionally set DEFAULT_USER in ~/.zshrc to your regular username to hide the “user@hostname” info when you’re logged in as yourself on your local machine.  
  43. DEFAULT_USER=tangkai@virtual-machine  


转自:http://logicmd.net/2012/11/installing-zsh-on-ubuntu/

0 0