Script Shortcuts tool to simplify shell terminal command input _linux shell

Source: Internet
Author: User

1. The problem addressed

When you need to enter many commands at once, for example, to remove files from multiple directories at once

Copy Code code as follows:

CD Dir1
RM file1.temp
Cd.. /.. /dir2
RM-RF Dir3

When you don't bother typing a 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 to a button to do repetitive things and don't bother to write a lot of scripts,
Duang~~ This tool is useful!

2. Perceptual knowledge

This tool is a shell script, attached at the end of this article, copy the entire script source, save locally as rew.sh, put under $path, plus chmod +x permissions.
Name of file can be changed according to preference. R e W can be entered with one left hand, and then the TAB key is out. SH, I feel pretty good.

The complex operation described above becomes as simple as this:

Go to several directories at a time to delete files, only need rew.sh D
If you want to specify a starting directory, you can also take the parameter rew.sh D dir_path

Generate Ctags, only need rew.sh ct

If you forget what this script does, just run crt.sh with no parameters and list all the commands.

3. Rational knowledge

If you want to add a custom command, find the

Copy Code code as follows:

Cmds= (XXXXX)

Place, add one line to it. Each line is a parameter and a real command that you can see:
Copy Code code 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 before the rew.sh parameters (shortcut key), the first space after the actual operation of the command. The commands for several of these steps can be made into functions, such as:

Copy Code code as follows:

Updatechrome () {
Git pull
CD Third_party/webkit
Git pull
Gclient Sync--nohooks
}

If you are afraid to forget the long command to do, you can also put into the function, the name of the function to see the name known or annotated.

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

Attach Tool Script:

Copy Code code 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 $;} ' `
echo "$rsss"
Pids= ' echo ' $ps | awk ' {print $} ' `
for P in $pids; Todo
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/. BROWSERACTIVITY-E Policy ucm_current_window-d $
}

# 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++); Todo
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 255
Fi

for ((i = 0; i < ${#cmds [@]}; i++); Todo
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 $@
Exit $?
Fi
Done

# If no cmd matched, echohelp
Echohelp

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.