简单介绍一个我用了很久的小工具,cheat[1] 可以被看作一个 Linux 操作系统下的命令行的备(xiǎo)忘录(chāo),今天搜索了以后才知道它还有 go 版本的,因为常用的是 Python 版本,所以还是基于这个版本来介绍。
安装
安装的方法非常简单,使用 pip 安装即可:pip install cheat --user
使用
正常情况下安装完成后会在 $HOME 目录下有一个 .cheat 目录,里面是一些文本文件,此时就可以愉快的“作弊”啦。
举个栗子:
~> cheat tar
# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar
# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/
# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz
# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/
# More ...
看一下 cheat 命令提供的功能:
~> cheat --help
cheat
Create and view cheatsheets on the command line.
Usage:
cheat <cheatsheet> # 查看小抄
cheat -e <cheatsheet> # 打小抄
cheat -s <keyword> # 搜索小抄
cheat -l # 列出打过的小抄
cheat -d # 查看小抄存放的目录
cheat -v # 打印作弊器版本
Options:
-d --directories List directories on $CHEAT_PATH
-e --edit Edit cheatsheet
-l --list List cheatsheets
-s --search Search cheatsheets for <keyword>
-v --version Print the version number
Examples:
To view the tar cheatsheet:
cheat tar
To edit (or create) the foo cheatsheet:
cheat -e foo
To list all available cheatsheets:
cheat -l
To search for "ssh" among all cheatsheets:
cheat -s ssh
除了可以记录 Linux 命令的使用方法,还可以记录任何在以后工作中可能会遇到的重复问题,比如最近学习 docker 和 k8s 的时候遇到了不少了代理的问题,就可以打在小抄里,然后再次需要用到的时候只需要:
~> cheat -s proxy
apt:
# Ref: https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-the-proxy-for-apt-for-ubuntu-18-04/
sudo vi /etc/apt/apt.conf.d/proxy.conf
Acquire::http::Proxy "http://user:password@proxy.server:port/";
Acquire::https::Proxy "http://user:password@proxy.server:port/";
HTTP::proxy "http://127.0.0.1:8080";
HTTPS::proxy "http://127.0.0.1:8080";
docker:
# set a proxy for pulling images
# Ref: https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy
# 2. Create a file named /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
Environment="HTTP_PROXY=http://proxy.example.com:80"
Environment="HTTPS_PROXY=https://proxy.example.com:443"
Environment=HTTP_PROXY=http://proxy.example.com:80 HTTPS_PROXY=https://proxy.example.com:443 NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp
# Setup the proxy for Dockerfile building
# Ref: https://dev.to/zyfa/setup-the-proxy-for-dockerfile-building--4jc8
docker build --build-arg http_proxy=http://10.239.4.80:913 --build-arg https_proxy=http://10.239.4.80:913 .
ENV http_proxy 10.239.4.80:913
git:
# set and unset a git proxy
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
go:
# Go proxy setup
# Ref: https://goproxy.cn/
go env -w GOPROXY=https://goproxy.cn,direct
然后在 cheat 指定的条目查看就好啦。
参考资料
[1] cheat: github.com/cheat/cheat…