# cd to path in child or in parent cds(){ STH_CDS_FILES_FIND=0; STH_CDS_FLINES=(`ls $PWD`) for i ($STH_CDS_FLINES){ [[ $i == *$1* ]] && STH_CDS_FILES_FIND=1 && cd $i && break } if [[ $STH_CDS_FILES_FIND == 0 ]] { STH_CDS_FILES_FIND=0; STH_CDS_FLINES=(`ls $(dirname $PWD)`) for i ($STH_CDS_FLINES){ [[ $i == *$1* ]] && cd "$(dirname $PWD)/$i" && break } } }; # my custom directorys mcd(){ STH_FLINES=(${(f)"$(<~/.mcd_path)"}) echo -e "\n===> how to use? \n .1 to use dir 1 \n s. to open dir\n" for i ($STH_FLINES){ echo $i sth_num=$i[(ws.:.)1] sth_path=$i[(ws.:.)2] [[ $sth_num[1] != "#" ]] && alias ".$sth_num"="cd $sth_path" } echo -e "\n" };
#Sth's MACOS zsh config #Author: stanhe #echo "$(date +"%Y-%m-%d %T %N") Init .bashrc start! " alias function='func(){ #================= alias function start ===================== gitcreatePreStatus(){ sPath=$PWD/.git/hooks if [[ -e "$sPath" && ! -e "$sPath/pre-status.sh" ]] then echo -e "#!/bin/bash\necho 'pre-status'" > $sPath/pre-status.sh; chmod +x $sPath/pre-status.sh; echo "Create pre-status in .git/hooks"; fi }; # add git command pre-status git(){ gPath=$PWD/.git/hooks/pre-status.sh if [[ $# -ge 1 && "$1" == "pre" && -e "$gPath" ]] then command $gPath "$@"; else command git "$@"; fi }; my_test(){ echo "my test"; }; test1(){ echo "test1"; }; # switch branch for current and submodules. checkoutSub(){ echo "switch $1 ..."; gck $1 && gsf gck $1; echo "===end==="; }; # checkout new branch for current and submodules. checkoutNewSub(){ echo "Create $1 ..."; gck -b $1 && gsf gck -b $1; echo "===end==="; }; # delete current and submodules branch. deleteBranch(){ echo "Delete $1 ..."; gb -d $1 && gsf gb -d $1; echo "===end==="; }; # checkout current and submodules to master checkoutMaster(){ echo "Checkout all modules to master..."; gckm && gsf gckm; echo "===end==="; };
# cd to path in child or in parent cds(){ STH_CDS_FILES_FIND=0; STH_CDS_FLINES=(`ls $PWD`) for i ($STH_CDS_FLINES){ [[ $i == *$1* ]] && STH_CDS_FILES_FIND=1 && cd $i && break } if [[ $STH_CDS_FILES_FIND == 0 ]] { STH_CDS_FILES_FIND=0; STH_CDS_FLINES=(`ls $(dirname $PWD)`) for i ($STH_CDS_FLINES){ [[ $i == *$1* ]] && cd "$(dirname $PWD)/$i" && break } } }; # my custom directorys mcd(){ STH_FLINES=(${(f)"$(<~/.mcd_path)"}) echo -e "\n===> how to use? \n .1 to use dir 1 \n s. to open dir\n" for i ($STH_FLINES){ echo $i sth_num=$i[(ws.:.)1] sth_path=$i[(ws.:.)2] [[ $sth_num[1] != "#" ]] && alias ".$sth_num"="cd $sth_path" } echo -e "\n" }; # gck -n gckn(){ if [[ -z $1 ]] { echo " ===> please input branch number !" } else { TARGET_BRANCH=$1p git checkout $(git branch | sed -n $TARGET_BRANCH) } }; # git check status by number gdn(){ if [[ -z $1 ]] { STH_GIT_DIFF=$(git status|grep '"'"'modified: '"'"'|awk -F: '"'"'{print $2" ===> "FNR}'"'"') echo "$STH_GIT_DIFF" } else { STH_GIT_TARGET=$1p git diff $(echo "$STH_GIT_DIFF"|sed -n $STH_GIT_TARGET|awk -F"===>" '"'"'{print $1}'"'"') } }; # use the devices with number adbd(){ if [[ -z $1 ]] { STH_ADB_DEVICE=$(adb devices -l |grep device|awk -F: '"'"'{if(NR>1){print $4" ===> "FNR-1}}'"'"') [[ -n $ANDROID_SERIAL ]] && echo "Used: ===> $ANDROID_SERIAL" echo "$STH_ADB_DEVICE" } else { STH_ADB_TARGET=`expr $1 + 1`p export ANDROID_SERIAL=$(adb devices|awk -F "[[:space:]]" '"'"'{print $1}'"'"'|sed -n $STH_ADB_TARGET) STH_ADB_DEVICE_MODEL=$(adb devices -l |awk -F '"'"'[[:space:]]+'"'"' '"'"'{print $5}'"'"'|sed -n $STH_ADB_TARGET|awk -F: '"'"'{print $2}'"'"') echo "Use device: $STH_ADB_DEVICE_MODEL serial: $ANDROID_SERIAL" } }; # adb shell kill pid with package name adbk(){ if [[ -z $1 ]] { echo "please input package name!" } else { STH_ADB_KILL_PID=$(adb shell ps|grep $1|awk '"'"'{print $2}'"'"') $(adb shell kill $STH_ADB_KILL_PID) } }; # check network connection sth_netstat(){ STH_NET_BACK_CODE=$(curl -I -s --connect-timeout 3 www.baidu.com|head -n 1|awk -F "[[:space:]]" '"'"'{print $2}'"'"') if [[ "$STH_NET_BACK_CODE" == 200 ]] { echo "Can access network..." } else { echo "Access network Error!" } }; # ssh my pi sshpi(){ if [[ -z $1 ]] { echo " ===> please input the port number !" } else { ssh -p $1 pi@1.tcp.cpolar.cn } }; # open a file with file browser s.(){ if [[ -z $1 ]] { open ./ } else { open $1 } }; # create qrcode qr(){ if [[ -z $1 ]] { echo " ===> please input the qrcode string !" } else { echo $1 |curl -F-=\<- qrenco.de } }; #================= alias function end ===================== };func'
#================= custom alias ===================== #alias sth_alias_gdn_cmd1='git status|grep '"'"'modified: '"'"'|awk -F: '"'"'{print $2" ====> "FNR}'"'" simple for use ' in cmds alias q='exit' alias test='my_test' alias t1='test1' alias la='ls -lsah' alias gaa='git add . && gst' alias gii='git init' alias gst='git status' alias gsh='git stash' alias gd='git diff' alias gb='git branch' alias gbs='gb && gsf gb' alias gdc='git diff --cached' alias gp='git push' alias gpre='git pre' alias gf='git pull' alias gcmsg='git commit -m' alias gcps='gitCreatePreStatus' alias gl='git lg' alias gck='git checkout' alias gckm='git checkout master' alias gcks='checkoutSub' alias gckbs='checkoutNewSub' alias gbds='deleteBranch' alias gcksm='checkoutMaster' #alias gcksm='gckm && gsf gckm' alias gsf='git submodule foreach ' alias gsu='git submodule update ' #gsb 所有gsb开头的指令都是git submodule相关指令 alias gsb='cat ~/.zshrc.pre-oh-my-zsh|grep '"'"'^#gsb'"'"' ' #gsb-dev: 切换kt-smart和相关module到dev分支,并update alias gsb-dev='gck dev && gsf gck dev && gsu' #gsb-master: 切换kt-smart和相关module到master分支,并update alias gsb-master='gck master && gsf gck master && gsu' #gsb-check: 检查当前所有模块所在分支 alias gsb-check='gsf gb' #gsb-checkout-dev: 检查当前所有模块的dev分支,自动从远端创建关联的本地dev分支 alias gsb-checkout-dev='gck -b dev origin/dev && gsf -b dev origin/dev' #gsb-pull: 对所有module执行pull指令,拉去并合并最新代码 alias gsb-pull='gf && gsf gf' #gsb-status: 对所有module执行status指令 alias gsb-status='gst && gsf gst' alias gci='git commit' alias grh='git reset --hard ' alias gr='git restore ' alias grs='git restore --staged ' alias ggrep='git grep -n ' alias adbi='adb shell input text' # action input alias adbh='adb shell input keyevent 3' # action home alias adbb='adb shell input keyevent 4' # action back alias adbn='adb shell input keyevent 61' # action next alias adbe='adb shell input keyevent 66' # action enter alias adbdd='adb shell input keyevent 67' # action delete alias adbwd='adb shell svc wifi disable' # disable wifi alias adbwe='adb shell svc wifi enable' # enable wifi alias adbfd='adb shell settings put global airplane_mode_on 0' # close airplane mode alias adbfe='adb shell settings put global airplane_mode_on 1' # open airplane mode alias adbne='adbwe && adbfd' # enable net alias adbnd='adbwd && adbfe' # disable net alias adbr='adb reboot' # reboot machine alias adbl='adb shell ls' # ls alias adbg='adb shell ps | grep ' alias adbbc='adb shell am broadcast -a ' # eg: adb shell am broadcast -a com.android.test --es test_string “this is test string” --ei test_int 100 --ez test_boolean true alias adbsa='adb shell am start -n ' # start activity pkg/.activity alias alg='adb logcat | grep --color=auto ' #adb logcat grep file alias adbsh='scrcpy -b8M -m1920 --window-x 800 --window-y 100 --window-width 800 --window-height 450 &' alias adbsv='scrcpy -b8M -m1400 --window-x 800 --window-y 100 --window-width 450 --window-height 800 &'
# tmux session alias txsn='tmux new -s ' alias txsd='tmux detach' alias txsl='tmux ls' alias txsa='tmux attach -t ' alias txsk='tmux kill-session -t ' alias txss='tmux switch -t ' # tmux window alias txwi='tmux split-window' alias txws='tmux split-window -h' alias txpu='tmux select-pane -U' alias txpd='tmux select-pane -D' alias txpl='tmux select-pane -L' alias txpr='tmux select-pane -R' alias txps='tmux swap-pane -d '
# system #alias s.='open ./' alias t.='open ./ -a Terminal.app'