aboutsummaryrefslogtreecommitdiffhomepage
path: root/alias
blob: 4c8ec5a4becd303ac354f9cc47cf80a648680137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#! /bin/sh

# settings
alias al="vim $SETTING_DIR/alias && source $SETTING_DIR/alias"
alias all="source $SETTING_DIR/alias"
alias zshrc="vim ~/.zshrc && source ~/.$(basename $SHELL)rc"
alias bashrc="vim ~/.bashrc && source ~/.$(basename $SHELL)rc"
alias vimrc='vim ~/.vimrc'
alias tigrc="vim $SETTING_DIR/tigrc"
alias muttrc='vim ~/.muttrc'
alias gitconfig='vim ~/.gitconfig'
alias log="cat $SETTING_DIR/log | grep '`date +'%b %d'`'"

# vim
alias v='vim'
alias vv='vim ~/vimwiki/index.md'
alias vr='vim -R'
alias cdv='cd ~/.vim_runtime' # amix/vimrc repo

# for custom scripts
vs() { 
  which $1 && vim $(which $1)
}
todo() {
  which $1 && grep -Po 'TODO.*' $(which $1)
}
fix() {
  which $1 && grep -Po 'FIXME.*' $(which $1)
}
alias g='gist'
alias gs='gist star'
alias gl='gist last'
alias gg='gist grep'
alias gt='gist tag'
alias gtt='gist tags'
alias gd='gist detail'

# shell
alias path="echo $PATH"
alias fd="ls -l /proc/$$/fd"
alias src="source $HOME/.$(basename $SHELL)rc"
alias ll='ls -alh'
alias hg='history | grep'
alias rmrf='rm -rf'
alias rr='_move_to_tmp'
_move_to_tmp() { 
  mv $@ /tmp 
}
prompt() {
  TMPFILE=$(mktemp)
  echo -e $1 > $TMPFILE \
  && vim $TMPFILE \
  && sed -i '$ q; s/$/ \\/' $TMPFILE \
  && eval $(cat $TMPFILE | tee /dev/tty)
  rm $TMPFILE
}

# package
alias ai='sudo apt install' # apt install
alias aptu='sudo apt update && sudo apt upgrade'
alias pac='sudo pacman -Sy' # pacman install
alias si='sudo snap install' # snap install
alias pi='sudo pip3 install' # python install
alias ni='sudo npm install -g' # nodejs install

# cd to DIRs
alias ..='cd ..'
alias ld='cd -' # last directory
cdg() { 
  cd ~/git/$1 || cd ~/git 
}
alias cda='cd ~/data'
alias cdd='cd ~/Downloads'
alias cdD='cd ~/Documents'
alias cdP='cd ~/Pictures'
alias cdV='cd ~/Videos'

# git
unalias gc &> /dev/null # override zsh plugin alias
gc() {
  git clone $1 && cd $(basename $1) 
}
gc1() {
  git clone --depth=1 $1 && cd $(basename $1) 
}
alias gls='git log -S'
alias cdgw='cd .github/workflows'
alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" "  -f2)' # cd to first submodule

# github
GITHUB_API='https://api.github.com'
GITHUB_API_TOKEN=$(cat $SETTING_DIR/tokens/github 2>/dev/null)
alias hub="GITHUB_TOKEN=$GITHUB_API_TOKEN hub"
alias github_token='xdg-open https://github.com/settings/tokens'
github() {
  xdg-open https://github.com/$1/$2
}
github_api() {
  curl --header "Authorization: token $GITHUB_API_TOKEN" $GITHUB_API/$1
}
gcg() {
  git clone git@github.com:$1/$2.git && cd $(basename $2) 
}
release() {
  command="github-release.sh\n  github_api_token=$GITHUB_API_TOKEN\n  repo=typebrook/mapstew\n  tag=daily-taiwan-pbf\n  type=asset\n  filename=taiwan-latest.osm.pbf\n  action=upload|overwrite|rename|delete\n  extra="
  prompt "$command"
}
asset() {
  curl -LO https://github.com/$1/$2/releases/download/$3/$4
}

# tig
alias cdt='cd ~/git/tig'
alias t='tig'
alias ts='tig status'
alias ta='tig --all'
alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2.5.0/tig'
upload_tig() {
  github-release.sh \
    github_api_token=$GITHUB_API_TOKEN \
    repo=typebrook/tig \
    tag=LATEST \
    filename=$(which tig)
    overwrite=false
}

# about custom settings
alias cds="cd $SETTING_DIR"
alias chs="cd $SETTING_DIR && tig status"
cdss() {
  cd $SETTING_DIR/tools/$1 || cd $SETTING_DIR/tools 
}

# about vimwiki
alias cdw='cd ~/vimwiki'
alias chw='cd ~/vimwiki && tig --all'
alias ww='cd ~/vimwiki && git add * && git commit -am "update" && git push'
wg() { 
  vim ~/vimwiki/$1.md 
}
wi() { 
  cat ~/vimwiki/$1.md 
}

# crontab
alias ce='crontab -e'

# ranger
alias r='_ranger_cd'
alias ranrc='vim ~/.config/ranger/rc.conf'
_ranger_cd() {
  tempfile="$(mktemp -t tmp.XXXXXX)"
  ranger --choosedir="$tempfile" "${@:-$(pwd)}"
  test -f "$tempfile" &&
  if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
    cd -- "$(cat "$tempfile")"
  fi
  rm -f -- "$tempfile"
}

# disk
alias df='df -h'

# docker
alias dp='docker ps'
alias di='docker images'
alias dc='docker-compose run --rm'
alias ds='docker stop'
alias drm='docker `docker ps -aq`'
alias dr='docker run --rm -it'
drb() {
  docker run --rm -it --entrypoint /bin/bash $@
}

