# My alias for bash and zsh # 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 ~/.config/mutt/muttrc' alias gitconfig='vim ~/.gitconfig' alias log="cat $SETTING_DIR/log | grep '`date +'%b %d'`'" # vim alias v='vim' alias sv='sudo vim' alias vl="vim -c ':CtrlPMRU'" alias vr='vim -R' alias vu='vim -u NONE' alias vv='vim ~/vimwiki/index.md' 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 gl='gist last' unalias gg &>/dev/null alias gg='gist grep' # unix alias chmodx='sudo chmod +x' alias s='sudo systemctl' alias j='sudo journalctl -xe' alias path="echo $PATH" alias fd="echo /proc/$$/fd; ls -l /proc/$$/fd" alias src="source $HOME/.$(basename $SHELL)rc" alias ll='ls -alh' llw() { which $1 | xargs ls -alh; } alias hg='history | grep' alias rmrf='rm -rf' alias rr='_move_to_tmp' alias sound="echo -ne '\a'" cdp() { [[ ! -d $1 ]] && mkdir -p $1 cd $1 } _move_to_tmp() { mv $@ /tmp } prompt() { TMPFILE=$(mktemp) echo -e "$@" >$TMPFILE \ && vim $TMPFILE \ && sed -i '$ q; s/$/ \\/' $TMPFILE \ && eval $( <$TMPFILE tee /dev/tty ) rm $TMPFILE } # package alias ai='sudo apt install' # apt install alias aptu='sudo apt update && sudo apt upgrade' alias si='sudo snap install' # snap install alias pi='sudo pip3 install' # python install alias ni='sudo npm install -g' # nodejs install # pacman alias pac='sudo pacman -S' # pacman install alias psy='sudo pacman -Syy' alias ys='yay -S' alias pqs='pacman -Qs' alias pqi='pacman -Qi' alias ysi='yay -Si' alias pss='pacman -Ss' alias yss='yay -Ss' alias pqi='pacman -Qi' alias yql='yay -Ql' alias pf='pacman -F' alias yf='yay -F' alias pfl='pacman -Fl' alias yfl='yay -Ql' alias pqe='pacman -Qqe' alias pR='sudo pacman -R' psi() { pqe | grep $1 >/dev/null && echo -e "$(tput setaf 13)[Installed]$(tput sgr0)" pacman -Si $1 } # cd to DIRs alias ..='cd ..' alias ld='cd -' # last directory cdg() { cd ~/git/$1 || cd ~/git } alias cda='mkdir -p ~/data && cd ~/data' alias cdc='cd ~/.config' alias cdd='cd ~/Downloads' alias cdD='cd ~/Documents' alias cdP='cd ~/Pictures' alias cdV='cd ~/Videos' alias cdb='cd ~/git/bashblog' # 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 cdgg='cd $(git rev-parse --show-toplevel)' alias cdgw='cdgg && cd .github/workflows' alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule # github export GITHUB_API='https://api.github.com' export 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/$@ } gcg() { local user=$1; local repo=$2; shift; shift git clone git@github.com:$user/$repo.git $@ && cd $(basename $repo) } 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 } raw() { curl -O https://raw.githubusercontent.com/$1/$2/$3 } # 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 \ type=asset \ filename=$(which tig) action=overwrite } # 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' wg() { vim ~/vimwiki/$1.md } wi() { cat ~/vimwiki/$1.md } # crontab alias ce='crontab -e' # lf alias r='_lf_cd' _lf_cd() { tempfile=$(mktemp -t tmp.XXXXXX) lf --last-dir-path $tempfile test -f "$tempfile" && \ cd -- "$(cat "$tempfile")" && \ 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 rm `docker ps -aq`' alias dr='docker run --rm -it' drb() { docker run --rm -it --entrypoint /bin/bash $@ } # ssh alias cdssh='cd ~/.ssh' alias ptt='ssh bbsu@ptt.cc' alias topo='ssh topo.tw' 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.view='adb shell am start -a android.intent.action.VIEW -d' 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='DIR=/sdcard/Pictures/Screenshots/; adb pull $DIR/`adb shell ls -t $DIR | head -1` ~/Desktop' alias adb_last_camera='DIR=/sdcard/DCIM/Camera; adb pull $DIR/`adb shell ls -t $DIR | 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' alias sample_image='curl https://file-examples-com.github.io/uploads/2017/10/file_example_JPG_100kB.jpg' taiwan_dem() { <<<"http://dtm.moi.gov.tw/不分幅_全台及澎湖.zip" perl -lpe 's/([^A-Za-z0-9.\/:])/sprintf("%%%02X", ord($1))/seg' |\ xargs curl -Lo taiwan_dem.zip unzip -p taiwan_dem.zip dem_20m.tif >20m.tif } # 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() { suffix=${1##*.} convert "$@" -append $(basename -s .$suffix $1)-$(basename -s .$suffix ${@: -1}).${format:-$suffix} } image_horizontal() { convert "$@" +append output.png } # thunderbird alias thunder.push='rsync -a --delete ~/.thunderbird/ pham@topo.tw:~/.thunderbird' # 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 } unalias gr &>/dev/null gr() { grep -R $1 . } alias wcl='wc -l' alias findn='find . -iname' alias x='xdg-open' 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 we='weechat' alias p8='ping 8.8.8.8' alias pg='ping google.com' date-reset() { sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" } mvt_decode() { mvt_decode.py $1 | tr \' \" | sed 's/True/true/g' | jq . } big52utf8() { iconv -f BIG-5 -t UTF-8 } utf82big5() { iconv -t BIG-5 -f UTF-8 } urlencode() { perl -lpe 's/([^A-Za-z0-9.\/:])/sprintf("%%%02X", ord($1))/seg' # Alternative: # curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" } bak() { cp $1 $1.bak } wrap2geojson() { jq -s '{ type: "FeatureCollection", features: . }' } # task alias tk='task' alias taskrc='vim ~/.taskrc' alias cdtk='cd ~/.task' alias cdk='cd ~/.task' alias li='tasksh' tt() { taskwarrior-tui ( cd ~/.task && git add --all && git commit -m 'update' && git push origin & ) &>/dev/null } # upload with 0x0.st up() { curl -F"file=@${1}" http://0x0.st } short() { curl -F"shorten=${1}" http://0x0.st } # pass alias cdpass='cd ~/.password-store' alias p='pass' alias pc='pass -c' alias pgc='pass generate -c' # tmp alias and='cd ~/git/geoBingAn.Android' alias cdS='cd ~/git/StreetComplete' alias cdT='cd ~/git/taiwan-topo' alias cdand='cd ~/git/sample' alias cdm='cd ~/git/mapstew' alias cdma='cd ~/git/mapstew-android' alias cdT='cd ~/git/tilemaker' alias cdngx='cd /etc/nginx' 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'