杂谈:终端小工具

一、关于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 '\n' | 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 "\033[31m【检索】:\033[0m\c"
    echo  $result | awk -F 'query":' '{print $(2)}' | awk -F ',' '{print $1}'
    echo "\033[33m【释义】:\033[0m\c"
    echo  $result | awk -F ':' '{print $(2)}' | awk -F ',' '{print $1}'
    echo "\033[36m【说明】:\033[0m\c"
    echo  $result | awk -F 'explains":' '{print $(2)}' | awk -F '}' '{print $1}'
}

# 网络状态
ws() curl -o /dev/null -s -w '
状态码:%{http_code}\n
响应类型:%{content_type}\n
总时间:%{time_total}\n
重定向次数:%{num_redirects}\n
DNS解析时间:%{time_namelookup}\n
连接时间:%{time_connect}\n
连接完成时间:%{time_appconnect}\n
准备上传输时间:%{time_pretransfer}\n
重定向时间:%{time_redirect}\n
开始传输时间:%{time_starttransfer}\n
下载大小:%{size_download}\n
下载速度:%{speed_download}\n
上传大小:%{size_upload}\n
响应头大小:%{size_header}\n
请求体大小:%{size_request}\n' $1
posted @ 2018-11-09 19:09  ony-z  阅读(325)  评论(0编辑  收藏  举报