- Open multiple terminal Windows at the same time, switching back and forth is too troublesome!
- Can I view pasted history records like IDEA?
- Is there a way to log in to the server with one click?
To do a good job, you must sharpen your tools. It’s really important to choose the right tools for work or study. ITerm2: iTerm2: iTerm2: iTerm2: iTerm2: iTerm2: iTerm2: iTerm2: iTerm2
As an engineer who often deals with Terminal, the Windows command line is the most difficult to use for the native Terminal. The author generally uses XShell. After entering the pit Mac found that everyone is using iTerm2, half a year down to feel only two words: really sweet!
- Like it before you see it, make it a habit. Thank you
01 Window Management
Window, of course, is how to want to how to divide! One key difference from the Mac native Terminal is that iTerm2 supports arbitrary splitting and creation of Windows.
Hotkey Window
ITerm2 ->Perferences->Kes->Hotkey to open the iTerm window.
If you already have the iTem2 app open, you can open and hide it with one click shortcuts. The main features of the default Hotkey Window are transparency and hover. It can hover over any Window.
Ordinary Window
Create Window: Command + N Close Window: Command + W Full screen: Command + Enter, press again to restore display all Windows: Command + Option + e Close Window: Command + W
Tab Tab
Create a label: Command + T Close a label: Command + W Switch a label: Command + digit or Command + left/right direction
Pane Panes
Vertical split screen: Command + D Horizontal split screen: Command + Shift + D Switch panes: Command + Option + arrow keys or Command + left and right parentheses
02 Instant Replay
In addition to window partitioning, another killer feature of Term2 is playback. You can not only view the clipboard history, but also play back the history in the window like video!
Historical shear plate
For a normal text editor, each copy overwrites the previous clipboard, making it very difficult to use. ITerm2 provides the same functionality as IDEA to view the history clipboard, which is quite friendly for the CV engineer!
Shortcut keys ** : Command + Shift + h**
History Command prompt
Command prompt, can prompt the recently entered content, and commonly used commands; Note that only the typed content is used here, but iTerm also has command completion plugins, which I’ll cover later.
Shortcut keys: Command +;
Of course, in addition to the history command prompt, you can also use the system support way to search and view the history command.
Previous command: Ctrl + P (Previous) or Up arrow key Next command: Ctrl + N (Next) or Down arrow key Search history command: Ctrl + R
Instant replay
Very interesting function, like recording screen, record the past period of time window display content.
Shortcut key: Command + Option + B
Forward/backward: Left and right arrows/mouse drag the progress bar **Exit the playback: esc
03 Shortcut Functions
Intelligent copy
Select item to copy, and the selected text is automatically saved to the clipboard. Double click to select, triple click to select the entire line, four click intelligent selection, you can intelligently select the data you want, such as url, email, parentheses or quotes data.
Quick pasting is also supported. After the mouse is selected, you can use the middle mouse button or Command+ V to paste. At the same time, you can also quickly copy and paste by dragging and dropping.
To complete the search, run Command+ F. After the search, press Tab or Tab + Shift to expand the selection to the right or left.
Use the Command
Command can be combined with other keys to create shortcut keys, or with the mouse to achieve some shortcut functions. Just press Command to match the action.
-
Click on the URL and invoke the default browser to access the url
-
Click the file and call the default program to open the file. If filename: number is selected and the default text editor is Mac VIm will open directly to this line.
-
Click on the folder to open it in Finder
-
With the Optional key, select the rectangular area content with the mouse
Common Shortcut keys
These shortcuts are not specific to iTem2 and are very basic. Most importantly, of course, they are very practical and are used almost every day.
Clear the screen: Command + R or CTRL + L Clear the current line: CTRL + U Delete the current cursor character: CTRL + D Delete the character before the cursor: CTRL + H Delete the word before the cursor: CTRL + W Delete to the end of the text: CTRL + K Switch cursor text: CTRL + T Cursor move leading line: CTRL + A Cursor move to line position: CTRL + E
04 One-click Login
ITerm2 certainly does a good job of supporting basic operations such as quick login. Simply configure the script in the Command input box in iTerm2->Preferences->Profiles->General, either as a single line Command or as a Shell script file.
ssh + sshpass
The SSH command is generally used to remotely log in to a Linux host. However, you need to log in in two steps. Enter the SSH connection command first and then enter the password when the server responds.
To combine the two logins into one step, simply install the sshpass tool, which is used for non-interactive SSH password authentication. Sshpass allows you to specify a plaintext password and then configure SSH commands to log directly into the remote server.
It supports reading passwords from command lines, files, and environment variables. The three uses are as follows:
#1. PasswordSshpass -p {password} SSH -p ${port} {username}@{host IP address}#2. Password text fileSshpass -f {password text file} SSH -p ${port} {username}@{host IP}#3. Environment variables
#Configuring environment Variables
export SSHPASS='my_pass_here'
echo $SSHPASS
#landingSshpass - e SSH to [email protected]Copy the code
Note that in order to prevent the password from first appearing on the screen, it is common to log in using a password file and environment variables.
Expect scripts
Work usually can not be directly connected to the server or database, but need to log in the jumper, and then through the jumper to connect the line server/database. These can be solved with expect scripts.
Expect is a tool used for automatic control and testing, mainly for automatic interaction with SSH/TALnet/FTP and other interactive software, such as remote automatic password input, script execution, etc.
The rough idea behind Expect is to spawn the command we want to execute, then set one or more results we expect from command A, select the next branch based on matching results, and then execute subsequent commands through send, simulating keyboard input.
Suppose we want to implement automatic login to the online database and view all the data tables. Specific steps can be divided into the following steps:
- Log on the jumper
- Log in to the online database via the jumper
- Select Database, and then run the show tables command
Here is a simple script template provided by the author:
#! /usr/bin/expect -f
#Script parameters, mysql server login address, password, and select database instructions
set loginCommand [lrange $argv 0 1]
set passwd [lrange $argv 2 2]
set script [lrange $argv 3 4]
#Timeout period of waiting for command execution, 10s
set timeout 10
#1. Log on the jumperSpawn SSH username @host expect {# spawn SSH username @host expect {# spawn SSH username @host expect { Username @host's password:" {send "host's password \r"; $loginCommand\r; $loginCommand\r; $loginCommand\r; Exp_continue} # Enter password:" {send "$passwd\r; Exp_continue} # "*ERROR*" interact; "Welcome to the MySQL monitor "{send "$script\r"; Exp_continue} # execute show tables directive "Reading table information*" {send "show tables; \r"} } interactCopy the code
Command configures script files and execution parameters
/ / Users/XXX ssh_login. J exp mysql [email protected]: 3456 database password use dbzz_zzpayaccountCopy the code
Execute configuration file, effect picture:
05 Waiting for you to explore
ITerm2 supports a lot of custom personalization and has interesting and useful features to explore. If you want to make your iTerm2 look cool, geeky. Might as well see here www.jianshu.com/p/7de00c73a…
Space is limited, such as password manager, input (command) broadcast and other practical functions, not listed here. It is said that every programmer has his sunflower treasure dictionary, welcome to the students in the message area to share your most handy tools to everyone!