婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 簡化shell終端命令輸入的腳本式快捷鍵工具

簡化shell終端命令輸入的腳本式快捷鍵工具

熱門標簽:曲阜400電話辦理 聯通電話機器人怎么接 奧維互動地圖標注參數 寧波智能外呼系統公司 電銷機器人 劍魚 申請公司400電話要注意什么 地圖標注輻射圖案 衛星地圖標注地名 安裝外呼系統費用

1.解決的問題

當你需要一次輸入很多個命令的時候,例如一次去多個目錄刪除文件

復制代碼 代碼如下:

cd dir1
rm file1.temp
cd ../../dir2
rm -rf dir3

當你懶得輸入一個好長的命令或者直接就記不住那么長的命令的時候,例如生成ctags
ctags --languages=C++ --exclude=third_party --exclude=.git --exclude=build --exclude=out -R -f .tags

當你想要個類似快捷鍵來一鍵搞定重復的事情又懶得寫好多腳本的時候,
duang~~ 這個工具就有用啦!

2.感性認識

這個工具是個shell腳本,附在本文末尾,復制整個腳本源碼,在本地保存為rew.sh,放到$PATH下,加上chmod +x權限。
文件名命名可以按喜好改。r e w 可以用一只左手輸入完畢,然后tab鍵就出.sh了,我感覺挺好的。

前面所說的復雜操作就變成了這么簡單:

一次去幾個目錄刪除文件,只需要rew.sh d
如果想指定起始目錄,還可以再帶參數rew.sh d dir_path

生成ctags,只需要rew.sh ct

如果忘了這個腳本有什么功能,只需要不帶參數運行crt.sh就會列出所有的命令。

3.理性認識

如果想加入自定義的命令,找到

復制代碼 代碼如下:

cmds=(xxxxx)

的地方,增加一行就可以了。每行就是一個參數和實際命令,可以看到:
復制代碼 代碼如下:

# defines commands here,format:
# shortcut|one space|action
cmds=(
  'w ninja -C out/Debug android_webview_apk'
  'gyp build/gyp_chromium'
  'd gdb -ex=r --args out/Debug/chrome --no-sandbox http://100.84.44.189'
  'ct ctags --languages=C++ --exclude=third_party --exclude=.git --exclude=build --exclude=out -R -f .tags'
  # 'e echo example to show this can be commentted'
  'r ninja -C out/Debug chrome_shell_apk'
  'u updateChrome'
  't testChromeShellMemory'
  'o openUrlInCAWShell'
)

也就是,第一個空格前是rew.sh的參數(快捷鍵),第一個空格后是實際運行的命令。其中多個步驟的命令可以做成函數,例如:

復制代碼 代碼如下:

updateChrome() {
  git pull
  cd third_party/WebKit
  git pull
  gclient sync --nohooks
}

如果怕忘記長命令用來干什么,也可以放到函數里,函數名要見名知意或者加注釋。

這個腳本可以被其它腳本調用,返回值和被代替的命令相同。

附工具腳本:

復制代碼 代碼如下:

#!/bin/bash
#author liuhx 2015/03/03 http://blog.csdn.net/hursing

# if including multiple steps, combine them into function
updateChrome() {
  git pull
  cd third_party/WebKit
  git pull
  gclient sync --nohooks
}

testChromeShellMemory() {
  ps=`adb shell ps | grep org.chromium.chrome.shell`
  rsss=`echo "$ps" | awk '{print $5;}'`
  echo "$rsss"
  pids=`echo "$ps" | awk '{print $2;}'`
  for p in $pids; do
    adb shell dumpsys meminfo $p | grep TOTAL | awk '{print $2;}'
  done
}

openUrlInCAWShell() {
  # $1 should be url
  adb shell am start -a android.intent.action.VIEW -n com.caw.webkit.test/.BrowserActivity -e policy UCM_CURRENT_WINDOW -d $1
}

# defines commands here,format:
# shortcut|one space|action
cmds=(
  'w ninja -C out/Debug android_webview_apk'
  'gyp build/gyp_chromium'
  'd gdb -ex=r --args out/Debug/chrome --no-sandbox http://100.84.44.189'
  'ct ctags --languages=C++ --exclude=third_party --exclude=.git --exclude=build --exclude=out -R -f .tags'
  # 'e echo example to show this can be commentted'
  'r ninja -C out/Debug chrome_shell_apk'
  'u updateChrome'
  't testChromeShellMemory'
  'o openUrlInCAWShell'
)

echoHelp() {
  for ((i = 0; i ${#cmds[@]}; i++)); do
    echo "${cmds[$i]}"
  done
  shName=`basename $0`
  echo -e "\033[0;33;1mexample: input '$shName ${cmds[0]%% *}' to run '${cmds[0]#* }'\033[0m"
}

if [[ $# -eq 0 ]]; then
  echoHelp
  exit 255
fi

for ((i = 0; i ${#cmds[@]}; i++)); do
  cmd=${cmds[$i]}
  shortcut=${cmd%% *}
  if [[ "$shortcut"x == "$1"x ]]; then
    action=${cmd#* }
    echo -e "\033[0;33;1m$action\033[0m"
    # skip shortcut
    shift 1
    eval $action $@
    exit $?
  fi
done

# if no cmd matched, echoHelp
echoHelp

您可能感興趣的文章:
  • linux shell命令的常用快捷鍵
  • Windows Powershell 快捷鍵介紹
  • Linux下Shell編程快捷鍵大全(日常整理)

標簽:上饒 大慶 安康 大興安嶺 遵義 仙桃 三門峽 江西

巨人網絡通訊聲明:本文標題《簡化shell終端命令輸入的腳本式快捷鍵工具》,本文關鍵詞  簡化,shell,終端,命令,輸入,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《簡化shell終端命令輸入的腳本式快捷鍵工具》相關的同類信息!
  • 本頁收集關于簡化shell終端命令輸入的腳本式快捷鍵工具的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 剑河县| 咸宁市| 阿合奇县| 曲沃县| 盐山县| 鹤山市| 勐海县| 嘉黎县| 定陶县| 巧家县| 乌拉特中旗| 许昌市| 卢龙县| 巴彦淖尔市| 北安市| 津南区| 罗城| 清丰县| 广河县| 西城区| 虹口区| 衡山县| 扎鲁特旗| 长乐市| 东明县| 溧水县| 乾安县| 楚雄市| 晋宁县| 明光市| 象山县| 福建省| 额尔古纳市| 搜索| 新泰市| 昌黎县| 平和县| 巩留县| 修武县| 新源县| 噶尔县|