algonote

There's More Than One Way To Do It

サクッと調べたいときはmanページでなくcheat.shを使おう!

ターミナルで作業しているとあのコマンドどうやって使うんだったけ?という時がしばしばある。通常、そういう時はmanコマンドが使われることが多いが、cheat.shが便利なので布教してみる。

f:id:hiromichinomata:20180708205114p:plain

manページのつらみとcheat.shの優位性

コマンドの使い方を調べるときにおそらく一番有名なのはmanコマンド。Unix環境ではビルトインで入っており、 man <コマンド名> と叩けば網羅的な情報が出てくることや、日本語翻訳があることなどから入門書には必ず紹介されている。

一方、基本コマンドオプションの羅列で、コピペ可能な一番よく使われるオプションの組み合わせはのっていないことも多く、気づけばググっていることもしばしば。

cheat.shを使えばインストール不要でチートシートが手軽に取り出せる。

使い方

必要なものはcurlだけなので、Mac環境ならbrew install curlなどでインストールしておく。

後は、

curl cheat.sh/scp

と叩くと

# To copy a file from your local machine to a remote server:
scp foo.txt user@example.com:remote/dir

# To copy a file from a remote server to your local machine:
scp user@example.com:remote/dir/foo.txt local/dir

と使い方が出てくる。

また、言語ごとにディレクトリがきられており、

curl cheat.sh/ruby/File

と叩くと各言語固有のチートシートも見られる。

# How to create a file in Ruby
#
# Use:

File.open("out.txt", [your-option-string]) {|f| f.write("write your stuff here") }

# where your options are:
#
    # * r - Read only. The file must exist.
    # * w - Create an empty file for writing.
    # * a - Append to a file.The file is created if it does not exist.
    # * r+ - Open a file for update both reading and writing. The file
# must exist.
    # * w+ - Create an empty file for both reading and writing.
    # * a+ - Open a file for reading and appending. The file is created
# if it does not exist.
#
# In your case, 'w' is preferable.
#
# OR you could have:

out_file = File.new("out.txt", "w")
#...
out_file.puts("write your stuff here")
#...
out_file.close

# [zanbri] [so/q/7911669] [cc by-sa 3.0]

簡単な解説

おさっしの通り、cheat.shはコマンドですらなく、いってしまえばコマンドラインからの使用に特化したWebサイト。いくつかのソースからの情報を集めて作られている模様。

所感

curl叩くだけの手軽さは便利。linterとかdeployでもやってみると面白いかもしれない。