aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-04-08 15:04:06 +0800
committertypebrook <typebrook@gmail.com>2020-04-08 15:04:06 +0800
commitee7d3d28a8fdea410cd688a0a3f4deb5a196de7b (patch)
tree7da9079969cd4632456b50ba0409666722e43983
parente5d259070da4bc6a6bca62e814b32c73ee5417ef (diff)
parent0f6da18b752b0a9541e1975518df21bb15b6a2a6 (diff)
Merge branch 'readme'
-rw-r--r--README.md217
-rwxr-xr-xgist2
2 files changed, 164 insertions, 55 deletions
diff --git a/README.md b/README.md
index da70fdb..4699ae4 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,23 @@
1# gist - Manage your gist like a pro 1# gist - Manage your gist like a pro
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)
20
2## Getting started 21## Getting started
3```bash 22```bash
4# fetch your gists and clone them into ~/gist as git repos 23# fetch your gists and clone them into ~/gist as git repos
@@ -9,15 +28,17 @@ gist
9gist new 28gist new
10# create private gist with files 'foo' and 'bar' 29# create private gist with files 'foo' and 'bar'
11gist new -p foo bar 30gist new -p foo bar
12# get the path of cloned repo of your third gist 31# get the path and cd to cloned repo with subshell
13gist 3 32gist 3
14# cd to the cloned repo
15cd `gist 3`
16# push changes in your third gist to the remote repo 33# push changes in your third gist to the remote repo
17gist push 3 34gist push 3
18# update the description of your third gist 35# update the description of your third gist
19gist edit 3 36gist edit 3
20# 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
21gist delete 3 4 5 42gist delete 3 4 5
22# or use Brace Expansion 43# or use Brace Expansion
23gist delete {3..5} 44gist delete {3..5}
@@ -26,49 +47,58 @@ gist github 3
26# For more detail, read the helper message 47# For more detail, read the helper message
27gist help 48gist help
28``` 49```
29## Commands 50
30### Update information and clone gists from Github 51## Basic Commands
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/`)
33- Run `gist fetch star` to fetch you starred gist 55- Run `gist fetch star` to fetch you starred gist
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```
39[index] [gist-URL] [files-number] [comments-number] [description]
40``` 60```
41like following: 61<index> <gist-URL> <files-number> <comments-number> <description>
42![](https://i.imgur.com/CP6ZL2G.png) 62```
63
64like the following:
43 65
44- Use `gist star` to show your starred gist 66![](https://i.imgur.com/ZCLGZLW.png)
67
68- Use `gist star` to show your starred gists
69- Use `gist all` to show your and starred gists
45- 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
46- There are colorful hints for each gist in the following cases: 71- There are colorful hints for each gist in the following cases:
47 - **working:** some changes are made locally but not yet do `git commit`, or you are not in `master` branch 72 - **working**
48 - **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
49 - **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
50 78
51### Create a new gist 79### Create a new gist
52Run `gist new` to create a new gist 80Run `gist new` to create a new gist
53- You can create a new gist with 3 different ways: 81- You can create a new gist with 3 different ways:
54 1. type the content by hand, run `gist new` 82 1. type the content by hand, run `gist new`
55 2. use existig files, run `gist new <file1> <file2>...` 83 2. use existing files, run `gist new <file1> <file2>...`
56 3. from STDIN, like `<command> | gist new` 84 3. from STDIN, like `<command> | gist new`
57- 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'`
58- 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!
59 87
60### Modify a gist 88### Modify a gist
61Run `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))
62 90
63Since 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.
64 92
65### Clean unnecessary local repos 93### Clean unnecessary local repos
66Say 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`
67 95
68## Configuration 96## Configuration
69`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.
98
99This file is created automatically when you use `gist` at the first time, it only allows current user to read and write (permission 600).
70 100
71Valid 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: 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:
72``` bash 102``` bash
73gist config <key> <value> 103gist config <key> <value>
74 104
@@ -105,20 +135,21 @@ Use `gist config folder <prefered-directory>` to set the value if needed.
105Use `gist config auto_sync false` to disable this feature. 135Use `gist config auto_sync false` to disable this feature.
106 136
107### action 137### action
108**[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.
109 139
110For example, you can use the following command to set the action for: 140For example, you can use the following command to
111**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**
112``` 142```bash
113gist config action 'tail -n +1 *' 143gist config action 'tail -n +1 *'
114``` 144```
115or do 145
116``` 146If action is not being set, then a default action will be performed:
117gist config action '${EDITOR:-vi} .' 147```bash
148# Enter sub-shell with current shell or bash
149${SHELL:-bash}
118``` 150```
119That is, use default editor or vi (if not being set) to open the cloned repo.
120 151
121Also, 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.
122 153
123### EDITOR 154### EDITOR
124**[Optional]** Editor to open `~/.config/gist.conf`. Default to be `vi` . 155**[Optional]** Editor to open `~/.config/gist.conf`. Default to be `vi` .
@@ -133,48 +164,126 @@ valid values are:
133 164
134For example, use `gist config protocol ssh` to use SSH protocol instead. 165For example, use `gist config protocol ssh` to use SSH protocol instead.
135 166
136## Tips 167## Filter gists
137### Git Branching 168### Filter by tags
138Each 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? 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.
139 174
140### Jump to gist repo 175#### Tag a gist
141Sometimes you want to switch to the gist repo as working directory with given index. 176You can use the following command to add/remove tags:
142But 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. 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.
143 182
144`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. 183#### Display list with tags
184Use sub-command `tag` to show the list of gists with tags instead of URLs.
145```bash 185```bash
146 function cdgist() { 186# show tags for your gists
147 local dir=$(gist $1 --no-action) 187gist tag
148 [[ -d $dir ]] && cd $dir
149 }
150 ```
151 And run `cdgist 3` to jump to the repo of your third gist.
152
153### Suppress hint
154If [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.
155``` 188```
156gist config action 'true' 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
157``` 196```
197![](https://i.imgur.com/rchqMN1.png)
158 198
159There are serveral environment variables can suppress hint or user confirm, like: 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
160``` 206```
161# show list without hint 207![](https://i.imgur.com/LuEjNry.png)
162hint=false gist
163 208
164# just print the repo path with a given index 209### Filter by pattern
165gist 3 --no-action 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```
166 217
167# delete your third gist without confirmation 218## Filter by file languages
168gist delete 3 --force 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
234### Index Range
235You can specify the range of indices, works both on your owned gists and starred gists.
236```bash
237# only show gists with index 5 to 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
245```
246
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.
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
257gist tag tag1 | gist grep pattern1 | gist lan SHELL
169``` 258```
170 259
260### Git Branching
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?
171 262
263### Suppress action
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.
265```
266gist config action 'true'
267```
172 268
173### Useful action for gist repo 269### Useful action for gist repo
174I 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! 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!
175 271
176If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action: 272If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action:
177 273
178``` 274```bash
179gist config action 'tig -all' 275gist config action 'tig -all'
180``` 276```
277
278### Suppress hint
279There are several environment variables or arguments can suppress hint or user confirm, like:
280```bash
281# show list without hint
282hint=false gist
283
284# just print the repo path with a given index
285gist 3 --no-action
286
287# delete your third gist without confirmation
288gist delete 3 --force
289```
diff --git a/gist b/gist
index 8158d5b..5a10d90 100755
--- a/gist
+++ b/gist
@@ -350,7 +350,7 @@ _grep_content() {
350 && hint=false mark="$index " _show_list \ 350 && hint=false mark="$index " _show_list \
351 && echo -e " $file$content" 351 && echo -e " $file$content"
352 fi 352 fi
353 done | grep --color=always -Ei -C1 "$1" 353 done
354} 354}
355 355
356# Parse JSON object of the result of gist fetch 356# Parse JSON object of the result of gist fetch