diff options
| author | typebrook <typebrook@gmail.com> | 2019-12-24 11:45:36 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2019-12-24 11:45:36 +0800 |
| commit | 223871381da8d9f9bb4dfddc35dca7ec4b942880 (patch) | |
| tree | 29b8786e869f9b78836d15427ef1bdad02236ca0 | |
| parent | b747017036f18b3dfc98f363233a53bba4b95143 (diff) | |
update
| -rw-r--r-- | alias | 1 | ||||
| -rwxr-xr-x | scripts/gist/gist | 20 |
2 files changed, 15 insertions, 6 deletions
| @@ -43,6 +43,7 @@ alias ld='cd -' # last directory | |||
| 43 | function cdg(){ | 43 | function cdg(){ |
| 44 | cd ~/git/$1 | 44 | cd ~/git/$1 |
| 45 | } | 45 | } |
| 46 | alias cdgg='cd ~/git/gist' | ||
| 46 | alias cda='cd ~/data' | 47 | alias cda='cd ~/data' |
| 47 | alias cdd='cd ~/Downloads' | 48 | alias cdd='cd ~/Downloads' |
| 48 | alias cdD='cd ~/Documents' | 49 | alias cdD='cd ~/Documents' |
diff --git a/scripts/gist/gist b/scripts/gist/gist index 200ed5a..ab68176 100755 --- a/scripts/gist/gist +++ b/scripts/gist/gist | |||
| @@ -2,24 +2,32 @@ | |||
| 2 | 2 | ||
| 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) | 3 | github_api_token=$(cat $SETTING_DIR/tokens/github) |
| 4 | 4 | ||
| 5 | folder=~/git/gist | ||
| 6 | mkdir -p $folder | ||
| 7 | index=$folder/index | ||
| 8 | |||
| 5 | function _update() { | 9 | function _update() { |
| 10 | # get the list of gists | ||
| 6 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ | 11 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/users/typebrook/gists |\ |
| 7 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ | 12 | jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ |
| 8 | tr -d '"' | tac | nl |\ | 13 | tr -d '"' | tac | nl |\ |
| 9 | while read line_num link file_num description; do | 14 | while read line_num link file_num description; do |
| 10 | echo $line_num $link $file_num $(echo $description | cut -c -70) | 15 | echo $line_num $link $file_num $(echo $description | cut -c -70) |
| 11 | done | tee ~/.gist | 16 | done | tee $index |
| 17 | |||
| 18 | # clone repos which are not in the local | ||
| 19 | comm -13 <(find . -maxdepth 1 -type d | sed '1d; s#\./##' | sort) \ | ||
| 20 | <(cat index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ | ||
| 21 | xargs -I{} git clone git@github.com:{}.git $folder/{} | ||
| 12 | } | 22 | } |
| 13 | 23 | ||
| 14 | function _get_gist() { | 24 | function _get_gist() { |
| 15 | GIST_ID=$(cat ~/.gist | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/([^/]+)$#\1#') | 25 | GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') |
| 16 | 26 | cd $folder/$GIST_ID && tig --all | |
| 17 | curl -s -H "Authorization: OAuth $github_api_token" https://api.github.com/gists/$GIST_ID |\ | ||
| 18 | jq .files | ||
| 19 | } | 27 | } |
| 20 | 28 | ||
| 21 | if [[ $# -eq 0 ]]; then | 29 | if [[ $# -eq 0 ]]; then |
| 22 | cat ~/.gist | 30 | cat $index |
| 23 | exit 0 | 31 | exit 0 |
| 24 | fi | 32 | fi |
| 25 | 33 | ||