aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-04-08 15:03:57 +0800
committertypebrook <typebrook@gmail.com>2020-04-08 15:03:57 +0800
commit0f6da18b752b0a9541e1975518df21bb15b6a2a6 (patch)
tree105ee699799f61dc9dc78bd632394312db2a5f91
parent039ec62e65224bae703f57d31bb6557fa4d7d4a1 (diff)
Update README
-rw-r--r--README.md197
1 files changed, 144 insertions, 53 deletions
diff --git a/README.md b/README.md
index ca5badc..4699ae4 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,24 @@
1# [[gist]] - Manage your gist like a pro 1# gist - Manage your gist like a pro
2## Getting started 2- [Getting started](#Getting-started)
3- [Basic Commands](#Basic-Commands)
4 - [Update and clone gists from Github](#Update-and-clone-gists-from-Github)
5 - [List your gists](#List-your-gists)
6 - [Create a new gist](#Create-a-new-gist)
7 - [Modify a gist](#Modify-a-gist)
8 - [Clean unnecessary local repos](Clean-unnecessary-local-repos)
9- [Configuration](#Configuration)
10- [Filter gists](#Filter-gists)
11 - [Filter by tags](#Filter-by-tags)
12 - [Filter by file languages](#Filter-by-file-languages)
13 - [Filter by pattern](#Filter-by-pattern)
14- [Tips](#Tips)
15 - [Filter gists with pipe](#Filter-gists-with-pipe)
16 - [Git Branching](#Git-Branching)
17 - [Suppress action](#Suppress-action)
18 - [Useful action for gist repo](#Useful-action-for-gist-repo)
19 - [Suppress hint](#Suppress-hint)
3 20
21## Getting started
4```bash 22```bash
5# fetch your gists and clone them into ~/gist as git repos 23# fetch your gists and clone them into ~/gist as git repos
6gist fetch 24gist fetch
@@ -16,7 +34,11 @@ gist 3
16gist push 3 34gist push 3
17# update the description of your third gist 35# update the description of your third gist
18gist edit 3 36gist edit 3
19# delete gists with index 3, 4 and 5 37# add tags to your third gist
38gist tag 3
39# list your gists with tags instead of URL
40gist tag
41# delete gists with indices 3, 4 and 5
20gist delete 3 4 5 42gist delete 3 4 5
21# or use Brace Expansion 43# or use Brace Expansion
22gist delete {3..5} 44gist delete {3..5}
@@ -26,7 +48,7 @@ gist github 3
26gist help 48gist help
27``` 49```
28 50
29## Commands 51## Basic Commands
30### Update and clone gists from Github 52### Update and clone gists from Github
31Run `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`) 53Run `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`)
32- Automatically Clone/Pull each gist with git into a given folder. (default to `~/gist/`) 54- Automatically Clone/Pull each gist with git into a given folder. (default to `~/gist/`)
@@ -34,9 +56,9 @@ Run `gist fetch` to fetch your all gists with Github API and keep short informat
34- If token is not being set, then you cannot fetch your private gist 56- If token is not being set, then you cannot fetch your private gist
35 57
36### List your gists 58### List your gists
37Run `gist` to read index file (default to `~/gist/index`) and list your gists with the folloing format: 59Run `gist` to read index file (default to `~/gist/index`) and list your gists with the following format:
38``` 60```
39[index] [gist-URL] [files-number] [comments-number] [description] 61<index> <gist-URL> <files-number> <comments-number> <description>
40``` 62```
41 63
42like the following: 64like the following:
@@ -47,31 +69,36 @@ like the following:
47- Use `gist all` to show your and starred gists 69- Use `gist all` to show your and starred gists
48- Index with prefix `s` is a starred gist, index with prefix `p` is a private gist 70- Index with prefix `s` is a starred gist, index with prefix `p` is a private gist
49- There are colorful hints for each gist in the following cases: 71- There are colorful hints for each gist in the following cases:
50 - **working:** some changes are made locally but not yet do `git commit`, or you are not in `master` branch 72 - **working**
51 - **ahead:** your local **HEAD** is yet to be applied to upstream 73 Some changes are made locally but not yet do `git commit`, or you are not in `master` branch
52 - **outdated:** your local **HEAD** is differs from the last fetched gists, do `gist fetch` to refresh index file and pull if needed 74 - **ahead**
75 Your local **HEAD** is yet to be applied to upstream
76 - **outdated**
77 Your local **HEAD** is differs from the last fetched gists, do `gist fetch` to refresh index file and pull if needed
53 78
54### Create a new gist 79### Create a new gist
55Run `gist new` to create a new gist 80Run `gist new` to create a new gist
56- You can create a new gist with 3 different ways: 81- You can create a new gist with 3 different ways:
57 1. type the content by hand, run `gist new` 82 1. type the content by hand, run `gist new`
58 2. use existig files, run `gist new <file1> <file2>...` 83 2. use existing files, run `gist new <file1> <file2>...`
59 3. from STDIN, like `<command> | gist new` 84 3. from STDIN, like `<command> | gist new`
60- You can specify filename with `--file`, and description with `--desc`, like `gist new --file new --desc 'a new gist'` 85- You can specify filename with `--file`, and description with `--desc`, like `gist new --file new --desc 'a new gist'`
61- If you don't specify filename or description, a prompt will shows up! 86- If you don't specify filename or description, a prompt will shows up!
62 87
63### Modify a gist 88### Modify a gist
64Run `gist <index-of-gist>` to use default editor to open files in local repo (by default action). Also use `cd $(gist <index-of-gist>)` to cd to that repo. You can do some trick to simplify it.(See [action](#action) and [Tips](#Tips)) 89Run `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](#action) and [Tips](#Tips))
65 90
66Since now a gist is a local cloned repo, it is your business to do git commit and git push. Use `gist push <index-of-gist>` is not recommended. 91Since 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.
67 92
68### Clean unnecessary local repos 93### Clean unnecessary local repos
69Say 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` 94Say 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`
70 95
71## Configuration 96## Configuration
72`gist` stores your configuraion inside `~/.config/gist.conf`, with `<key>=<value>` format for each line. And just do `source ~/.config/gist.con` at runtime. This file is created automatically when you do the first configuration, and only allows current user to read and write (permission 600). 97`gist` stores your configuraion inside `~/.config/gist.conf`, with `<key>=<value>` format for each line. And just do `source ~/.config/gist.conf` at runtime.
73 98
74Valid keys are [`user`](#user), [`token`](#token), [`folder`](#folder), [`auto_sync`](#auto_sync), [`action`](#action), [`EDITOR`](#EDITOR) and [protocol](#protocol). Use the following commads to set value: 99This file is created automatically when you use `gist` at the first time, it only allows current user to read and write (permission 600).
100
101Valid keys are [`user`](#user), [`token`](#token), [`folder`](#folder), [`auto_sync`](#auto_sync), [`action`](#action), [`EDITOR`](#EDITOR) and [`protocol`](#protocol). Use the following commands to set value:
75``` bash 102``` bash
76gist config <key> <value> 103gist config <key> <value>
77 104
@@ -108,20 +135,21 @@ Use `gist config folder <prefered-directory>` to set the value if needed.
108Use `gist config auto_sync false` to disable this feature. 135Use `gist config auto_sync false` to disable this feature.
109 136
110### action 137### action
111**[Optional]** A custom action is performed when you do `gist <index-of-gist>` (like `gist 3` for your third gist). If is being set, `gist` will `cd` to the cloned repo, and just simply use `eval` to perform action. 138**[Optional]** A custom action is performed when you do `gist <INDEX>` (like `gist 3` for your third gist). If is being set, `gist` will `cd` to the cloned repo, and just simply use `eval` to perform action.
112 139
113For example, you can use the following command to set the action for: 140For example, you can use the following command to
114**print the filename and its content of all files inside the given gist** 141**print the filename and its content of all files inside the given gist**
115```bash 142```bash
116gist config action 'tail -n +1 *' 143gist config action 'tail -n +1 *'
117``` 144```
118or do 145
146If action is not being set, then a default action will be performed:
119```bash 147```bash
120gist config action '${EDITOR:-vi} .' 148# Enter sub-shell with current shell or bash
149${SHELL:-bash}
121``` 150```
122That is, use default editor or vi (if not being set) to open the cloned repo.
123 151
124Also, if you run `gist <index-of-gist>` with `--no-action`, then action would be ignored. 152Also, if you run `gist <INDEX>` with `--no-action`, then action would be ignored.
125 153
126### EDITOR 154### EDITOR
127**[Optional]** Editor to open `~/.config/gist.conf`. Default to be `vi` . 155**[Optional]** Editor to open `~/.config/gist.conf`. Default to be `vi` .
@@ -136,45 +164,119 @@ valid values are:
136 164
137For example, use `gist config protocol ssh` to use SSH protocol instead. 165For example, use `gist config protocol ssh` to use SSH protocol instead.
138 166
139## Tips 167## Filter gists
168### Filter by tags
169`gist` treats **trailing hashtags** inside gist description as tags. For example, if a description s:
170```
171[Title] this is description #tag1 #tag2
172```
173When [`gist`](#List-your-gists) is performed, it only display description with part: `[Title] this is description`, and treat the trailing hashtags as tags of a gist.
174
175#### Tag a gist
176You can use the following command to add/remove tags:
177```bash
178# tag your third gist
179gist tag 3
180```
181After it is finished, `gist` just calls Github API to apply new description onto the given gist.
182
183#### Display list with tags
184Use sub-command `tag` to show the list of gists with tags instead of URLs.
185```bash
186# show tags for your gists
187gist tag
188```
189![](https://i.imgur.com/6IqxQjA.png)
190
191#### Filter gists with tags
192If arguments after `gist tag` are not indices of gist, then they will be treated as tag values. The output will be a list of gists with those tags
193```bash
194# Filter gists with tag1 and tag2
195gist tag tag1 tag2
196```
197![](https://i.imgur.com/rchqMN1.png)
198
199#### Pin/Unpin tags
200Say you are working with gists with some meaningful tags. You can use sub-command `pin` to pin them, and filter your gists with pinned tags
201```bash
202# Pin tag1 and tag2, If a tag is pinned, then unpin it
203gist pin tag1 tag2
204# Disply gists with pinned tags
205gist pin
206```
207![](https://i.imgur.com/LuEjNry.png)
208
209### Filter by pattern
210You can search gists with pattern in description, filename or file contents with sub-command `grep`
211```bash
212# search by a simple string
213gist grep string
214# search by a pattern(heading string in a line)
215gist grep '^string'
216```
217
218## Filter by file languages
219#### Display list with languages
220You can use sub-command `lan` to show the list of gists with file languages instead of URLs.
221```bash
222# show languages for your gists
223gist lan
224```
225![](https://i.imgur.com/QAS7ZRE.png)
226
227#### Filter gists with languages
228```bash
229# Filter gists with files in Shell and Yaml format
230gist lan
231```
232![](https://i.imgur.com/tKI5KND.png)
233
140### Index Range 234### Index Range
235You can specify the range of indices, works both on your owned gists and starred gists.
141```bash 236```bash
142# show gists from index 5
143gist 5-
144# show starred gists from index s3
145gist s3-
146# only show gists with index 5 to 10 237# only show gists with index 5 to 10
147gist 5-10 238gist 5-10
239# show gists from index 5
240gist 5-
241# show starred gists only to index s10
242gist -s10
243# only show gists with index 1 to 20
244seq 20 | gist
148``` 245```
149 246
150### Filter 247## Tips
248
249### Filter gists with pipe
250If `STDIN` is from a pipe, then `gist` will only process gists with **indices in the first column**. So, you can concatenate the output of each sub-command.
151```bash 251```bash
252# only show gists with index 1 to 20
253seq 20 | gist
254# Show the list of starred gist with Yaml file
255gist star | gist lan Yaml
256# Only show the list of gists with tag1, pattern1 in description/filenames/contents and markdown file
152gist tag tag1 | gist grep pattern1 | gist lan SHELL 257gist tag tag1 | gist grep pattern1 | gist lan SHELL
153``` 258```
154 259
155### Git Branching 260### Git Branching
156Each gist is a git repository. Although there are some limits on `git push`, like sub-directory. But guess what? Push another branch to `github.com` is allowed. So why not use this feature for your gist workflow? 261Each gist is a git repository. Although there are some limits on `git push`, like sub-directory. But guess what? Push another branch to `github.com` is allowed. So why not use this feature for your gist workflow?
157 262
158### Jump to gist repo 263### Suppress action
159Sometimes you want to switch to the gist repo as working directory with given index. 264If [`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.
160But since `gist` is a bash script which goes in subshell, if you want to achieve this, it is necessary to configure shell setting by yourself. 265```
266gist config action 'true'
267```
268
269### Useful action for gist repo
270I 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!
271
272If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action:
161 273
162`gist <index-of-gist>` will return the path of repo, so you can put the following function into your `~/.bashrc` or `~/.zshrc` to apply it.
163```bash 274```bash
164 function cdgist() { 275gist config action 'tig -all'
165 local dir=$(gist $1 --no-action) 276```
166 [[ -d $dir ]] && cd $dir
167 }
168 ```
169 And run `cdgist 3` to jump to the repo of your third gist.
170 277
171### Suppress hint 278### Suppress hint
172If [action](#action) is not configured, there is always a hint to show how to configure it. The following command can suppress it with a simple action that does nothing. 279There are several environment variables or arguments can suppress hint or user confirm, like:
173```bash
174gist config action 'true'
175```
176
177There are serveral environment variables can suppress hint or user confirm, like:
178```bash 280```bash
179# show list without hint 281# show list without hint
180hint=false gist 282hint=false gist
@@ -185,14 +287,3 @@ gist 3 --no-action
185# delete your third gist without confirmation 287# delete your third gist without confirmation
186gist delete 3 --force 288gist delete 3 --force
187``` 289```
188
189
190
191### Useful action for gist repo
192I strongly recommend using [`tig`](https://github.com/jonas/tig) as [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!
193
194If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action:
195
196```bash
197gist config action 'tig -all'
198```