gist - Manage your gist like a pro
All your notes, scripts, config files and snippets deserve version control and tagging!
gist
is a simple bash script for gist management.
It is lightweight(~700LOC) and dependency-free! Helps you to boost coding workflow.
Getting Started
# Install with script on GitHub Page
curl -L https://git.io/J3DXe -o gist # This shortened link points to the bash script
sudo install -m755 gist /usr/local/bin/gist # Install this script wherever you like
# Fetch your gists and clone them into ~/gist as git repos
gist fetch
# List your gists
gist
# Create a new gist
gist new
# Create private gist with files 'foo' and 'bar'
gist new -p foo bar
# Check information of your third gist
gist detail 3
# Get the path and cd to cloned repo with subshell
gist 3
# List your gists with tags instead of URL
gist tag
# Add tags to your third gist
gist tag 3
# Update the description of your third gist
gist edit 3
# Push changes in your third gist to the remote repo
gist push 3
# Delete gists with indices 3, 4 and 5
gist delete 3 4 5
# Or use Brace Expansion
gist delete {3..5}
# Export your third gist as a new Github repo with web page
gist github 3
# For more detail, read the helper message
gist help
Dependencies
OK…I lied, this script really depends on some very basic dev tools.
- GNU coreutils
Used to process text streams. Also, if you are on Mac and use sed
, tail
with BSD version, then it is still fine!
- wget or curl
Used to making request to github.com
.
- git
Do not tell me you don’t have it on your machine…
- Python
Both 2 and 3 works. It is used to process JSON response from github.com
and launch default browser.(Only built-in modules are used)
Basic Commands
Update and clone gists from Github
Run gist fetch
to fetch your all gists with Github API and keep short information for each gist in a index file inside a given folder. (default to ~/gist/index
)
- Automatically Clone/Pull each gist with git into a given folder. (default to ~/gist/
)
- Run gist fetch star
to fetch your starred gist
- If token is not being set, then you cannot fetch your private gist
List your gists
Run gist
to read index file (default to ~/gist/index
) and list your gists with the following format:
<index> <gist-URL> <files-number> <comments-number> <description>
like the following:
- Use
gist star
to show your starred gists - Use
gist all
to show your and starred gists - Index with prefix
s
is a starred gist, index with prefixp
is a private gist - There are colorful hints for each gist in the following cases:
- working
Some changes are made locally but not yet do
git commit
, or you are not inmaster
branch - ahead Your local HEAD is yet to be applied to upstream
- outdated
Your local HEAD is differs from the last fetched gists, do
gist fetch
to refresh index file and pull if needed
- working
Some changes are made locally but not yet do
Create a new gist
Run gist new
to create a new gist
- You can create a new gist with 3 different ways:
1. type the content by hand, run gist new
2. use existing files, run gist new <file1> <file2>...
3. from STDIN, like <command> | gist new
- You can specify filename with --file
, and description with --desc
, like gist new --file new --desc 'a new gist'
- If you don’t specify filename or description, a prompt will shows up!
Modify a gist
Run gist <INDEX>
to enter sub-shell with working directory of the given gist index (by default action). You can do some trick with custom action.(See action and Tips)
Since now a gist is a local cloned repo, it is your business to do git commit and git push. Use gist push <INDEX>
is not recommended.
Clean unnecessary local repos
Say you delete gists with command gist delete <index-of-gist>...
, the local git repositories are still at ~/gist/
.
Run gist clean
to move them into /tmp/gist/
.
Configuration
gist
stores your configuraion inside ~/.config/gist.conf
, with <key>=<value>
format for each line. And just do source ~/.config/gist.conf
at runtime.
https://codeload.github.com/gist//tar.gz/
### Useful action for gist repo
I strongly recommend using [`tig`](https://github.com/jonas/tig) as your custom [action](#action). It is the most powerful git CLI tool as far as I know, and also easy to get in most of the Linux distros or Homebrew for mac. Give it a try!
If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action:
gist config action ‘tig -all’
`tig` interface for history diagram:

### Suppress action
If [`action`](#action) is not being set, you will enter sub-shell by default. If you want suppress it and do not want to type `--no-action` every time, just use command `ture` to do nothing.
gist config action ‘true’
### Suppress hint
There are several environment variables or arguments can suppress hint or user confirm, like:
# List gists without hint
hint=false gist
Just print the repo path with a given index
gist 3 –no-action
Or shorter argument
gist 3 -n
Delete your third gist without confirmation
gist delete 3 –force
```