diff options
author | typebrook <typebrook@gmail.com> | 2020-01-04 00:07:22 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-01-04 00:07:22 +0800 |
commit | eeb7d09d1cd1eb13804d11e84ed1480e38f463c3 (patch) | |
tree | 52caf7a1360f7408cd53eac9c20ddf6d68e1980f | |
parent | bce3980d54e051f68a858114993b1e3901bd4122 (diff) | |
parent | 07228d5f372d171618f28a64b446759e7eeadf4a (diff) |
Merge commit '07228d5f372d171618f28a64b446759e7eeadf4a' into dev
-rw-r--r-- | alias | 34 | ||||
-rwxr-xr-x | scripts/gist | 24 | ||||
-rwxr-xr-x | scripts/upload-github-release-asset.sh | 8 |
3 files changed, 38 insertions, 28 deletions
@@ -24,19 +24,24 @@ vs() { | |||
24 | # shell | 24 | # shell |
25 | alias src="source $HOME/.$(basename $SHELL)rc" | 25 | alias src="source $HOME/.$(basename $SHELL)rc" |
26 | alias ll='ls -alh' | 26 | alias ll='ls -alh' |
27 | alias si='sudo snap install' # snap install | 27 | alias hg='history | grep' |
28 | alias ni='sudo npm install -g' # nodejs install | ||
29 | alias ss='sudo !!' | ||
30 | alias hg='history|grep' | ||
31 | alias rmrf='rm -rf' | 28 | alias rmrf='rm -rf' |
32 | alias rr='move_to_tmp' | 29 | alias rr='move_to_tmp' |
33 | move_to_tmp() { | 30 | move_to_tmp() { |
34 | mv $@ /tmp | 31 | mv $@ /tmp |
35 | } | 32 | } |
33 | prompt() { | ||
34 | TMPFILE=$(mktemp); echo -e $1 > $TMPFILE && \ | ||
35 | vim $TMPFILE && \ | ||
36 | sed -i '$ q; s/$/ \\/' $TMPFILE && \ | ||
37 | eval $(cat $TMPFILE | tee /dev/tty) | ||
38 | } | ||
36 | 39 | ||
37 | # package | 40 | # package |
38 | alias ai='sudo apt install' # apt install | 41 | alias ai='sudo apt install' # apt install |
39 | alias aptu='sudo apt update && sudo apt upgrade' | 42 | alias aptu='sudo apt update && sudo apt upgrade' |
43 | alias si='sudo snap install' # snap install | ||
44 | alias ni='sudo npm install -g' # nodejs install | ||
40 | 45 | ||
41 | # cd to DIRs | 46 | # cd to DIRs |
42 | alias ..='cd ..' | 47 | alias ..='cd ..' |
@@ -71,9 +76,9 @@ wi() { | |||
71 | alias ce='crontab -e' | 76 | alias ce='crontab -e' |
72 | 77 | ||
73 | # ranger | 78 | # ranger |
74 | alias r='_ranger-cd' | 79 | alias r='_ranger_cd' |
75 | alias ranrc='vim ~/.config/ranger/rc.conf' | 80 | alias ranrc='vim ~/.config/ranger/rc.conf' |
76 | _ranger-cd() { | 81 | _ranger_cd() { |
77 | tempfile="$(mktemp -t tmp.XXXXXX)" | 82 | tempfile="$(mktemp -t tmp.XXXXXX)" |
78 | ranger --choosedir="$tempfile" "${@:-$(pwd)}" | 83 | ranger --choosedir="$tempfile" "${@:-$(pwd)}" |
79 | test -f "$tempfile" && | 84 | test -f "$tempfile" && |
@@ -99,6 +104,10 @@ gcg() { | |||
99 | } | 104 | } |
100 | alias gls='git log -S' | 105 | alias gls='git log -S' |
101 | alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule | 106 | alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule |
107 | github_release_asset() { | ||
108 | command="upload-github-release-asset.sh\n github_api_token=$(cat ~/settings/tokens/github)\n owner=typebrook\n repo=tig\n tag=LATEST\n filename=$(which tig)\n overwrite=false" | ||
109 | prompt "$command" | ||
110 | } | ||
102 | 111 | ||
103 | # docker | 112 | # docker |
104 | alias dp='docker ps' | 113 | alias dp='docker ps' |
@@ -122,7 +131,7 @@ alias t='tig' | |||
122 | alias ts='tig status' | 131 | alias ts='tig status' |
123 | alias ta='tig --all' | 132 | alias ta='tig --all' |
124 | alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2.5.0/tig' | 133 | alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2.5.0/tig' |
125 | upload-tig() { | 134 | upload_tig() { |
126 | upload-github-release-asset.sh \ | 135 | upload-github-release-asset.sh \ |
127 | github_api_token=$(cat ~/settings/tokens/github) \ | 136 | github_api_token=$(cat ~/settings/tokens/github) \ |
128 | owner=typebrook \ | 137 | owner=typebrook \ |
@@ -138,7 +147,7 @@ alias adb-default='adb shell dumpsys package domain-preferred-apps' | |||
138 | alias adb-list='adb shell dumpsys package d' | 147 | alias adb-list='adb shell dumpsys package d' |
139 | alias rmcache='rm -rf ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/*' | 148 | alias rmcache='rm -rf ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/*' |
140 | alias adb-last-screenshot='adb pull /sdcard/Screenshots/`adb shell ls -t /sdcard/Screenshots/ | head -1` ~/Desktop' | 149 | alias adb-last-screenshot='adb pull /sdcard/Screenshots/`adb shell ls -t /sdcard/Screenshots/ | head -1` ~/Desktop' |
141 | adb-push() { | 150 | adb_push() { |
142 | adb push $1 /sdcard/Download | 151 | adb push $1 /sdcard/Download |
143 | } | 152 | } |
144 | 153 | ||
@@ -191,10 +200,7 @@ alias data-osm-diff="curl https://planet.openstreetmap.org/replication/minute/st | |||
191 | alias data-taiwan-town='curl -o town.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=CD02C824-45C5-48C8-B631-98B205A2E35A' | 200 | alias data-taiwan-town='curl -o town.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=CD02C824-45C5-48C8-B631-98B205A2E35A' |
192 | alias data-taiwan-village='curl -o village.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE' | 201 | alias data-taiwan-village='curl -o village.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE' |
193 | alias data-taiwan-poly='curl -O http://download.geofabrik.de/asia/taiwan.poly' | 202 | alias data-taiwan-poly='curl -O http://download.geofabrik.de/asia/taiwan.poly' |
194 | data-taiwan-county-code() { | 203 | alias data-taiwan-county-code='curl --silent https://www.ris.gov.tw/documents/data/5/1/RSCD0101.txt | iconv -f BIG-5 -t UTF-8 -' |
195 | curl --silent https://www.ris.gov.tw/documents/data/5/1/RSCD0101.txt |\ | ||
196 | iconv -f BIG-5 -t UTF-8 - | ||
197 | } | ||
198 | 204 | ||
199 | # clipboard | 205 | # clipboard |
200 | alias xi='xsel -ib' | 206 | alias xi='xsel -ib' |
@@ -244,13 +250,9 @@ alias cdo='cd ~/git/openmaptiles' | |||
244 | alias cdS='cd ~/git/StreetComplete' | 250 | alias cdS='cd ~/git/StreetComplete' |
245 | alias cdW='cd ~/git/geoBingAnWeb' | 251 | alias cdW='cd ~/git/geoBingAnWeb' |
246 | alias and='cd ~/git/geoBingAn.Android' | 252 | alias and='cd ~/git/geoBingAn.Android' |
247 | alias cdG='cd ~/git/git' | ||
248 | alias cdT='cd ~/git/taiwan-topo' | 253 | alias cdT='cd ~/git/taiwan-topo' |
249 | alias cdand='cd ~/git/sample' | 254 | alias cdand='cd ~/git/sample' |
250 | alias cdm='cd ~/git/sharkbig.github.io/rescue' | 255 | alias cdm='cd ~/git/sharkbig.github.io/rescue' |
251 | alias cdmw='cd ~/git/sharkbig.github.io/.github/workflows' | 256 | alias cdmw='cd ~/git/sharkbig.github.io/.github/workflows' |
252 | 257 | ||
253 | repo='git@github.com' | ||
254 | hub='https://github.com' | ||
255 | typebrook='git@github.com:typebrook' | ||
256 | GITHUB_API='https://api.github.com' | 258 | GITHUB_API='https://api.github.com' |
diff --git a/scripts/gist b/scripts/gist index 9dfa31d..b55012b 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -49,6 +49,9 @@ auth_header="Authorization: token $github_api_token" | |||
49 | mkdir -p $folder | 49 | mkdir -p $folder |
50 | index=$folder/index | 50 | index=$folder/index |
51 | 51 | ||
52 | # Validate settings. | ||
53 | [ "$TRACE" ] && set -x && echo foo | ||
54 | |||
52 | # get the list of gists | 55 | # get the list of gists |
53 | _update() { | 56 | _update() { |
54 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ | 57 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ |
@@ -107,15 +110,19 @@ _show_detail() { | |||
107 | # create a new gist with a file and description | 110 | # create a new gist with a file and description |
108 | # TODO support folder of files | 111 | # TODO support folder of files |
109 | _create_gist() { | 112 | _create_gist() { |
110 | FILE=$(basename $1) | 113 | echo -n 'description: ' |
114 | read DESC | ||
111 | 115 | ||
112 | jq --arg FILE "$FILE" --arg DESC "$2" '. as $content | { | 116 | echo $@ | tr " " "\n" |\ |
113 | public: true, | 117 | while read file; do |
114 | files: { | 118 | FILE=$(basename $file) |
115 | ($FILE): {content: $content} | 119 | jq --arg FILE "$FILE" '. as $content | { ($FILE): {content: $content} }' -Rs $file |
116 | }, | 120 | done |\ |
121 | jq -s --arg DESC "$DESC" '{ | ||
122 | public: true, | ||
123 | files: add, | ||
117 | description: ($DESC) | 124 | description: ($DESC) |
118 | }' -R -s $1 |\ | 125 | }' |\ |
119 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ | 126 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ |
120 | _update | 127 | _update |
121 | } | 128 | } |
@@ -134,7 +141,8 @@ case "$1" in | |||
134 | cat $index | 141 | cat $index |
135 | ;; | 142 | ;; |
136 | create | c) | 143 | create | c) |
137 | _create_gist "$2" "$3" | 144 | shift; |
145 | _create_gist $@ | ||
138 | ;; | 146 | ;; |
139 | edit | e) | 147 | edit | e) |
140 | _edit_gist "$2" "$3" | 148 | _edit_gist "$2" "$3" |
diff --git a/scripts/upload-github-release-asset.sh b/scripts/upload-github-release-asset.sh index 6923870..0325530 100755 --- a/scripts/upload-github-release-asset.sh +++ b/scripts/upload-github-release-asset.sh | |||
@@ -62,17 +62,17 @@ eval $(echo "$response" | grep -C2 "\"name\":.\+$(basename $filename)" | grep -m | |||
62 | if [ "$asset_id" = "" ]; then | 62 | if [ "$asset_id" = "" ]; then |
63 | echo "No need to overwrite asset" | 63 | echo "No need to overwrite asset" |
64 | else | 64 | else |
65 | if [ "$overwrite" ]; then | 65 | if [[ "$overwrite" == "true" ]] || [[ "$overwrite" == "delete" ]]; then |
66 | echo "Deleting asset($asset_id)... " | 66 | echo "Deleting asset($asset_id)... " |
67 | curl -X "DELETE" -H "Authorization: token $github_api_token" "https://api.github.com/repos/$owner/$repo/releases/assets/$asset_id" | 67 | curl -X "DELETE" -H "Authorization: token $github_api_token" "https://api.github.com/repos/$owner/$repo/releases/assets/$asset_id" |
68 | if [[ "$overwrite" == "delete" ]]; then | ||
69 | exit 0 | ||
70 | fi | ||
68 | else | 71 | else |
69 | echo "File already exists on tag $tag" | 72 | echo "File already exists on tag $tag" |
70 | echo "If you want to overwrite it, set overwrite=true" | 73 | echo "If you want to overwrite it, set overwrite=true" |
71 | exit 1 | 74 | exit 1 |
72 | fi | 75 | fi |
73 | if [ "$overwrite" == "delete" ]; then | ||
74 | exit 0 | ||
75 | fi | ||
76 | fi | 76 | fi |
77 | 77 | ||
78 | # Upload asset | 78 | # Upload asset |