1、安装cheat
首先,需要安装python、python-pip(这是cheat命令所依赖的)注:Linux默认已经安装Python
[[email protected] ~]# yum -y install python
[[email protected] ~]# yum -y install wget
- [[email protected] ~]# wget https://bootstrap.pypa.io/get-pip.py
- [[email protected] ~]# python get-pip.py
2、使用git工具安装cheat
安装git
[[email protected] ~]# yum -y install git
安装Python依赖文件:
[[email protected] ~]# pip install docopt pygments
从git克隆项目
[[email protected] ~]# git clone https://github.com/chrisallenlane/cheat
切换到cheat目录进行安装
[[email protected] ~]# cd cheat/
[[email protected] cheat]# python setup.py install
测试安装是否成功
[[email protected] cheat]# cheat -v
cheat 2.1.26
3、配置cheat
(1)、设置自定义备忘单
cheat还有一个好处就是你可以定义自己常用的备忘单,默认的只是一些最基础的例子。自定义的备忘录放到~/.cheat/目录下,当设置好编辑环境可以使用下面的命令进行编辑
# cheat -e foo
注:这里默认使用的是Nano编辑器,提示中的^X代表Ctrl + X组合键可推出编辑器,其他以此类推。
如果新建的foo已经存在,会直接打开编写,不存在会创建然后编辑
[[email protected] ~]# cheat -d
/root/.cheat
/usr/lib/python2.6/site-packages/cheat/cheatsheets #cheat默认的常用命令保存路径
修改
[[email protected] ~]# mkdir /opt/cheats
[[email protected] ~]# vim ~/.bashrc #设置参数(见参数)
[[email protected] ~]# source ~/.bashrc #使设置生效
[[email protected] ~]# cheat -d
/opt/cheat #默认cheat保存路径已经改变
/usr/lib/python2.6/site-packages/cheat/cheatsheets
其中:在~/.bashrc末尾添加的具体参数如下:
export DEFAULT_CHEAT_DIR=‘/opt/cheat‘ #设置cheat默认保存路径
export EDITOR=/usr/bin/vim #设置默认编辑器(可根据自己喜好添加,如nano等)
export CHEATCOLORS=true #语法高亮
(3)、开启自动补全功能
下载自动补全脚本到/etc/bash_completion.d目录:
[[email protected] ~]# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash
[[email protected] ~]# mv cheat.bash /etc/bash_completion.d/
其他脚本地址:
三个文件的具体内容如下:
[[email protected] ~]# cat /etc/bash_completion.d/cheat.bash
function _cheat_autocomplete {
sheets=$(cheat -l | cut -d‘ ‘ -f1)
COMPREPLY=()
if [ $COMP_CWORD = 1 ]; then
COMPREPLY=(`compgen -W "$sheets" -- $2`)
fi
}
complete -F _cheat_autocomplete cheat
[[email protected] ~]# cat /etc/bash_completion.d/cheat.fish
#completion for cheat
complete -c cheat -s h -l help -f -x --description "Display help and exit"
complete -c cheat -l edit -f -x --description "Edit <cheatsheet>"
complete -c cheat -s e -f -x --description "Edit <cheatsheet>"
complete -c cheat -s l -l list -f -x --description "List all available cheatsheets"
complete -c cheat -s d -l cheat-directories -f -x --description "List all current cheat dirs"
complete -c cheat --authoritative -f
for cheatsheet in (cheat -l | cut -d‘ ‘ -f1)
complete -c cheat -a "$cheatsheet"
complete -c cheat -o e -a "$cheatsheet"
complete -c cheat -o ‘-edit‘ -a "$cheatsheet"
end
[[email protected] ~]# cat /etc/bash_completion.d/cheat.zsh
#compdef cheat
#
#declare -a cheats
#cheats=$(cheat -l | cut -d‘ ‘ -f1)
#_arguments "1:cheats:(${cheats})" && return 0
[[email protected] ~]#
注:本文参考网址:
1、一个cheat命令 == Linux命令小抄大全 http://mp.weixin.qq.com/s?__biz=MzA3OTgyMDcwNg==&mid=2650625792&idx=1&sn=02cfdf9dcf3206a6bb91282234ef89c9&scene=2&srcid=0805bWEEe3lULY8qUBtLzbqU&from=timeline&isappinstalled=0#wechat_redirect
2、Linux下更好用的帮助命令—cheat http://www.mamicode.com/info-detail-1470185.html
3、Cheat—— 给Linux初学者和管理员一个终极命令行"备忘单"-技术 ◆ 学习|Linux.中国-开源社区 https://linux.cn/article-3760-1.html