Linux 无root权限安装ZSH

服务器没有zsh,不能忍。

  1. 下载
#最新版本自行查看
mkdir ~/tmp
cd ~/tmp
wget https://sourceforge.net/projects/zsh/files/zsh/5.7/zsh-5.7.tar.xz
  1. 解压
tar xvJf  zsh-5.7.tar.xz
  1. 编译
cd ~/tmp/zsh-5.7
./configure --prefix=$HOME
make
make install
  1. 配置
    安装oh-my-zsh
#自动
wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh
#手动
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
  1. 启用
  • 有root权限:chsh -s /bin/zsh
  • 无root权限:在~/.profile中加入
#active zsh
exec $HOME/bin/zsh -l
  • 重新登入
  1. 修改
  • 初始配置并不好用,也不好看,我们需要微调一下~/.zshrc文件

强大的zsh配置文件

效果图
  • 我的~/.zshrc
      #color{{{
      autoload colors
      colors
       
      for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
      eval _$color='%{$terminfo[bold]$fg[${(L)color}]%}'
      eval $color='%{$fg[${(L)color}]%}'
      (( count = $count + 1 ))
      done
      FINISH="%{$terminfo[sgr0]%}"
      #}}}
    
      # If you come from bash you might have to change your $PATH.
      # export PATH=$HOME/bin:/usr/local/bin:$PATH
    
      # Path to your oh-my-zsh installation.
      export ZSH="/home/username/.oh-my-zsh"
    
      # Set name of the theme to load --- if set to "random", it will
      # load a random theme each time oh-my-zsh is loaded, in which case,
      # to know which specific one was loaded, run: echo $RANDOM_THEME
      # See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
      ZSH_THEME="ys"
    
      # Set list of themes to pick from when loading at random
      # Setting this variable when ZSH_THEME=random will cause zsh to load
      # a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
      # If set to an empty array, this variable will have no effect.
      # ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
    
      # Uncomment the following line to use case-sensitive completion.
      # CASE_SENSITIVE="true"
    
      # Uncomment the following line to use hyphen-insensitive completion.
      # Case-sensitive completion must be off. _ and - will be interchangeable.
      # HYPHEN_INSENSITIVE="true"
    
      # Uncomment the following line to disable bi-weekly auto-update checks.
      # DISABLE_AUTO_UPDATE="true"
    
      # Uncomment the following line to automatically update without prompting.
      # DISABLE_UPDATE_PROMPT="true"
    
      # Uncomment the following line to change how often to auto-update (in days).
      # export UPDATE_ZSH_DAYS=13
    
      # Uncomment the following line if pasting URLs and other text is messed up.
      # DISABLE_MAGIC_FUNCTIONS=true
    
      # Uncomment the following line to disable colors in ls.
      # DISABLE_LS_COLORS="true"
    
      # Uncomment the following line to disable auto-setting terminal title.
      # DISABLE_AUTO_TITLE="true"
    
      # Uncomment the following line to enable command auto-correction. 用The FUCK插件代替
      # ENABLE_CORRECTION="true"
    
      # Uncomment the following line to display red dots whilst waiting for completion.
      # COMPLETION_WAITING_DOTS="true"
    
      # Uncomment the following line if you want to disable marking untracked files
      # under VCS as dirty. This makes repository status check for large repositories
      # much, much faster.
      # DISABLE_UNTRACKED_FILES_DIRTY="true"
    
      # Uncomment the following line if you want to change the command execution time
      # stamp shown in the history command output.
      # You can set one of the optional three formats:
      # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
      # or set a custom format using the strftime function format specifications,
      # see 'man strftime' for details.
      HIST_STAMPS="mm/dd/yyyy"
    
      # Would you like to use another custom folder than $ZSH/custom?
      # ZSH_CUSTOM=/path/to/new-custom-folder
    
      # Which plugins would you like to load?
      # Standard plugins can be found in ~/.oh-my-zsh/plugins/*
      # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
      # Example format: plugins=(rails git textmate ruby lighthouse)
      # Add wisely, as too many plugins slow down shell startup.
      # z命令快速跳转目录     x命令解压一切文件
      plugins=(
        git
        z
        zsh-autosuggestions
        extract
        zsh-syntax-highlighting
        last-working-dir
      )
    
      source $ZSH/oh-my-zsh.sh
    
      # User configuration
    
      # export MANPATH="/usr/local/man:$MANPATH"
    
      # You may need to manually set your language environment
      # export LANG=en_US.UTF-8
    
      # Preferred editor for local and remote sessions
      # if [[ -n $SSH_CONNECTION ]]; then
      #   export EDITOR='vim'
      # else
      #   export EDITOR='mvim'
      # fi
    
      # Compilation flags
      # export ARCHFLAGS="-arch x86_64"
    
      # Set personal aliases, overriding those provided by oh-my-zsh libs,
      # plugins, and themes. Aliases can be placed here, though oh-my-zsh
      # users are encouraged to define aliases within the ZSH_CUSTOM folder.
      # For a full list of active aliases, run `alias`.
      #
      # Example aliases 别名
      # alias zshconfig="mate ~/.zshrc"
      # alias ohmyzsh="mate ~/.oh-my-zsh"
      alias check='nvidia-smi'
      alias ta='tmux attach'
      alias cp='cp -i'
      alias mv='mv -i'
      alias rm='rm -i'
      alias ls='ls -F --color=auto'
      alias ll='ls -al'
      alias grep='grep --color=auto'
      alias la='ls -a'
    
      #路径别名 {{{
      #进入相应的路径时只要 cd ~xxx
      hash -d H="/home"
      #}}}
    
      eval $(thefuck --alias)
    
      #命令提示符样式{{{
      RPROMPT=$(echo "$RED%D %T$FINISH")
      PROMPT=$(echo "$WHITE@SSH:  $CYAN%n@$YELLOW%M:$GREEN%/$_YELLOW>$FINISH ")
      #}}}
    
      #标题栏、任务栏样式{{{
      case $TERM in (*xterm*|*rxvt*|(dt|k|E)term)
      precmd () { print -Pn "\e]0;%n@%M//%/\a" }
      preexec () { print -Pn "\e]0;%n@%M//%/\ $1\a" }
      ;;
      esac
      #}}}
      
      #编辑器
      export EDITOR=vim
    
      #关于历史纪录的配置 {{{
      #历史纪录条目数量
      export HISTSIZE=10000
      #注销后保存的历史纪录条目数量
      export SAVEHIST=10000
      #历史纪录文件
      export HISTFILE=~/.zsh_history
      #以附加的方式写入历史纪录
      setopt INC_APPEND_HISTORY
      #如果连续输入的命令相同,历史纪录中只保留一个
      setopt HIST_IGNORE_DUPS
      #为历史纪录中的命令添加时间戳
      setopt EXTENDED_HISTORY      
       
      #启用 cd 命令的历史纪录,cd -[TAB]进入历史路径
      setopt AUTO_PUSHD
      #相同的历史路径只保留一个
      setopt PUSHD_IGNORE_DUPS
       
      #在命令前添加空格,不将此命令添加到纪录文件中
      #setopt HIST_IGNORE_SPACE
      #}}}
    
      ##空行(光标在行首)补全 "cd " {{{
      user-complete(){
      case $BUFFER in
      "" )                       # 空行填入 "cd "
      BUFFER="cd "
      zle end-of-line
      zle expand-or-complete
      ;;
      "cd --" )                  # "cd --" 替换为 "cd +"
      BUFFER="cd +"
      zle end-of-line
      zle expand-or-complete
      ;;
      "cd +-" )                  # "cd +-" 替换为 "cd -"
      BUFFER="cd -"
      zle end-of-line
      zle expand-or-complete
      ;;
      * )
      zle expand-or-complete
      ;;
      esac
      }
      zle -N user-complete
      bindkey "\t" user-complete
      #}}}
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,117评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,963评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,897评论 0 240
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,805评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,208评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,535评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,797评论 2 311
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,493评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,215评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,477评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,988评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,325评论 2 252
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,971评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,807评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,544评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,455评论 2 266