@kyanny's blog

世界に対して侵略は成功しないということを示す義務がある。もはや誰かが決断しなければならない - マーガレット・サッチャー

How to create and update a gist by `gh` command

Creating a gist is straightforward, but editing a gist is a little tricky.

gh gist | GitHub CLI

Create a gist

gh gist create | GitHub CLI

❯ shuf -n 3 /usr/share/dict/words > words.txt

❯ cat words.txt
oomantia
syngenic
expensive

❯ gh gist create words.txt
- Creating gist words.txt
✓ Created gist words.txt
https://gist.github.com/f030560cfe3134340963a6031f89c3a3

View a gist

gh gist list | GitHub CLI

gh gist view | GitHub CLI

❯ id=$(gh gist list -L 1 | awk '{print $1}')

❯ gh gist view $id
oomantia
syngenic
expensive

Edit a gist

gh gist edit | GitHub CLI

❯ shuf -n 3 /usr/share/dict/words > words.txt

❯ cat words.txt
Gourinae
triticism
neocracy

❯ gh gist edit $id -a words.txt

❯ gh gist view $id
Gourinae
triticism
neocracy

If you use -f option instead of -a, a text editor is launched to edit the file. If $EDITOR is not set, nano is used.