For engineers who need to work with terminals for a long time, it is necessary to have a decent terminal manager, and for Windows users, the best choice is Xshell, which no one disputes. But for MacOS users, there’s still no doubt that iTerm2 is what you want, and if you don’t think it is, that’s your problem, not iTerm2’s. Today I’m going to tell you what the problem is, and what I’m going to show you is basically a recipe you’ve never seen before, so keep your eyes peeled!
This tutorial is divided into three parts: the first is about setting up and optimizing iTerm itself; The second part is about setting up and optimizing connections to remote servers. The third part is about ZSH setup and optimization.
Today is the first part.
1. Suspension window
First, let’s solve the first problem: how do I call in and out of iTerm2 Windows on any interface and float them at the top of the interface?
I believe everyone has this scenario: you are browsing a web page in a full-screen browser, or writing code in a full-screen editor to write an article or something, suddenly think of something, or find something, want to quickly open the terminal, perform a command or two (such as open a file, start a service, etc.), and then close.
In this case, the vision is to be able to quickly open the terminal with a shortcut key, and then quickly hide it with the same shortcut key until it comes to me again when I need it. As for the implementation method, although tedious but not complicated, the following steps follow me:
Creating a New Profile
First open Preperence → Profiles and create a new profile named HotKey Window.
Background transparency and blur Settings
Set it in Preperence → Profiles → Window → Window Appearance
Window Style configuration
Go to Preperence → Profiles → Window → Settings for New Windows
Explain these parameters:
- Full-width Top of Screen: This is easy to understand, so that the terminal appears at the Top of the Screen and takes up the entire Width.
- Current Spce: indicates that only the Current workspace is displayed. For example, if you have a terminal open on the Current screen, it will not follow when you switch to the next screen.
- Screen Width Cursor: This is used with the above parameter to determine which Screen belongs to the current workspace, indicating where your mouse is, and which is the current workspace.
Set the HotKey
Go to Preperence → Profiles → Keys → HotKey Window
Select A hotkey opens A dedicated window with this profile, which indicates that the profile can be opened and closed quickly by using shortcut keys.
Then click Configure Hotkey Window and set the shortcut key.
To use only one key, you can use function keys as shortcuts. I chose F12.
One caveat here is that function keys only work on macBooks without Touch Bar. For the new MacBook with Touch Bar, you can only use other combination shortcuts, such as Cmd+P. As for the reason, the function keys on the new MacBook are only displayed on the Touch Bar, so you can only open the function keys for each application, which means that the function keys are only displayed on the Touch Bar when you open the app, but we want to use the shortcut keys to call the terminal from anywhere. I can’t open terminal first and then use function keys to open terminal… It’s a chicken-and-egg problem, so stick with other shortcuts.
For a MacBook without Touch Bar, we can do this by first opening system Preferences and selecting keyboard Settings.
Select keys F1 and F2 as standard function keys.
This allows you to quickly open and close the terminal via F12.
Please note: after opening the standard function key, the special function of the function key, such as F11 to reduce the volume, F12 to increase the volume, must be combined with Fn key, for example, to increase the volume is Fn+F12.
On the new MacBook with Touch Bar, you can do this by opening system Preferences and selecting keyboard Settings.
“Press the Fn key to” select “display F1, F2 and other keys” :
This allows you to quickly open the terminal using Fn+F12.
At the same time, add iTerm application in shortcut key → function key Settings, so that you can directly use F12 key to close the iTerm2 window.
So far, the Profile on the hover terminal is configured, and you can press your HotKey to quickly open and hide the command line. If you want to create new tabs using this Profile, you can set Hotkey Window to the default Profile:
Now let’s do some optimization.
2. Change the cursor shape
Set it in Preperence → Profiles → Text.
The default cursor shape is maroon:
The cursor shape is much more pleasing to the eye after changing the Settings:
3. Speak for yourself
If you want to speak for yourself and want to put your Logo on any new terminal window, you can set it in Preperence → Profiles → General.
! [](/Users/cnsgyg/Desktop/ screen snapshot 2020-03-10 PM 2.56.46.png)
So no matter which terminal I switch to, I can fuck Cloud Native!
4. Customize the label title
Set it in Preperence → Profiles → General.
Deselect Applications in terminal may change the title:
Title Select Profile Name and deselect Job Name:
The title of each TAB page is displayed as the corresponding Profile Name:
5. Customize color schemes
There is a ready-made colorscheme on the web that we can use directly here: iterm2colorschemes.com/.
Download the zip package and unzip it. Open the Settings for iTerm2: Preperence → Profiles → Colors → Color Presets. Click Import and select your desired theme import from schemes in the extracted theme directory.
Import, and then choose the theme you want, I of course is Ubuntu purple ~~
6. Match colors
By default, the TAB color is black, even if you change the color scheme:
If you want a uniform color palette, you need to modify the configuration slightly. Go to Appearence → General and change the Theme to Minimal:
7. Close the startup page
If you don’t want to open iTerm2 with the default window every time you open the program silently, you can set Appearence → General:
Check Exclude from Dock and… The next time you reopen iTerm2 after changing the Settings, it will look like this:
It no longer appears in the Dock, nor does it open a default window for you when you start up, and you can gracefully call in and out of the window with shortcut keys, perfect.
Use shell Integration
ITerm2 can be integrated with the Unix shell. After installing the Shell integration tool for iTerm2, you can see the command history, current working directory, host name, uploaded and downloaded files, and so on in iTerm2.
You can either go to the menu bar iTerm2 > Install Shell Integration or enter a terminal command:
If your default shell is bash, change ZSH to bash
$ curl -L https://iterm2.com/misc/install_shell_integration.sh | zsh
Copy the code
The script automatically installs the corresponding script of the current terminal shell and writes it to the corresponding shell configuration file. For example, after executing a script in ZSH shell, the following statement is written in the middle of.zshrc:
$ test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
Copy the code
After installing iTerm2’s shell integration, there will be an extra blue triangle on the far left of the terminal interface. As shown in figure:
Tags with blue triangles indicate that the current shell supports shell Integration. To turn off the markup, you can turn off Show Mark Indicators in iTerm2 > Preferences > Profiles > (Your Profile) > Terminal bottom > Shell Integration.
All tools:
imgcat filename
Displays the image inline.
imgls
Shows a directory listing with image thumbnails.
it2api
Command-line utility to manipulate iTerm2.
it2attention start|stop|fireworks
Gets your attention.
it2check
Checks if the terminal is iTerm2.
it2copy [filename]
Copies to the pasteboard.
it2dl filename
Downloads the specified file, saving it in your Downloads folder.
it2setcolor ...
Changes individual color settings or loads a color preset.
it2setkeylabel ...
Changes Touch Bar function key labels.
it2ul
Uploads a file.
it2universion
Sets the current unicode version.
Copy the code
For example, you can use imgCat to display images directly on the terminal:
9. Clever tricks
Finally, some of iTerm2’s quirks.
Clipboard history
ITerm2 allows us to quickly view the contents of the clipboard simply by using Command + Shift + H to call out the paste history, supporting fuzzy retrieval. You can also set the paste history to save on disk (Preferences -> General)
Intelligent selected
In iTerm2, double click to select, triple click to select the entire line, four click intelligent select (intelligent rules can be configured), can recognize urls, quotes caused by strings, email addresses, etc. (A lot of times the double click is already smart)
Using the Command button
Press the ⌘ key:
- You can drag and drop the selected string;
- Click on url: call the default browser to visit the url;
- Click file: call the default program to open the file;
- Click On Folder: To open the folder in Finder;
- At the same time hold down the
option
Key, which can be selected as a rectangle, similar to viMctrl v
Operation.
Copy the text content to the clipboard
$ pbcopy < text.md
Copy the code
Open the current directory in Finder
$ open .
Copy the code
Ok, the setup and optimization of iTerm itself is over here. The next article will cover the setup and optimization of connecting to remote servers, so stay tuned.
Wechat official account
Scan the following QR code to follow the wechat public account, in the public account reply ◉ plus group ◉ to join our cloud native communication group, and Sun Hongliang, Zhang Curator, Yang Ming and other leaders to discuss cloud native technology