Linux zsh 实用配置

一、软件安装

# Redhat 系列执行
sudo yum install zsh
# Debian 系列执行
sudo apt-get install zsh

# 安装on-my-zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

二、基本配置

2.1 别名配置

# ip查询
i() curl cip.cc/$1

# 天气
tq() curl wttr.in

# ctrl+q 退回上层
cdlast() {
      cd -
        ls -lrth --color=auto | tail
          zle reset-prompt
}
zle -N cdlast
bindkey '^Q' cdlast


# 时间戳转换
ds() date -d @$1 "+%Y-%m-%d %H:%M:%S"
sd() date -d "$1" +%s


# 有道翻译
fanyi() {
    word=`echo $1 | tr -d '
' | xxd -plain | sed 's/(..)/%1/g'`
    result=$(curl -s "http://fanyi.youdao.com/openapi.do?keyfrom=CoderVar&key=802458398&type=data&doctype=json&version=1.1&q=$word")
    echo "33[31m【检索】:33[0mc"
    echo  $result | awk -F 'query":' '{print $(2)}' | awk -F ',' '{print $1}'
    echo "33[33m【释义】:33[0mc"
    echo  $result | awk -F ':' '{print $(2)}' | awk -F ',' '{print $1}'
    echo "33[36m【说明】:33[0mc"
    echo  $result | awk -F 'explains":' '{print $(2)}' | awk -F '}' '{print $1}'

    if test '-s' = $2; then
        say $(echo $result | awk -F ':' '{print $(2)}' | awk -F ',' '{print $1}');
    fi
}


# 网络状态
ws() curl -o /dev/null -s -w '
状态码:%{http_code}

响应类型:%{content_type}

总时间:%{time_total}

重定向次数:%{num_redirects}

DNS解析时间:%{time_namelookup}

连接时间:%{time_connect}

连接完成时间:%{time_appconnect}

准备上传输时间:%{time_pretransfer}

重定向时间:%{time_redirect}

开始传输时间:%{time_starttransfer}

下载大小:%{size_download}

下载速度:%{speed_download}

上传大小:%{size_upload}

响应头大小:%{size_header}

请求体大小:%{size_request}
' $1

alias cls='clear'
alias ll='ls -l'
alias la='ls -a'
alias vi='vim'
alias javac="javac -J-Dfile.encoding=utf8"
alias grep="grep --color=auto"
alias -s html=mate   # 在命令行直接输入后缀为 html 的文件名,会在 TextMate 中打开
alias -s rb=mate     # 在命令行直接输入 ruby 文件,会在 TextMate 中打开
alias -s py=vi       # 在命令行直接输入 python 文件,会用 vim 中打开,以下类似
alias -s js=vi
alias -s c=vi
alias -s java=vi
alias -s txt=vi
alias -s gz='tar -xzvf'
alias -s tgz='tar -xzvf'
alias -s zip='unzip'
alias -s bz2='tar -xjvf'

2.2 插件配置

oh my zsh 项目提供了完善的插件体系,插件相关的文件在   ~/.oh-my-zsh/plugins   目录下,可根据自己的实际学习和工作环境开启插件。

开启插件方法, 在  ~/.zshrc   找到如下这行配置,在括号内追加插件

plugins=(git 插件1 插件2 )

 常用插件

autojump:快速切换目录插件

# Debain 安装
suto apt-get install autojump

# Mac安装
brew install autojump

 

  zsh-autosuggestions:命令行命令键入时的历史命令建议插件 

# 安装
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

 

  zsh-syntax-highlighting: 命令行语法高亮插件

# 安装
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

  

colored-man-pages: 手册页提供颜色突出现实

  免安装

 

cp: 使用 cpv 命令,这个命令使用 rsync 实现带进度条的复制功能。

  免安装

 

extract: 使用  x  命令,通用解压插件

  免安装

 

gitignore:提供一条  gi  命令,用来查询 gitignore 模板 例如:gi python > .gitignore 

  免安装

 

command-not-found: 当你输入一条不存在的命令时,会自动查询这条命令可以如何获得。

  免安装

 

sudo:击 Esc,zsh 会把上一条命令加上 sudo 

  免安装

 

 

 参考文章

  【知乎】mac上使用oh my zsh有哪些必备的插件推荐?

 

  

 

 

原文地址:https://www.cnblogs.com/onlycat/p/12971130.html