杂谈:终端小工具

一、关于shell的选择

# 安装zsh
yum install zsh

# 修改用户默认shell
chsh -s /bin/zsh

# 安装on-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

二、关于配置

# 修改zsh配置文件
vi ~/.zshrc

# 修改zsh主题为steeef
ZSH_THEME="steeef"

# 设置自定义提示符
PROMPT='%{$fg[blue]%}[%D %*]${PR_RST} %{$fg[red]%}>%{$fg[yellow]%}>%{$fg[green]%}>${PR_RST} %{$purple%}%n${PR_RST} at %{$orange%}iwm-yyz${PR_RST} in %{$limegreen%}%~${PR_RST} $vcs_info_msg_0_$(virtualenv_info)
$ '

三、自定义命令文件

# 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}'
}

# 网络状态
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
原文地址:https://www.cnblogs.com/onlycat/p/9936716.html