Skip to content

Commit 6322f3c

Browse files
Hsieh Chin Fanhackmd-deployGeoThings
authored
New Component gist - manage gist in CLI (#213)
* New Component gist - manage gist in CLI run ./gist/gist help for more information * Fix some typo, comments and outdated code * Remove unnecessary quotes with bash syntax * Improve code for configuration - in ~/.config/gist.conf, quote every value to include spaces (mainly for key 'action') - skip prompt for username when not necessary - improve syntax * Use variable to configure behavior - mark 's' for starred gist - hint for showing hint or helper message, default to be true - when create/edit a gist, disable helper message * Improve auto_sync feature Default to be true. When doing `gist fetch` and some gists is not cloned yet, show 'cloning' when it is true, 'not cloned yet' if false (since we are not cloning repo). * Add README for gist * Add more introduction into README * Improve helper message * Improve code with shellcheck * Remove trailing spaces * Fix behavior when fetching gist Just return 0 when there are no gist in response * Add variable for delete confirmation * Add parameter to specify decription when editing * Fix invalid syntax causes error * Update tests Includes the following 14 tests: 1. Tool name 2. Tool version 3. Tool update 4. gist help 5. gist config (for user) 6. gist config (for token) 7. gist new 8. gist fetch 9. gist fetch star 10. gist 11. gist <index> 12. gist edit 13. gist delete 14. gist user * Improve edit command Do not fetch gists again, use response to update local index file * Improve fetch command up to 100 gists Still, need a way to deal with Github pagination if user's gists is more than 100. ref: https://developer.github.com/v3/guides/traversing-with-pagination/ * Fix invalid token in test Since Github check every commit to not include user token, concat strings to avoid this. * Fix syntax error from 4f4f27f * Fix test on Travis CI - Use script from repo, or test for gist would fails - Add gist into install.sh * Fix code for test from 821eb99 * Fix return value for fetch command return 0 anyway even if fail to sync repos * Improve code syntax with shellcheck * Add configuration for git protocol Default to HTTPS, this should suppress the ssh key setting for some users. * Change test pattern to be simpler * Improve edit commend Allow cursor to scroll back when editing new description * Improve user command up to 100 gists Just like what 3e8e57e did * Improve test condition Narrow down the scope of alnum. Also, use pattern for test of user command. * Color description text with braces * Fix/Improve helper message * Fix bug about folder configuration If user gives folder with empty string or not writable, set it to default value `~/gist`. * Improve code style * Fix typo and missing link * Replace default action with hint * Update README * Fix bug about private mark Variable 'mark' should be reset everytime, or the value from previous line would persist. * Return false instantly when the given id is not valid * Change remote url if user configure protocol * Add error message for gist config * Fix bug about parsing starred gists * Refactor code for marking star/non-star gist * Refactor behavior about subcommand detail - Store created/updated time inside index file - gist detail only shows the content from index file * Fix missing argument of sed for darwin * Update output of 'gist user' * Fix default configuration for 'gist fetch' * Show working when checkout to non-master branch * Update helper message and todo item * Improve 'gist grep' Now it supports description, filename and file content * Suppress wrong status message with merged commit * Remove unnecessary exit statement * Change format when creating a new gist * Update todo items * Update comments for functions * Refactor code to reduce repetitive text * Update test to fit changes in 85fb3dd * Update todo items * Add blink visuals to indicate valid indices * Refactor code for order of functions * Improve 'gist push' Allow empty index if user is already inside repo * Refactor code for readibility * Update README * Fix potential error when getting ID from a given index Originally, if user gives command like 'gist .', _gist_id() still returns true * Reformat list of starred gist * Refactor code * Improve/Fix 'gist edit' - Prefill with original description - Fix pattern when editing is finished - Fix unnecessary prefix for result when edit is done * Refactor code about INDEX file format Refactor code to reduce potential code changes when INDEX file format changes * Improve 'gist push' - Allow directly push if commit is ready - Only push when current commit is ahead * Add new subcommand 'gist tag' * Apply hashtags to 'gist detail' - a standalone function to extract hashtags from description - in 'gist detail', split puse description and trailing tags into 2 lines for a clear format * Add definition for characters used in tag * Modify sub-commands for tags - 'gist tag' to show gist list without url but tags insdead - 'gist tags' to list existing tags * Fix column difference caused by color control code * Modify hint wording * Fix logic error with index prefix It loses prefix 'p' for newly created private gist Fow now, decide prefix only in _parse_response() * Reformat 'gist detail' * Modify parameter for 'gist delete' Use environment variable is too risky here * Fix logic error about format Original approach also replace ', ' with ',' in description * Add todo item * Refactor code * Modify behavior for 'gist tag' - Always print list with tag=true - Let tags align right * Add new subcommand 'gist pin' * Fix logic error with invalid index * Modify short subcommand for user form U to u * Improve 'gist tags' and 'gist pin' 'gist tag' - Replace hint with pinned tags 'gist tags' - Display each line by the first charactor - highlight pinned tags - Show pinned tags at the bottom 'gist pin' - With given tags, update pinned tags and do 'gist tags' again - With no aguments, print gists with pinned tags * Improve code readibility * Add color for pinned tags in 'gist tag' * Add todo items * Add pipe support * Fix format for showing author prevent author name concates file number if its length > 12 * Refactor code for tag condition, speed up 'gist tag' * Improve sed usage * Add subcommand 'gist all' To show both user gists and starred gist * Update helper message * Update helper message * Fix dotfile is gone in 'gist detail' * Reformat star list * Add language support * Prevent language contains space * Replace non-parsable file type into 'Text' * Reformat index to let pipe easier Make sure no space in front of index, this helps commands like 'cut' works without extra processing * Add default action 'into subshell' * Improve syntax * Fix logic error in 'gist grep' Remove content greping for hashtags inside original description * Fetch gists after doing 'git push' * Refator grep in 'gist grep' to speed up * Add alert message when index file is empty * Update hint message * Add subcommand 'gist lan' * Add parameter for index range * Suppress hint when STDIN is not empty * Add subcommand 'gist last' * Supress hint message when command is in pipe * Fix logic error about action * Fetch in background when 'gist push' is performed * Update comments * Add hint for mtime of INDEX file * Fix runtime error Only output the first line of grep result in files * Improve 'gist detail' Make it works without index if working dir is a gist repo * Refactor code * Refactor code * Add gist into install/uninstall script Also, with alphabetical order * Add description into README * Refactor helper message for general use case * Chech internet when using Github API * Fix hint configuration * Update manual * Fix error message for 'gist detail' when there is no valid index, show error message * Update README Now it contains contents with new sub-commands: tag, tags, pin, lan * Update README Correct titile level * Improve README with wording * Fix 'gist detail' inside repo * Improve 'gist help' with proper pattern * Enable backspace and readline hotkeys with 'gist new' * Improve 'gist tag <tag-value>' Use user put '.' as pattern, treat them as '[^ ]' * Update helper message and comments * Pin tags with regex pattern * Update todo items * Refactor the way of checking repo status * Add configuration 'show_untagged' * Make Command Substitution works with configuration * Process more after 'gist fetch' * Remove outdated TODO items * Add processing for filename with space * Fix/Refactor the way to process description * Merge branch 'tag-refactor' * Remove method checkInternet All API calls github.com, do not need this. * Add shorter argument '-n' for '--no-action' * Update todo items * Refactor code * Update hint * Fix Mac Compatibility Looks like alias fails in bash script, even after adding: shopt -s expand_aliases * Improve removing temporary files - Specify directory instead of each files to remove - background job cannot be trapped, so need to call script again * Remove temporary file after user create a gist * Add option to debug with log * Allow remove token * Mac compatibility for 'mktemp' * Fix error on Mac when getting gist ID * Fix bats test with latest changes - Use 'gist' instead of 'todo' to get version - 'gist <index>' returns path at the last line - Config file keeps value without single quote now - Use 'gist detail' to check description is modified by 'gist edit' Since the output of 'gist edit' might hides description by small screen width * Remove finished todo item * Refactor variable 'mark' - make it global and export it to sub-shell - refator _sync_repos(), now only do 'git pull' in repos that: 1. Already cloned before 2. Fit the mark. That is, either user's gist or starred gists * Refactor code * Use valid URL when export to github Also change some texts * Refactor code * Improve sub-command 'tag', 'edit' and 'new' 1. By default, do not shows tags for starred gist 2. Tags user typed allow any number of leading '#' 3. Fix the parameter of 'gist edit', it takes arguemnts behind $1 as description 4. An easy to read way to wrap JSON body * Fix sed compatibility for BSD version * Use simpler way to clone repo in background And this way also do not need to export variables into new bash instance * Initialize variables to avoid affetcted by env variables * Update hint text for 'gist clean' * Show status with description, do not override file_num and comment_num * Refactor mark usage So by default, 'gist lan' won't show starred gists * Suppress error msg with insane filename * Change hint and helper message by script name * Also use variable to set hint and helper message * Fix logic error in helper message * Update comments, helper msg and todo items * Refactor code in _configure() * Refactor code * Refactor _show_list() * Fix json processing for 'edit' Looks like xargs cannot handle too many texts * Improve README with wording * Update README * Add configuration 'show_untagged' Co-authored-by: HackMD <no-reply@hackmd.io> Co-authored-by: GeoThings <geothings@GeoThingss-MacBook-Pro.local>
1 parent 367f5f5 commit 6322f3c

10 files changed

+2291
-3
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ Provides data for wan, lan, router, dns, mac, and ip geolocation
129129
Written by: [Jake Meyer](https://github.com/jakewmeyer)
130130
</details>
131131

132+
<details>
133+
<summary>Gist</summary>
134+
135+
Manage your gist like a pro
136+
137+
Clone your owned gists and starred gists as git repos, and Fetch/Create/Edit/Delete them with Github API. It also supports quick search with hashtag and contents.
138+
139+
For more information, please go through the [guide](gist/README.md)
140+
141+
<div align="center">
142+
143+
<img max-height="500px" max-width="500px" src="https://github.com/alexanderepstein/Bash-Snippets/blob/master/gist/gist.png?raw=true">
144+
145+
</div>
146+
147+
Written by: [typebrook](https://github.com/typebrook)
148+
</details>
149+
132150
<details>
133151
<summary>Lyrics</summary>
134152

bash-snippets.1

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BASH\-SNIPPETS" "1" "December 2017" "ff" ""
4+
.TH "BASH\-SNIPPETS" "1" "April 2020" "" ""
55
.
66
.SH "NAME"
77
\fBbash\-snippets\fR \- A collection of small bash scripts for heavy terminal users
@@ -274,6 +274,91 @@ Example: geo \-a 8\.8\.8\.8 \-o city,zip,isp
274274
.
275275
.IP "" 0
276276
.
277+
.SS "Gist"
278+
Description: Manage your gists with git and Github API v3
279+
.
280+
.P
281+
Usage: gist [command] [args]
282+
.
283+
.IP "\(bu" 4
284+
[star|all] List your gists, use \'star\' as argument for your starred gists, \'all\' or \'a\' for both your and starred gists\. Format for each line is: \fIINDEX\fR \fIURL\fR \fIFILE_NUM\fR \fICOMMENT_NUM\fR \fIDESCRIPTION\fR
285+
.
286+
.IP "\(bu" 4
287+
fetch Update the local list of your gists, \'star\' as argument for your starred gists
288+
.
289+
.IP "\(bu" 4
290+
\fIINDEX\fR Show the path of local gist repo and do custom actions
291+
.
292+
.IP "\(bu" 4
293+
new Create a new gist with files or STDIN
294+
.
295+
.IP "\(bu" 4
296+
grep Grep gists by description, filename and content with a given pattern
297+
.
298+
.IP "\(bu" 4
299+
tag Modify/List tags for a gist
300+
.
301+
.IP "\(bu" 4
302+
tags List all tags and pinned tags
303+
.
304+
.IP "\(bu" 4
305+
pin, Pin/Unpin tags, or filter gists with pinned tags
306+
.
307+
.IP "\(bu" 4
308+
lan Filter gists or list gist with coding languages
309+
.
310+
.IP "\(bu" 4
311+
detail Show the detail of a gist
312+
.
313+
.IP "\(bu" 4
314+
edit Edit description for a gist
315+
.
316+
.IP "\(bu" 4
317+
delete Delete gists by given indices
318+
.
319+
.IP "\(bu" 4
320+
push Push changes by git
321+
.
322+
.IP "\(bu" 4
323+
clean Clean local repos of removed gists
324+
.
325+
.IP "\(bu" 4
326+
config Do configuration
327+
.
328+
.IP "\(bu" 4
329+
user Get list of gists with a given Github user
330+
.
331+
.IP "\(bu" 4
332+
github Import selected gist as a new Github repo
333+
.
334+
.IP "\(bu" 4
335+
help Show the helper message
336+
.
337+
.IP "" 0
338+
.
339+
.P
340+
Example:
341+
.
342+
.IP "\(bu" 4
343+
gist (Show your gists)
344+
.
345+
.IP "\(bu" 4
346+
gist tag (Show your gists with tags)
347+
.
348+
.IP "\(bu" 4
349+
gist fetch (update the list of gists from github\.com)
350+
.
351+
.IP "\(bu" 4
352+
gist 3 (show the repo path of your 3rd gist, and do custom actions)
353+
.
354+
.IP "\(bu" 4
355+
gist 3 \-\-no\-action (show the repo path of your 3rd gist, and do not perform actions)
356+
.
357+
.IP "\(bu" 4
358+
gist new \-\-desc bar foo (create a new gist with files and description)
359+
.
360+
.IP "" 0
361+
.
277362
.SS "Lyrics"
278363
Description: Fetch lyrics for a certain song\.
279364
.

0 commit comments

Comments
 (0)