In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to simplify shell terminal command input script shortcut key tool", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to simplify shell terminal command input script shortcut key tool"!
1. Problem solved
When you need to enter many commands at a time, such as going to multiple directories at a time to delete files
The code is as follows:
Cd dir1
Rm file1.temp
Cd.. /.. / dir2
Rm-rf dir3
When you are too lazy to type a long command or simply can't remember it, such as generating a ctags
Ctags-- languages=C++-- exclude=third_party-- exclude=.git-- exclude=build-- exclude=out-R-F. tags
When you want a keyboard shortcut to do repetitive things with one click and don't bother to write a lot of scripts.
Duang~~ this tool is useful!
two。 Perceptual knowledge
This tool is a shell script, attached at the end of this article, copy the entire script source code, save it locally as rew.sh, put it under $PATH, and add chmod + x permissions.
The name of the file can be changed as you like. R e w can be typed with one left hand, and then the tab key will be .sh. I feel fine.
The complex operation mentioned earlier becomes so simple:
Go to several directories at a time to delete files, only need rew.sh d
If you want to specify the starting directory, you can also take the parameter rew.sh d dir_path
To generate ctags, only rew.sh ct is needed.
If you forget what this script does, just run crt.sh with no arguments and all the commands are listed.
3. Rational cognition
If you want to add custom commands, find the
The code is as follows:
Cmds= (xxxxx)
Just add one line to it. Each line is a parameter and an actual command, as you can see:
The code is as follows:
# 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'
)
That is, the first space is preceded by the parameter of rew.sh (shortcut key), and after the first space is the actual running command. Commands with multiple steps can be made into functions, such as:
The code is as follows:
UpdateChrome () {
Git pull
Cd third_party/WebKit
Git pull
Gclient sync-nohooks
}
If you are afraid of forgetting what the long command is used for, you can also put it in the function, and the function name should be noted or annotated.
This script can be called by other scripts, and the return value is the same as the command being replaced.
Tool script attached:
The code is as follows:
#! / 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-an 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 [@]}; iTunes +)); do
Echo "${cmds [$I]}"
Done
ShName= `basename $0`
Echo-e "\ 033 [0transport1mexample: input'$shName ${cmds [0]% *}'to run'${cmds [0] # *}'\ 033 [0m"
}
If [[$#-eq 0]]; then
EchoHelp
Exit 255
Fi
For ((I = 0; I < ${# cmds [@]}; iTunes +)); do
Cmd=$ {cmds [$I]}
Shortcut=$ {cmd%% *}
If [["$shortcut" x = = "$1" x]]; then
Action=$ {cmd#*}
Echo-e "\ 033 [033 / 033 [033 / 033]
# skip shortcut
Shift 1
Eval $action $@
Exit $?
Fi
Done
# if no cmd matched, echoHelp
EchoHelp
Thank you for your reading, the above is the content of "how to simplify the script shortcut key tool for shell terminal command input". After the study of this article, I believe you have a deeper understanding of how to simplify the script shortcut key tool for shell terminal command input, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.