The Journey of Mastering iTerm2
Compared to Mac’s built-in Terminal, I find iTerm2 to be quite powerful. Here I’ll summarize some settings and tips from my usage experience.
The app has too many complete settings to describe one by one, so I'll only highlight some configurations that I personally consider important
Basic Settings
Recommended Theme: Minimal
The terminal will have an immersive experience without a separate header toolbar
Badge Settings
Set badges for each profile to distinguish sessions/machines. Note that badge settings are per profile and don’t work for all machines.
Default Timestamp Display
Often I want to know the approximate time when commands were executed, so I enable the timestamp display on the right side by default
Enable Status Bar
Terminal sessions can display some data information, such as memory usage, battery level, etc.
Settings Sync/Save
Since I have multiple Mac devices, I want iTerm2 settings to sync automatically across devices. You can configure this by saving the configuration file to iCloud Drive, then loading it in iTerm2 on another Mac.
The configuration for iTerm2 should be consistent across multiple Macs
Unlimited Scrollback
Sometimes our terminal error output is very long. If you want to scroll up to see the complete output, you need to configure
Unlimited scrollback
Cursor Guide Settings
The line where the cursor is located will be highlighted with a different background color
Color Presets
Recommend coolnight
More themes recommended here
https://github.com/mbadolato/iTerm2-Color-Schemes
Integrated Tools
iTerm2 is powerful not only because of its built-in features but also because it can integrate with the following tools to become even more useful
oh my zsh
zsh is a powerful shell, and oh my zsh makes it even better and more beautiful.
- Visit the official website
- Install and set up the recommended theme
Recommended zsh Plugins
git
git-extras
zsh-syntax-highli
zsh-autosuggestio
autojump
jhipster
docker
docker-compose
spring
cask
macos
colored-man-pages
tmux
tmux can solve session saving/restoration. For detailed introduction, you can check my other summary. Here’s a brief description:
- Global settings in iTerm2
- Install tmux on the target machine
- Set commands in profile to enable when logging into the machine
ssh -p 22 -t root@188.146.132.160 "tmux -CC attach || tmux -CC"
Alfred
After Alfred integration, you can directly input commands in the input box to trigger iTerm2 execution
Copy script content
Alfred -> Features -> Terminal
Others
Dynamic Profile
When frequently operating multiple server terminals in iTerm2, there’s a problem of how to reuse profile configurations, such as szrz trigger support and key settings.
The solution is iTerm2 Dynamic Profile
Configuration
- cd ~/Library/Application\ Support/iTerm2/DynamicProfiles
- Create
iterm2-profile-template.json
- Configure
iterm2-profile-template.json
. For specific profile configuration items, you can configure a target in the UI, select export to json, and copy the needed configuration items to the template file- Here’s my template for reference
- UI operation to copy target configuration items
- Select template profile
- Select the category items that need to be copied Not all configurations in the current profile support copying
- Select the target profiles to copy to, multiple selection supported
- Select template profile
This solves the problem of profile configuration reuse
Dynamic Profile Parent Name
Profile templates themselves also support dynamic inheritance. The configuration method is the same as above, just with two additional fields Dynamic Profile Parent Name
and Dynamic Profile Parent GUID
to indicate inheritance relationships
- Either
name/guid
can be configured - Profiles in templates are lists, so pay attention to the configuration placement order: parent first, child inheritance after
GUID
generation can use the command line tooluuidgen
Recommended to create a soft link for profiles and sync to cloud drive for easy reuse.
ln -s "$HOME/Library/Mobile Documents/com~apple~CloudDocs/conf/iTerm2/iterm2-profile-template.json" "$HOME/Library/Application Support/iTerm2/DynamicProfiles/iterm2-profile-template.json"
Semantic History
Execute different actions when clicking different files in the iTerm2 terminal. 🚀
Script installation, click here
Triggers
For simple file upload and download, using SZRZ is much more convenient than using FileZilla alone
Final Thoughts
See how powerful iTerm2 is? Let’s get started with it.