杂谈:自定义小工具

一、主题

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 ip.cn/$1

# 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/9753799.html