aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--alias34
-rwxr-xr-xscripts/gist24
-rwxr-xr-xscripts/upload-github-release-asset.sh8
3 files changed, 38 insertions, 28 deletions
diff --git a/alias b/alias
index a930287..6b5042a 100644
--- a/alias
+++ b/alias
@@ -24,19 +24,24 @@ vs() {
24# shell 24# shell
25alias src="source $HOME/.$(basename $SHELL)rc" 25alias src="source $HOME/.$(basename $SHELL)rc"
26alias ll='ls -alh' 26alias ll='ls -alh'
27alias si='sudo snap install' # snap install 27alias hg='history | grep'
28alias ni='sudo npm install -g' # nodejs install
29alias ss='sudo !!'
30alias hg='history|grep'
31alias rmrf='rm -rf' 28alias rmrf='rm -rf'
32alias rr='move_to_tmp' 29alias rr='move_to_tmp'
33move_to_tmp() { 30move_to_tmp() {
34 mv $@ /tmp 31 mv $@ /tmp
35} 32}
33prompt() {
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
38alias ai='sudo apt install' # apt install 41alias ai='sudo apt install' # apt install
39alias aptu='sudo apt update && sudo apt upgrade' 42alias aptu='sudo apt update && sudo apt upgrade'
43alias si='sudo snap install' # snap install
44alias ni='sudo npm install -g' # nodejs install
40 45
41# cd to DIRs 46# cd to DIRs
42alias ..='cd ..' 47alias ..='cd ..'
@@ -71,9 +76,9 @@ wi() {
71alias ce='crontab -e' 76alias ce='crontab -e'
72 77
73# ranger 78# ranger
74alias r='_ranger-cd' 79alias r='_ranger_cd'
75alias ranrc='vim ~/.config/ranger/rc.conf' 80alias 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}
100alias gls='git log -S' 105alias gls='git log -S'
101alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule 106alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule
107github_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
104alias dp='docker ps' 113alias dp='docker ps'
@@ -122,7 +131,7 @@ alias t='tig'
122alias ts='tig status' 131alias ts='tig status'
123alias ta='tig --all' 132alias ta='tig --all'
124alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2.5.0/tig' 133alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2.5.0/tig'
125upload-tig() { 134upload_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'
138alias adb-list='adb shell dumpsys package d' 147alias adb-list='adb shell dumpsys package d'
139alias rmcache='rm -rf ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/*' 148alias rmcache='rm -rf ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/*'
140alias adb-last-screenshot='adb pull /sdcard/Screenshots/`adb shell ls -t /sdcard/Screenshots/ | head -1` ~/Desktop' 149alias adb-last-screenshot='adb pull /sdcard/Screenshots/`adb shell ls -t /sdcard/Screenshots/ | head -1` ~/Desktop'
141adb-push() { 150adb_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
191alias data-taiwan-town='curl -o town.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=CD02C824-45C5-48C8-B631-98B205A2E35A' 200alias data-taiwan-town='curl -o town.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=CD02C824-45C5-48C8-B631-98B205A2E35A'
192alias data-taiwan-village='curl -o village.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE' 201alias data-taiwan-village='curl -o village.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE'
193alias data-taiwan-poly='curl -O http://download.geofabrik.de/asia/taiwan.poly' 202alias data-taiwan-poly='curl -O http://download.geofabrik.de/asia/taiwan.poly'
194data-taiwan-county-code() { 203alias 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
200alias xi='xsel -ib' 206alias xi='xsel -ib'
@@ -244,13 +250,9 @@ alias cdo='cd ~/git/openmaptiles'
244alias cdS='cd ~/git/StreetComplete' 250alias cdS='cd ~/git/StreetComplete'
245alias cdW='cd ~/git/geoBingAnWeb' 251alias cdW='cd ~/git/geoBingAnWeb'
246alias and='cd ~/git/geoBingAn.Android' 252alias and='cd ~/git/geoBingAn.Android'
247alias cdG='cd ~/git/git'
248alias cdT='cd ~/git/taiwan-topo' 253alias cdT='cd ~/git/taiwan-topo'
249alias cdand='cd ~/git/sample' 254alias cdand='cd ~/git/sample'
250alias cdm='cd ~/git/sharkbig.github.io/rescue' 255alias cdm='cd ~/git/sharkbig.github.io/rescue'
251alias cdmw='cd ~/git/sharkbig.github.io/.github/workflows' 256alias cdmw='cd ~/git/sharkbig.github.io/.github/workflows'
252 257
253repo='git@github.com'
254hub='https://github.com'
255typebrook='git@github.com:typebrook'
256GITHUB_API='https://api.github.com' 258GITHUB_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"
49mkdir -p $folder 49mkdir -p $folder
50index=$folder/index 50index=$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
62if [ "$asset_id" = "" ]; then 62if [ "$asset_id" = "" ]; then
63 echo "No need to overwrite asset" 63 echo "No need to overwrite asset"
64else 64else
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
76fi 76fi
77 77
78# Upload asset 78# Upload asset