gh gist コマンド

gh gistコマンドは、gistの作成や削除などができるコマンドです。

gh gist <command> [flags]で実行し、<command>には以下の4個が利用できます。

create:     Create a new gist
edit:       Edit one of your gists
list:       List your gists
view:       View a gist

gh gist create

gh gist createコマンドは、gistを新規作成することができるコマンドです。

gh gist create [<filename>... | -] [flags]で実行する。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-d --desc gistの説明を指定
-f --filename ファイル名を指定 (標準入力から指定する場合)
-p --public gistを公開する (デフォルトprivate)

このようにファイル名を指定する方法を一番使うかと思います。

$ gh gist create hogefuga.txt
- Creating gist hogefuga.txt
✓ Created gist hogefuga.txt
https://gist.github.com/d09d42c7ef0643c432129f7085ffde9d

標準入力から内容を指定する場合、--filenameでファイル名を指定することができる。

$ echo hogehoge | gh gist create --filename hoge.txt
- Creating gist hoge.txt
✓ Created gist hoge.txt

もしくは、-を利用する。書き終わったらCtrl+Dで抜けることができる。

$ gh gist create - --filename hoge.js

const hoge = 'hoge';
console.log(hoge);

- Creating gist hoge.js
✓ Created gist hoge.js

help

$ gh gist create --help
Create a new GitHub gist with given contents.

Gists can be created from one or multiple files. Alternatively, pass "-" as
file name to read from standard input.

By default, gists are private; use '--public' to make publicly listed ones.


USAGE
  gh gist create [<filename>... | -] [flags]

FLAGS
  -d, --desc string       A description for this gist
  -f, --filename string   Provide a filename to be used when reading from STDIN
  -p, --public            List the gist publicly (default: private)

INHERITED FLAGS
  --help   Show help for command

EXAMPLES
  # publish file 'hello.py' as a public gist
  $ gh gist create --public hello.py

  # create a gist with a description
  $ gh gist create hello.py -d "my Hello-World program in Python"

  # create a gist containing several files
  $ gh gist create hello.py world.py cool.txt

  # read from standard input to create a gist
  $ gh gist create -

  # create a gist from output piped from another command
  $ cat cool.txt | gh gist create

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh gist list

gh gist listコマンドは、gistの一覧を取得できるコマンドです。

gh gist list [flags]で実行する。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-L --limit 表示最大件数を指定する(デフォルト 10)
  --public publicのgistを表示する
  --secret secretのgistを表示する

$ gh gist list
f6b19a5e7516b0bbadcba6e3b8732e62  hoge.js       1 file  secret  about 12 min...
08b23d0bc86a40cc74a7b2249259c7f8                1 file  secret  about 13 min...
1a564f0f1c176a7de2fff7738adc187c                1 file  secret  about 15 min...
c722167d04f9aa8528255f7db0f84e7f  hoge.txt      1 file  secret  about 17 min...
d09d42c7ef0643c432129f7085ffde9d  hogefuga.txt  1 file  secret  about 23 min...
8170566345795f3d330cef2fff57609e  hoge.txt      1 file  secret  about 19 hou...

help

$ gh gist list --help
List your gists

USAGE
  gh gist list [flags]

FLAGS
  -L, --limit int   Maximum number of gists to fetch (default 10)
      --public      Show only public gists
      --secret      Show only secret gists

INHERITED FLAGS
  --help   Show help for command

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh gist edit

gh gist editコマンドは、自分のgistを編集することができるコマンドです。

gh gist edit {<gist ID> | <gist URL>} [flags]で実行する。 あらかじめgh gist listなどでIDを調べる必要があります。もしくはgistのURLでも指定することができます。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-f --filename ファイル名

以下を実行すると、エディタが開いて編集することができます。

$ gh gist edit f6b19a5e7516b0bbadcba6e3b8732e62

複数ファイルから構成されるgistの場合は、editするファイルを選択します。

$ gh gist edit d7f1cc09968c1064f42dfb92181ee983
? Edit which file?  [Use arrows to move, type to filter]
> bar.txt
  hogefuga.js
  hogefuga.txt

他のファイルも編集する場合はEdit another fileを選択します。終了したらSubmitする。

? What next?  [Use arrows to move, type to filter]
> Edit another file
  Submit
  Cancel

ちなみに--filenameフラグを利用して特定のファイルを指定することができます。

$ gh gist edit d7f1cc09968c1064f42dfb92181ee983 --filename hogefuga.txt

help

$ gh gist edit --help
Edit one of your gists

USAGE
  gh gist edit {<gist ID> | <gist URL>} [flags]

FLAGS
  -f, --filename string   a specific file to edit

INHERITED FLAGS
  --help   Show help for command

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh gist view

gh gist viewコマンドは、gistを閲覧するコマンドです。

gh gist view {<gist id> | <gist url>} [flags]で実行する。 あらかじめgh gist listなどでIDを調べる必要があります。もしくはgistのURLでも指定することができます。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-f --filename ファイル名を指定
-r --raw markdownをレンダリングしない
-w --web ブラウザで開く

これは、複数のファイルから構成されているケースです。

$ gh gist view d7f1cc09968c1064f42dfb92181ee983
bar.txt

bar


hogefuga.js

const hoge = 'hoge';
const fuga = 'fuga';
console.log(hoge, fuga);


hogefuga.txt

foo
bar
baz

指定したgistが複数のファイルから構成されている場合は特定のファイルのみを指定することもできます。

$ gh gist view d7f1cc09968c1064f42dfb92181ee983 --filename hogefuga.js
const hoge = 'hoge';
const fuga = 'fuga';
console.log(hoge, fuga);

help

$ gh gist view --help
View a gist

USAGE
  gh gist view {<gist id> | <gist url>} [flags]

FLAGS
  -f, --filename string   display a single file of the gist
  -r, --raw               do not try and render markdown
  -w, --web               open gist in browser

INHERITED FLAGS
  --help   Show help for command

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual