From c4b487095fae8eff858ccf7e5d0958652c78b92a Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 25 Dec 2019 12:10:48 +0800 Subject: update --- alias | 1 + scripts/gist | 36 ++++++++++++++++++++++++------------ tigrc | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/alias b/alias index 117802a..34e3876 100644 --- a/alias +++ b/alias @@ -242,6 +242,7 @@ alias and='cd ~/git/geoBingAn.Android' alias cdG='cd ~/git/git' alias cdT='cd ~/git/taiwan-topo' alias cdand='cd ~/git/sample' +alias cdm='cd ~/git/sharkbig.github.io' repo='git@github.com' hub='https://github.com' diff --git a/scripts/gist b/scripts/gist index 558b659..5bfb9d6 100755 --- a/scripts/gist +++ b/scripts/gist @@ -4,12 +4,14 @@ github_api_token=$(cat $SETTING_DIR/tokens/github) user=typebrook folder=~/git/gist +github_api=https://api.github.com +auth_header="Authorization: token $github_api_token" mkdir -p $folder index=$folder/index +# get the list of gists _update() { - # get the list of gists - curl -s -H "Authorization: token $github_api_token" https://api.github.com/users/$user/gists |\ + curl -s -H "$auth_header" $github_api/users/$user/gists |\ jq '.[] | "\( .html_url ) \(.files | keys | length) \( .description )"' |\ tr -d '"' | tac | nl |\ while read line_num link file_num description; do @@ -17,8 +19,8 @@ _update() { done | tee $index } +# clone repos which are not in the local _sync_repos() { - # clone repos which are not in the local machine comm -13 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ xargs -I{} git clone git@github.com:{}.git $folder/{} @@ -32,10 +34,11 @@ _goto_gist() { _delete_gist() { GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') - curl -X DELETE -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID + curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID _update } +# remove repos which are not in user gists anymore _clean_repos() { comm -23 <(find $folder -maxdepth 1 -type d | sed '1d; s#.*/##' | sort) \ <(cat $index | cut -d' ' -f2 | sed 's#.*/##' | sort) |\ @@ -44,9 +47,10 @@ _clean_repos() { _show_detail() { GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') - curl -s -H "Authorization: token $github_api_token" https://api.github.com/gists/$GIST_ID + curl -s -H "$auth_header" $github_api/gists/$GIST_ID } +# create a new gist with a file and description _create_gist() { FILE=$(basename $1) @@ -57,9 +61,14 @@ _create_gist() { }, description: ($DESC) }' -R -s $1 |\ - curl -s -H "Authorization: token $github_api_token" \ - --data @- \ - https://api.github.com/gists + curl -s -H "$auth_header" --data @- $github_api/gists +} + +_edit_gist() { + GIST_ID=$(cat $index | sed -n "$1"p | cut -d' ' -f2 | sed -r 's#.*/##') + + jq -n --arg DESC "$2" '{ description: ($DESC) }' |\ + curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID } if [[ $# -eq 0 ]]; then @@ -69,7 +78,10 @@ fi case "$1" in create | c) - _create_gist $2 "$3" + _create_gist "$2" "$3" + ;; + edit | e) + _edit_gist "$2" "$3" ;; update | u) _update @@ -78,15 +90,15 @@ case "$1" in _sync_repos ;; detail | d) - _show_detail $2 + _show_detail "$2" ;; delete | D) - _delete_gist $2 + _delete_gist "$2" ;; clean | C) _clean_repos ;; *) - _goto_gist $1 + _goto_gist "$1" ;; esac diff --git a/tigrc b/tigrc index 1bfb501..cbe3fd4 100644 --- a/tigrc +++ b/tigrc @@ -94,7 +94,7 @@ bind main 1 +sh -c "git rev-list --all --children | \ bind main b none bind main bn @git branch "%(prompt Enter branch name: )" %(commit) bind main bN @git branch %(branch) --track %(remote)/%(branch) -bind main bu @git branch --set-upstream-to="%(prompt Set remote/branch: )" +bind main bu @git branch --set-upstream-to="%(prompt Set remote: )" %(branch) bind main bc @git checkout -b "%(prompt Checkout at new branch: )" %(commit) bind generic bd @git branch -d "%(prompt Delete branch: )" bind main bbd @git branch -d %(branch) -- cgit v1.2.3-70-g09d2