Centos 安装 Zsh

  • 内容
  • 评论
  • 相关

 

大多数的 Linux 用户偏爱 Bash,因为发行版通常默认的就是它。
Bash 确实是不错的 Shell,但仍有用很多不尽人意的地方,如自动补全的功能不够强大,定位较长路径不够方便,命令历史管理不够完善等。

介绍使用 zsh,功能十分强大.. 推荐给大家!

1 zsh 介绍


1.1 Linux shell


Linux/Unix 提供了很多种 Shell,为毛要这么多 Shell?

难道用来炒着吃么?那我问你,你同类型的衣服怎么有那么多件?花色,质地还不一样。写程序比买衣服复杂多了,而且程序员往往负责把复杂的事情搞简单,简单的事情搞复杂。牛程序员看到不爽的 Shell,就会自己重新写一套,慢慢形成了一些标准,常用的 Shell 有这么几种,sh、bash、csh 等,想知道你的系统有几种 shell,可以通过以下命令查看:

cat /etc/shells

显示如下:

/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
PS.默认没有安装zsh 

1.2 zsh 简介


Zsh 是一个 Linux 下强大的 shell, 由于大多数 Linux 产品安装,以及默认使用bash shell, 但是丝毫不影响极客们对 zsh 的热衷, 几乎每一款 Linux 产品都包含有 zsh,通常可以用 apt-get、urpmi 或 yum 等包管理器进行安装

Zsh 具有以下主要功能

  • 开箱即用、可编程的命令行补全功能可以帮助用户输入各种参数以及选项
  • 在用户启动的所有 shell 中共享命令历史
  • 通过扩展的文件通配符,可以不利用外部命令达到 find 命令一般展开文件名
  • 改进的变量与数组处理
  • 在缓冲区中编辑多行命令
  • 多种兼容模式,例如使用 / bin/sh 运行时可以伪装成 Bourne shell
  • 可以定制呈现形式的提示符;包括在屏幕右端显示信息,并在键入长命令时自动隐藏
  • 可加载的模块,提供其他各种支持:完整的 TCP 与 Unix 域套接字控制,FTP 客户端与扩充过的数学函数
  • 完全可定制化

1.3 zsh 与 oh-my-zsh 终极配置

Centos 安装 Zsh 和 autojump

yum install zsh autojump-zsh -y 

切换zsh

chsh -s /bin/zsh 

切换bash

chsh -s /bin/bash 

安装 oh-my-zsh

sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" 

安装 zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting 

安装 zsh-autosuggestions

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions 

编辑 ~/.zshrc

vim ~/.zshrc 

编辑zsh插件

plugins=( [plugins...] zsh-autosuggestions zsh-syntax-highlighting autojump)

显示文件夹git状态

安装 ccat

get https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz
tar -zvxf linux-amd64-1.1.0.tar.gz
cd linux-amd64-1.1.0.tar.gz
sudo cp ./ccat /bin/ 

让他替代cat,在自己的配置文件~/.bashrc(当前用户)或者系统的 / etc/bashrc(所有用户)中

#  use the ccat to instread cat for syntax highlighting.                         
alias cat="ccat"

ccat 代码高亮

.zshrc 配置文件


# 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/davymai/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="ys"

# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of
# looking in ~/.oh-my-zsh/themes/
# An empty array 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 change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# 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.
# 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.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# 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? (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.
plugins=(
  git
  autojump
  zsh-autosuggestions
  zsh-syntax-highlighting
)

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"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# 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 ll="ls -alF"
alias la="ls -AF"
alias ls="ls -CF"
alias l="ls -CF"
# grep
alias grep="grep --color=always"
# ccat
alias cat=ccat
# enables colorin the terminal bash shell export
export CLICOLOR=1
# setsup thecolor scheme for list export
export LSCOLORS=gxfxcxdxbxegedabagacad
# autojump
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
#解决乱码
export LC_ALL=en_US.UTF-8  
export LANG=en_US.UTF-8

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注