1. 程式人生 > >簡化常用命令(修改 .bash_profile 檔案)

簡化常用命令(修改 .bash_profile 檔案)

在 ~/.bash_profile 檔案中增加以下內容


# adb cmd
alias a='adb shell'
alias akill='adb kill-server'
alias astart='adb start-server'
alias apush='adb push '
alias apull='adb pull '
alias areboot='adb reboot'
alias atop='adb shell dumpsys activity top'
alias arecovery='adb reboot recovery'
alias abootloader='adb reboot bootloader'
alias alog='adb logcat'

# other cmd
alias rmdir='rm -r'
alias sourceb="source ~/.bash_profile"
alias antbuild='ant clean build'
alias obash='o ~/.bash_profile'
alias nstart='npm start'
# alias ninstall='npm install'
# alias npmtb='npm config set registry http://registry.npm.taobao.org/'
# alias npmofficial='npm config set registry https://registry.npmjs.org/'
alias javaloc='/usr/libexec/java_home -V'
alias pspy='ps -eaf|grep python'
alias kill9='kill -9 '
alias lastweek="git log --pretty=format:\"%an: %s\" --since=1.weeks "
alias clone="git clone "
alias st="git status "

# 獲取 ip 地址並拷貝到貼上板(針對 mac os)
ipcp(){
  ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"| pbcopy
}

# 執行指令碼並在指令碼執行完成後給予提示(針對 mac os)
ish(){
  sh $*
  say "指令碼執行完成"
  osascript -e 'display notification "指令碼執行完成" with title "ish"'
}

# 獲取 ip 地址
ip(){
  ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"
}

# 通過 wifi 的形式連線 android 裝置
acon(){
  line="------------------------------------------\r\n"
  echo "now we fetch the ip of android device"
  aip=`adb shell ifconfig |grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
  echo "ip is ${aip}"

  echo ${line}
  echo "now we connect"
  adb connect ${aip}

  echo ${line}

  adb devices -l
}

adis(){
  adb disconnect
}

# 安裝 apk ,並在結束時給予聲音和通知欄提示(針對 mac os)
apk(){
  adb install $*
  # 以下兩行鍼對 mac os
  say 安裝完成
  osascript -e 'display notification "安裝完成" with title "apk"'
}

# 使用 SublimeText 開啟內容
o(){
  Open -a /Applications/SublimeText.app $1
}

# 檢視 apk 包資訊
apkdump(){
  aapt dump badging  $1
}

# 檢視已連線裝置
list(){
  adb devices -l
}

arecord() {
  if [ $# -eq 0 ]
  then
    name="record"
  else
    name="record$1"
  fi  
  adb shell screenrecord /sdcard/demo${name}.mp4
  say "錄製完成"
}

# 對當前裝置截圖儲存到命令執行所在目錄且將其開啟
asp() {
  target_dir=`pwd`

  if [ $# -eq 0 ]
  then
    name="screenshot.png"
  else
    name="$1.png"
    if [ $# -eq 2 ]
    then
        target_dir=$2
    fi
  fi
  adb shell screencap -p /sdcard/${name}
  adb pull /sdcard/${name} ${target_dir}/${name}
  adb shell rm /sdcard/${name}
  echo "save to $target_dir/${name}"
  # for mac os
  open $name
}