diff options
author | typebrook <typebrook@gmail.com> | 2020-04-08 15:04:06 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-04-08 15:04:06 +0800 |
commit | ee7d3d28a8fdea410cd688a0a3f4deb5a196de7b (patch) | |
tree | 7da9079969cd4632456b50ba0409666722e43983 | |
parent | e5d259070da4bc6a6bca62e814b32c73ee5417ef (diff) | |
parent | 0f6da18b752b0a9541e1975518df21bb15b6a2a6 (diff) |
Merge branch 'readme'
-rw-r--r-- | README.md | 217 | ||||
-rwxr-xr-x | gist | 2 |
2 files changed, 164 insertions, 55 deletions
@@ -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 | |||
9 | gist new | 28 | gist new |
10 | # create private gist with files 'foo' and 'bar' | 29 | # create private gist with files 'foo' and 'bar' |
11 | gist new -p foo bar | 30 | gist 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 |
13 | gist 3 | 32 | gist 3 |
14 | # cd to the cloned repo | ||
15 | cd `gist 3` | ||
16 | # push changes in your third gist to the remote repo | 33 | # push changes in your third gist to the remote repo |
17 | gist push 3 | 34 | gist push 3 |
18 | # update the description of your third gist | 35 | # update the description of your third gist |
19 | gist edit 3 | 36 | gist edit 3 |
20 | # delete gists with index 3, 4 and 5 | 37 | # add tags to your third gist |
38 | gist tag 3 | ||
39 | # list your gists with tags instead of URL | ||
40 | gist tag | ||
41 | # delete gists with indices 3, 4 and 5 | ||
21 | gist delete 3 4 5 | 42 | gist delete 3 4 5 |
22 | # or use Brace Expansion | 43 | # or use Brace Expansion |
23 | gist delete {3..5} | 44 | gist 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 |
27 | gist help | 48 | gist help |
28 | ``` | 49 | ``` |
29 | ## Commands | 50 | |
30 | ### Update information and clone gists from Github | 51 | ## Basic Commands |
52 | ### Update and clone gists from Github | ||
31 | 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`) | 53 | 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`) |
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 |
37 | Run `gist` to read index file (default to `~/gist/index`) and list your gists with the folloing format: | 59 | Run `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 | ``` |
41 | like following: | 61 | <index> <gist-URL> <files-number> <comments-number> <description> |
42 |  | 62 | ``` |
63 | |||
64 | like the following: | ||
43 | 65 | ||
44 | - Use `gist star` to show your starred gist | 66 |  |
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 |
52 | Run `gist new` to create a new gist | 80 | Run `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 |
61 | Run `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)) | 89 | 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](#action) and [Tips](#Tips)) |
62 | 90 | ||
63 | Since 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. | 91 | 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. |
64 | 92 | ||
65 | ### Clean unnecessary local repos | 93 | ### Clean unnecessary local repos |
66 | 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` | 94 | 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` |
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 | |||
99 | This 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 | ||
71 | Valid 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: | 101 | Valid 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 |
73 | gist config <key> <value> | 103 | gist config <key> <value> |
74 | 104 | ||
@@ -105,20 +135,21 @@ Use `gist config folder <prefered-directory>` to set the value if needed. | |||
105 | Use `gist config auto_sync false` to disable this feature. | 135 | Use `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 | ||
110 | For example, you can use the following command to set the action for: | 140 | For 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 |
113 | gist config action 'tail -n +1 *' | 143 | gist config action 'tail -n +1 *' |
114 | ``` | 144 | ``` |
115 | or do | 145 | |
116 | ``` | 146 | If action is not being set, then a default action will be performed: |
117 | gist config action '${EDITOR:-vi} .' | 147 | ```bash |
148 | # Enter sub-shell with current shell or bash | ||
149 | ${SHELL:-bash} | ||
118 | ``` | 150 | ``` |
119 | That is, use default editor or vi (if not being set) to open the cloned repo. | ||
120 | 151 | ||
121 | Also, if you run `gist <index-of-gist>` with `--no-action`, then action would be ignored. | 152 | Also, 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 | ||
134 | For example, use `gist config protocol ssh` to use SSH protocol instead. | 165 | For 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 |
138 | Each 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 | ``` | ||
173 | When [`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 |
141 | Sometimes you want to switch to the gist repo as working directory with given index. | 176 | You can use the following command to add/remove tags: |
142 | But 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 | ||
179 | gist tag 3 | ||
180 | ``` | ||
181 | After 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 |
184 | Use 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) | 187 | gist 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 | ||
154 | If [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 | ``` |
156 | gist config action 'true' | 189 |  |
190 | |||
191 | #### Filter gists with tags | ||
192 | If 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 | ||
195 | gist tag tag1 tag2 | ||
157 | ``` | 196 | ``` |
197 |  | ||
158 | 198 | ||
159 | There are serveral environment variables can suppress hint or user confirm, like: | 199 | #### Pin/Unpin tags |
200 | Say 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 | ||
203 | gist pin tag1 tag2 | ||
204 | # Disply gists with pinned tags | ||
205 | gist pin | ||
160 | ``` | 206 | ``` |
161 | # show list without hint | 207 |  |
162 | hint=false gist | ||
163 | 208 | ||
164 | # just print the repo path with a given index | 209 | ### Filter by pattern |
165 | gist 3 --no-action | 210 | You can search gists with pattern in description, filename or file contents with sub-command `grep` |
211 | ```bash | ||
212 | # search by a simple string | ||
213 | gist grep string | ||
214 | # search by a pattern(heading string in a line) | ||
215 | gist grep '^string' | ||
216 | ``` | ||
166 | 217 | ||
167 | # delete your third gist without confirmation | 218 | ## Filter by file languages |
168 | gist delete 3 --force | 219 | #### Display list with languages |
220 | You 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 | ||
223 | gist lan | ||
224 | ``` | ||
225 |  | ||
226 | |||
227 | #### Filter gists with languages | ||
228 | ```bash | ||
229 | # Filter gists with files in Shell and Yaml format | ||
230 | gist lan | ||
231 | ``` | ||
232 |  | ||
233 | |||
234 | ### Index Range | ||
235 | You 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 | ||
238 | gist 5-10 | ||
239 | # show gists from index 5 | ||
240 | gist 5- | ||
241 | # show starred gists only to index s10 | ||
242 | gist -s10 | ||
243 | # only show gists with index 1 to 20 | ||
244 | seq 20 | gist | ||
245 | ``` | ||
246 | |||
247 | ## Tips | ||
248 | |||
249 | ### Filter gists with pipe | ||
250 | If `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 | ||
253 | seq 20 | gist | ||
254 | # Show the list of starred gist with Yaml file | ||
255 | gist star | gist lan Yaml | ||
256 | # Only show the list of gists with tag1, pattern1 in description/filenames/contents and markdown file | ||
257 | gist tag tag1 | gist grep pattern1 | gist lan SHELL | ||
169 | ``` | 258 | ``` |
170 | 259 | ||
260 | ### Git Branching | ||
261 | Each 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 | ||
264 | 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. | ||
265 | ``` | ||
266 | gist config action 'true' | ||
267 | ``` | ||
172 | 268 | ||
173 | ### Useful action for gist repo | 269 | ### Useful action for gist repo |
174 | I 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! | 270 | 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! |
175 | 271 | ||
176 | If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action: | 272 | If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action: |
177 | 273 | ||
178 | ``` | 274 | ```bash |
179 | gist config action 'tig -all' | 275 | gist config action 'tig -all' |
180 | ``` | 276 | ``` |
277 | |||
278 | ### Suppress hint | ||
279 | There are several environment variables or arguments can suppress hint or user confirm, like: | ||
280 | ```bash | ||
281 | # show list without hint | ||
282 | hint=false gist | ||
283 | |||
284 | # just print the repo path with a given index | ||
285 | gist 3 --no-action | ||
286 | |||
287 | # delete your third gist without confirmation | ||
288 | gist delete 3 --force | ||
289 | ``` | ||
@@ -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 |