diff options
author | typebrook <typebrook@gmail.com> | 2020-04-08 15:03:57 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-04-08 15:03:57 +0800 |
commit | 0f6da18b752b0a9541e1975518df21bb15b6a2a6 (patch) | |
tree | 105ee699799f61dc9dc78bd632394312db2a5f91 | |
parent | 039ec62e65224bae703f57d31bb6557fa4d7d4a1 (diff) |
Update README
-rw-r--r-- | README.md | 197 |
1 files changed, 144 insertions, 53 deletions
@@ -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 |
6 | gist fetch | 24 | gist fetch |
@@ -16,7 +34,11 @@ gist 3 | |||
16 | gist push 3 | 34 | gist push 3 |
17 | # update the description of your third gist | 35 | # update the description of your third gist |
18 | gist edit 3 | 36 | gist edit 3 |
19 | # 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 | ||
20 | gist delete 3 4 5 | 42 | gist delete 3 4 5 |
21 | # or use Brace Expansion | 43 | # or use Brace Expansion |
22 | gist delete {3..5} | 44 | gist delete {3..5} |
@@ -26,7 +48,7 @@ gist github 3 | |||
26 | gist help | 48 | gist help |
27 | ``` | 49 | ``` |
28 | 50 | ||
29 | ## Commands | 51 | ## Basic Commands |
30 | ### Update and clone gists from Github | 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/`) |
@@ -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 |
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 | ``` | 60 | ``` |
39 | [index] [gist-URL] [files-number] [comments-number] [description] | 61 | <index> <gist-URL> <files-number> <comments-number> <description> |
40 | ``` | 62 | ``` |
41 | 63 | ||
42 | like the following: | 64 | like 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 |
55 | Run `gist new` to create a new gist | 80 | Run `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 |
64 | 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)) |
65 | 90 | ||
66 | 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. |
67 | 92 | ||
68 | ### Clean unnecessary local repos | 93 | ### Clean unnecessary local repos |
69 | 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` |
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 | ||
74 | 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: | 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). |
100 | |||
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: | ||
75 | ``` bash | 102 | ``` bash |
76 | gist config <key> <value> | 103 | gist config <key> <value> |
77 | 104 | ||
@@ -108,20 +135,21 @@ Use `gist config folder <prefered-directory>` to set the value if needed. | |||
108 | Use `gist config auto_sync false` to disable this feature. | 135 | Use `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 | ||
113 | For example, you can use the following command to set the action for: | 140 | For 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 |
116 | gist config action 'tail -n +1 *' | 143 | gist config action 'tail -n +1 *' |
117 | ``` | 144 | ``` |
118 | or do | 145 | |
146 | If action is not being set, then a default action will be performed: | ||
119 | ```bash | 147 | ```bash |
120 | gist config action '${EDITOR:-vi} .' | 148 | # Enter sub-shell with current shell or bash |
149 | ${SHELL:-bash} | ||
121 | ``` | 150 | ``` |
122 | That is, use default editor or vi (if not being set) to open the cloned repo. | ||
123 | 151 | ||
124 | 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. |
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 | ||
137 | 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. |
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 | ``` | ||
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. | ||
174 | |||
175 | #### Tag a gist | ||
176 | You can use the following command to add/remove tags: | ||
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. | ||
182 | |||
183 | #### Display list with tags | ||
184 | Use sub-command `tag` to show the list of gists with tags instead of URLs. | ||
185 | ```bash | ||
186 | # show tags for your gists | ||
187 | gist tag | ||
188 | ``` | ||
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 | ||
196 | ``` | ||
197 |  | ||
198 | |||
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 | ||
206 | ``` | ||
207 |  | ||
208 | |||
209 | ### Filter by pattern | ||
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 | ``` | ||
217 | |||
218 | ## Filter by file languages | ||
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 | |||
140 | ### Index Range | 234 | ### Index Range |
235 | You 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 | ||
143 | gist 5- | ||
144 | # show starred gists from index s3 | ||
145 | gist s3- | ||
146 | # only show gists with index 5 to 10 | 237 | # only show gists with index 5 to 10 |
147 | gist 5-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 | ||
148 | ``` | 245 | ``` |
149 | 246 | ||
150 | ### Filter | 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. | ||
151 | ```bash | 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 | ||
152 | gist tag tag1 | gist grep pattern1 | gist lan SHELL | 257 | gist tag tag1 | gist grep pattern1 | gist lan SHELL |
153 | ``` | 258 | ``` |
154 | 259 | ||
155 | ### Git Branching | 260 | ### Git Branching |
156 | 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? | 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? |
157 | 262 | ||
158 | ### Jump to gist repo | 263 | ### Suppress action |
159 | Sometimes you want to switch to the gist repo as working directory with given index. | 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. |
160 | 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. | 265 | ``` |
266 | gist config action 'true' | ||
267 | ``` | ||
268 | |||
269 | ### Useful action for gist repo | ||
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! | ||
271 | |||
272 | If [`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() { | 275 | gist 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 |
172 | 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. | 279 | There are several environment variables or arguments can suppress hint or user confirm, like: |
173 | ```bash | ||
174 | gist config action 'true' | ||
175 | ``` | ||
176 | |||
177 | There 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 |
180 | hint=false gist | 282 | hint=false gist |
@@ -185,14 +287,3 @@ gist 3 --no-action | |||
185 | # delete your third gist without confirmation | 287 | # delete your third gist without confirmation |
186 | gist delete 3 --force | 288 | gist delete 3 --force |
187 | ``` | 289 | ``` |
188 | |||
189 | |||
190 | |||
191 | ### Useful action for gist repo | ||
192 | 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! | ||
193 | |||
194 | If [`tig`](https://github.com/jonas/tig) is installed, run the following command to configure it as custom action: | ||
195 | |||
196 | ```bash | ||
197 | gist config action 'tig -all' | ||
198 | ``` | ||