ubuntu zsh安装
cd~/.fonts/ && git clone https://github.com/scotu/ubuntu-mono-powerline.git?
?
来自:https://gist.github.com/agnoster/3712874# vim:ft=zsh ts=2 sw=2 sts=2## agnoster's Theme - https://gist.github.com/3712874# A Powerline-inspired theme for ZSH## # README## In order for this theme to render correctly, you will need a# [Powerline-patched font](https://gist.github.com/1595572).## In addition, I recommend the# [Solarized theme](https://github.com/altercation/solarized/) and, if you're# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -# it has significantly better color fidelity.## # Goals## The aim of this theme is to only show you *relevant* information. Like most# prompts, it will only show git information when in a git working directory.# However, it goes a step further: everything from the current user and# hostname to whether the last call exited with an error to whether background# jobs are running in this shell will all be displayed automatically when# appropriate. ### Segment drawing# A few utility functions to make it easy and re-usable to draw segmented prompts CURRENT_BG='NONE'SEGMENT_SEPARATOR='?' # Begin a segment# Takes two arguments, background and foreground. Both can be omitted,# rendering default background/foreground.prompt_segment() { local bg fg [[ -n $1 ]] && bg="%K{$1}" || bg="%k" [[ -n $2 ]] && fg="%F{$2}" || fg="%f" if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} " else echo -n "%{$bg%}%{$fg%} " fi CURRENT_BG=$1 [[ -n $3 ]] && echo -n $3} # End the prompt, closing any open segmentsprompt_end() { if [[ -n $CURRENT_BG ]]; then echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR" else echo -n "%{%k%}" fi echo -n "%{%f%}" CURRENT_BG=''} ### Prompt components# Each component will draw itself, and hide itself if no information needs to be shown # Context: user@hostname (who am I and where am I)prompt_context() { local user=`` if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m" fi} # Git: branch/detached head, dirty statusprompt_git() { local ref dirty if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then ZSH_THEME_GIT_PROMPT_DIRTY='±' dirty=$(parse_git_dirty) ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="? $(git show-ref --head -s --abbrev |head -n1 2> /dev/null)" if [[ -n $dirty ]]; then prompt_segment yellow black else prompt_segment green black fi echo -n "${ref/refs\/heads\//? }$dirty" fi} # Dir: current working directoryprompt_dir() { prompt_segment blue black '%d'} # Status:# - was there an error# - am I root# - are there background jobs?prompt_status() { local symbols symbols=() [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}?" [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}?" [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}?" [[ -n "$symbols" ]] && prompt_segment black default "$symbols"} ## Main promptbuild_prompt() { RETVAL=$? prompt_status prompt_context prompt_dir prompt_git prompt_end} PROMPT='%{%f%b%k%}$(build_prompt) '?
?
oh my zsh 提供了数十种主题,相关文件在~/.oh-my-zsh/themes目录下,你可以随意选择,也可以编辑主题满足自己的变态需求,默认主题robbyrussell,可以根据自己的需求改:
?
PROMPT='%{$fg_bold[red]%}? %{$fg_bold[green]%}%p%{$fg[cyan]%}%d %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$reset_color%}>'
?
#PROMPT='%{$fg_bold[red]%}? %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
对照原来的版本,我把 c 改为 d,c 表示当前目录,d 表示绝对路径,另外在末尾增加了一个「 > 」
?
?
插件
?
oh my zsh 项目提供了完善的插件体系,相关的文件在~/.oh-my-zsh/plugins目录下,默认提供了100多种,大家可以根据自己的实际学习和工作环境采用,想了解每个插件的功能,只要打开相关目录下的 zsh 文件看一下就知道了。插件也是在 ~.zshrc 配置文件里,找到plugins关键字,你就可以加载自己的插件了,系统默认加载 git ,你可以在后面追加内容,如下:
?
plugins=(rails3 rails git textmate ruby rvm gem git github brew bundler textmate pow)
下面简单介绍几个:
?
1、git:当你处于一个 git 受控的目录下时,Shell 会明确显示 「git」和 branch,如上图所示,另外对 git 很多命令进行了简化,例如 gco=’git checkout’、gd=’git diff’、gst=’git status’、g=’git’等等,熟练使用可以大大减少 git 的命令长度,命令内容可以参考~/.oh-my-zsh/plugins/git/git.plugin.zsh
?
2、textmate:mr可以创建 ruby 的框架项目,tm finename 可以用 textmate 打开指定文件。
?
3、osx:tab 增强,quick-look filename 可以直接预览文件,man-preview grep 可以生成 grep手册 的pdf 版本等。
?
4、autojump:zsh 和 autojump 的组合形成了 zsh 下最强悍的插件,今天我们主要说说这货。
?
首先安装autojump,如果你用 Mac,可以使用 brew 安装:
?
brew install autojump
如果是 Linux,去下载 autojump 的最新版本,比如:
?
wget https://github.com/downloads/joelthelion/autojump/autojump_v21.1.2.tar.gz
解压缩后进入目录,执行
?
./install.sh
最后把以下代码加入.zshrc:
?
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
至此,安装、配置、插件三位一体,终极 Shell 全面登场。退出终端会话重新登录,开始感受 zsh 的训疾如风!
?