Scripting Shortcuts: A tool for simplifying shell Terminal command input

Source: Internet
Author: User

1. Issues to solve

When you need to enter a number of commands at once , such as deleting files in multiple directories at once
CD Dir1
RM file1.temp
Cd.. /.. /dir2
RM-RF Dir3

When you are too lazy to enter a good long command or simply can't remember that long command , such as generating ctags
Ctags--languages=c++--exclude=third_party--exclude=.git--exclude=build--exclude=out-r-F. tags

When you want a shortcut key to do something repetitive and lazy to write a lot of scripts,
Duang~~ This tool is useful!

2. Perceptual knowledge

This tool is a shell script, attached to the end of this article, copy the entire script source code, saved locally as rew.sh, placed under $path, plus chmod +x permissions.
The name of the file can be changed as you prefer. The r e W can be entered with one left hand, then the TAB key is out. SH, I feel pretty good.

The complex operations described earlier have become so simple:

Go to a few 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 required.

If you forget what this script does, you only need to run crt.sh without parameters to list all the commands .


3. Rational understanding if you want toAdd a custom commandFound it
Cmds= (XXXXX)
Place, add a row to it. Each line is a parameter and the actual command, you can see:
# defines commands here,format:# shortcut|one space|actioncmds= (  ' 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 Sho W This can be commentted '  r ninja-c out/debug chrome_shell_apk '  u updatechrome '  T testchromeshellmemory '  ' O Openurlincawshell ')
That is, the first space before the rew.sh parameter (accelerator), the first space after the actual run of the command. Commands for multiple steps can be made into functions, such as
Updatechrome () {  git pull  cd third_party/webkit  git pull  gclient sync--nohooks}

If you are afraid of forgetting what the long command is for, you can put it in a function, the name of the function should be known or annotated.

This script can be called by other scripts, and the return value is the same as the command being substituted.


Tool Script:

#!/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 she ll PS | grep Org.chromium.chrome.shell ' rsss= ' echo "$ps" | awk ' {print $;} ' ' Echo ' $rsss ' pids= ' echo ' $ps ' | awk ' {print $;} ' ' for p in $pids; Do adb shell Dumpsys meminfo $p | grep Total |  awk ' {print $;} ' Done}openurlincawshell () {# should be URL adb shell am start-a android.intent.action.view-n com.caw.webkit.test/.b ROWSERACTIVITY-E policy ucm_current_window-d $1}# defines commands here,format:# shortcut|one space|actioncmds= (' W nin Ja-c out/debug android_webview_apk ' Gyp build/gyp_chromium ' d gdb-ex=r--args out/debug/chrome--no-sandbox http://1  00.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 is 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 $ ' echo-e "\033[0;33;1mexample:input ' $shName ${cmds[0]%% *} ' to run ' ${cmds[0]#*} ' \033[0m '}if [[$#-eq 0]; Then Echohelp exit 255fifor ((i = 0; i < ${#cmds [@]}; i++)); Do cmd=${cmds[$i]} shortcut=${cmd%% *} if [["$shortcut" x = = "" x]]; Then action=${cmd#*} echo-e "\033[0;33;1m$action\033[0m" # Skip shortcut Shift 1 eval $action [email&nbsp  ;p rotected] Exit $? fidone# if no cmd matched, echohelpechohelp

Reprint Please specify the Source:Http://blog.csdn.net/hursing

Scripting Shortcuts: A tool for simplifying shell Terminal command input

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.