gist にコマンドラインから貼り付ける

先日コマンドラインからgist に貼り付けられるんだと驚かれたのでちょっと書いておきます.

その時使ったsctipt はこちら.

Debian jessie 以降,Ubuntu 14.04 以降だとパッケージもあります.このパッケージで導入した場合コマンド名は gist ではなく gist-paste になります.

自分で入れる場合は,gem やHomebrew が使えます.

  • apt $ sudo apt-get install gist
  • gem $ sudo gem install gist
  • Homebrew $ brew install gist

※Homebrew が動く環境を持っていないのでこちらは未検証です.

導入後利用する前に,認証を済ませておきます.2要素認証にも対応しています.

$ gist --login
Obtaining OAuth2 access_token from github.
GitHub username: matoken
GitHub password: 
2-factor auth code: 984736

Success! https://github.com/settings/applications

認証が終わったら試してみます.
一番単純な動かし方は貼り付けたいファイルを指定するだけです.これで公開状態で貼り付けられます.

$ gist lingrbot_web.cgi
https://gist.github.com/ed68bd7182ffddee4801 🏛️

ファイルタイプを指定する場合は面倒ですがファイル名も指定しないと反映されないようです.

$ gist -f ml2lingr.pl -t perl /tmp/ml2lingr.pl
https://gist.github.com/3021d8d064d8a1d29ba9 🏛️

標準入力も

$ gist
(type a gist. to cancel, when done)
hoge
fuga
https://gist.github.com/3e993a396a7671403f9e 🏛️

$ echo “hoge” | sha512sum |gist
https://gist.github.com/970e190f97ae67c8e90d 🏛️

更新も可能です.

$ gist -u 3021d8d064d8a1d29ba9 -f ml2lingr.pl -t perl /tmp/ml2lingr.pl
https://gist.github.com/3021d8d064d8a1d29ba9 🏛️

しかし,更新などはURL やID を指定しないといけないのでgitでclone しておいて編集後push したほうがお手軽そうです.

その他のpastbin系サービスを使いたい場合いろんなコマンドがあります.最近は pastebinit を使っています.
このコマンドの対応サービスはこんなかんじです.

$ pastebinit -l
Supported pastebins:
- cxg.de
- fpaste.org
- p.defau.lt
- paste.debian.net
- paste.drizzle.org
- paste.kde.org
- paste.openstack.org
- paste.pocoo.org
- paste.pound-python.org
- paste.ubuntu.com
- paste.ubuntu.org.cn
- paste2.org
- pastebin.com
- pastie.org
- pb.daviey.com
- slexy.org
- sprunge.us
- yourpaste.net

ちなみにこのへんのコマンドを使うまではクリップボード操作アプリを使ってました.
$ cat file | xclip とかするとクリップボードにファイルの内容がコピーされるのでこれをブラウザ上のテキストエリアに貼り付けたりしていました.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)