# ssh
alias keygen='ssh-keygen -t rsa -C "typebrook@gmail.com"'
alias topo='ssh typebrook@topo.tw'
alias ptt='ssh bbsu@ptt.cc'
alias geothings-test='ssh geothings@test.geothings.tw'

# Android
alias debug='./gradlew app:installDebug && adb shell am start -n com.geothings.geobingan/.MainActivity_'
alias adb_default='adb shell dumpsys package domain-preferred-apps'
alias adb_list='adb shell dumpsys package d'
alias rmcache='rm -rf ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/*'
alias adb_last_screenshot='adb pull /sdcard/Screenshots/`adb shell ls -t /sdcard/Screenshots/ | head -1` ~/Desktop'
adb_push() { 
  adb push $1 /sdcard/Download 
}

# curl
alias co='curl -O'
alias curl.code='curl -o /dev/null --silent -Iw "%{http_code}"'

# python
alias pip3='python3 -m pip'

# gdal
alias oo='ogr2ogr'
alias oi='ogrinfo'
alias oias='ogrinfo -al -so'

# sample file
alias sample_gpx='curl -O https://docs.mapbox.com/help/data/run.gpx'
alias sample_geojson='curl -O https://docs.mapbox.com/help/data/stations.geojson'
alias sample_geotiff='curl -O https://docs.mapbox.com/help/data/landsat.tif'
alias sample_csv='curl -O https://docs.mapbox.com/help/data/airports.csv'
alias sample_svg='curl -O https://docs.mapbox.com/help/data/bicycle-24.svg'
alias sample_mbtiles='curl -O https://docs.mapbox.com/help/data/trails.mbtiles'
alias sample_kml='curl -O https://docs.mapbox.com/help/data/farmers_markets.kml'
alias sample_osm='curl https://api.openstreetmap.org/api/0.6/node/3428095932'

# data file
alias taiwan='curl -O http://download.geofabrik.de/asia/taiwan-latest.osm.pbf'
alias data_rudymap='curl -O https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/MOI_OSM.xml'
alias data_rudymap_ele='curl -O http://moi.kcwu.csie.org/osm_elevations/ele_taiwan_10_50_100_500_marker-2019.7.o5m'
data_osm_diff_min() {
  curl https://planet.openstreetmap.org/replication/minute/state.txt \
  | sed -n 2p | cut -d'=' -f2 | sed -r 's#(.{1})(.{3})#00\1/\2#' \
  | xargs -I{} echo 'https://planet.openstreetmap.org/replication/minute/{}'.osc.gz \
  | xargs curl -O
}
data_osm_diff_hour() {
  curl https://planet.openstreetmap.org/replication/hour/state.txt \
  | sed -n 2p | cut -d'=' -f2 | sed -r 's#(.{2})(.{3})#000/0\1/\2#' \
  | xargs -I{} echo 'https://planet.openstreetmap.org/replication/hour/{}'.osc.gz \
  | xargs curl -O
}
alias data_taiwan_town='curl -o town.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=CD02C824-45C5-48C8-B631-98B205A2E35A'
alias data_taiwan_village='curl -o village.zip -L http://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx\?DATA\=B8AF344F-B5C6-4642-AF46-1832054399CE'
alias data_taiwan_poly='curl -O http://download.geofabrik.de/asia/taiwan.poly'
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 -'

# clipboard
alias xi='xsel -ib'
alias xo='xsel -ob'
alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && echo Copied to clipboard && xsel -ob'
alias xll='xo >> ~/vimwiki/working.md'
alias xc='xsel -ob | gcc -xc -'

# image
image_vertical() { 
  convert "$@" -append output.png 
}
image_horizontal() { 
  convert "$@" +append output.png 
}

# mail mutt
alias m='mutt'

# misc
alias foo='echo bar > foo && echo File foo is created && ls -lh foo'
alias bar='echo foo > bar && echo File bar is created && ls -lh bar'
token() {
  cd $SETTING_DIR/tokens && [[ -e $1 ]] && cat $1 || ls -l
}
alias gr='_grepString'
_grepString() { 
  grep -R $1 .  
}
alias wcl='wc -l'
alias findn='find . -iname'
alias x='xdg-open'
alias f='free -h'
alias yl='youtube-dl'
alias yla='youtube-dl -x --audio-format mp3'
alias editor='select-editor'
alias hp='http-prompt'
alias clocg='cloc --vcs=git'
alias tma='tmux a'
alias mm='mkvmerge -o out.webm -w 01.webm + 02.webm'
alias du='ncdu'
alias we='weechat'
mvt_decode() {
  python3 $SETTING_DIR/tools/mvt_decode.py $1 | tr \' \" | sed 's/True/true/g' | jq .
}
big52utf8() { 
  iconv -f BIG-5 -t UTF-8 
}

# tmp
alias and='cd ~/git/geoBingAn.Android'
alias cdo='cd ~/git/openmaptiles'
alias cdS='cd ~/git/StreetComplete'
alias cdW='cd ~/git/geoBingAnWeb'
alias cdT='cd ~/git/taiwan-topo'
alias cdand='cd ~/git/sample'
alias cdm='cd ~/git/mapstew'
alias cdL='cd ~/Insync/pham@geothings.tw/Google\ Drive\ -\ Shared\ drives/LEOTEK'
alias stew='cd ~/git/mapstew'

TAIWAN_BBOX='118.1036,20.72799,122.9312,26.60305'
TAIWAN_BBOX_V='20.72799,118.1036,26.60305,122.9312'
TAIPEI_BBOX='121.346,24.926,121.676,25.209'
TAIPEI_BBOX_V='24.926,121.346,25.209,121.676'