Tuesday, January 23, 2018

iTerm2



https://codeburst.io/8-must-know-terminal-commands-and-tips-for-productivity-mac-edition-95935dba3ebc
3) iTerm2 split screening

The hotkeys for horizontal split are: cmd + d

The hotkeys for vertical split are: cmd + shift+ d


https://dev.to/therealdanvega/new-macbook-setup-for-developers-2nma
brew cask install iterm2
  • Launch iTerm 2. Get the latest version at iterm2.com
  • Type CMD+i
  • Navigate to Colors tab
  • Click on Load Presets
  • Click on Import
  • Select the .itermcolors file(s) of the scheme(s) you'd like to use
  • Click on Load Presets and choose a color scheme
https://gist.github.com/squarism/ae3613daf5c01a98ba3a
Clear the screen/pane (when Ctrl + L won't work) + K (I use this all the time)
https://superuser.com/questions/1018391/iterm2-clear-scrollback-buffers-for-all-sessions
cmd+K will clear current session
https://elweb.co/making-iterm-2-work-with-normal-mac-osx-keyboard-shortcuts/
The ones that I needed most where ⌥← (Option-Left Arrow) to move left one word, ⌥→ (Option-Right Arrow) to move right one word


https://gitlab.com/gnachman/iterm2/issues/3717#note_1733467
[Restore last windows after restart]
Ensure Prefs>Advanced>Restore window contents at startup is set to Yes. This is the default, so I doubt it's changed. Also Make sure Close windows when quitting an app is off in System Prefs>General:

https://medium.com/@jessesrsmith/five-tips-for-iterm-91db83cf4d4e
This one can save a lot of time. To access everything you’ve pasted into iTerm, use ⌘⇧H and select the command you wish to paste again.

To create a new workspace, first cd into your project’s directory. To create a horizontal split, use ⌘⌥⇧H, or ⌘⌥⇧V for a vertical split. When creating a new pane, iTerm will ask what profile you want to use. After you have a few panes created, you can rearrange them by dragging with the mouse. Once your panes are in a preferred configuration, just hit ⌘⇧S to save the window arrangement. To launch your arrangement, use ⌘⇧R at anytime.
For those using laptops or smaller monitors, ⌘⇧⏎ will maximize/minimize the active pane. This is useful for examining log files in greater depth.

https://superuser.com/questions/333591/windows-open-maximized-by-default
Somehow most other software I use opens up maximized anyway, possibly because I use ShiftIt and Ctrl-Alt-Cmd M a lot (and most software seems to remember the previously used window size). The only thing I use a lot that didn't open maximimized was iTerm2.

You can get iTerm2 to open in a maximized window by going to Preferences -> Profiles -> Window and setting a high number of Columns and Rows

https://gitlab.com/gnachman/iterm2/issues/4162
Recent directories (including starred ones) are gone after closing and reopening iTerm2
Shell integration works fine and continuously adds directories to my "Recent directories" section in the toolbelt.
Starting another session in a new window perfectly shows the same recent and starred directories. Multiple sessions of the same profile keep in sync as expected. But closing all sessions and reopen a new one works fine only as long as I do not close iTerm itself (what I do regularly to install nightly builds).

I would love to keep the starred directories persistently.

urning on Prefs > General > Save copy/paste and command history

https://superuser.com/questions/93573/select-text-in-iterm-using-keyboard
You could also assign custom keys in Prefs -> Keys. (Source)

move selection forward by word
move selection backward by word
https://gist.github.com/squarism/ae3613daf5c01a98ba3a

https://www.iterm2.com/documentation-badges.html
\(session.username)@\(session.hostname)
Its initial value is defined in Preferences>Profiles>General>Badge and it can be changed by an iTerm2-proprietary escape sequence. It may also reference iTerm2- and user-defined variables.
https://www.iterm2.com/documentation-images.html

Open Quickly

If you have lots of sessions you can quickly find the one you're looking for with Open Quickly. Select the View > Open Quickly menu item (cmd-shift-O) and then enter a search query. You can search by tab title, command name, host name, user name, profile name, directory name, badge label, and more. Open Quickly also lets you create new tabs, change the current session's profile, and open arrangements. If you start your query with a / then that gives you a shortcut to various commands. Enter a query of / to see them.

Cursor Location Assistance

Never lose your cursor. An optional cursor guide highlights the entire row your cursor is on and Cursor Boost dims all colors other than the cursor to make it really stand out.

Undo Close

Undo closing sessions, tabs, and windows. If you close a session by accident, you get five seconds to hit Cmd-Z to undo it.

Tab Bar on Left

Have lots of tabs? Put the tab bar on the left. Quickly search them by recent commands, directories, current host name, profile name, and more with the Open Quickly feature.

https://www.iterm2.com/features.html

Captured Output

The next time you log in, shell integration will be enabled.

You will also have these commands:
imgcat filename
  Displays the image inline.
it2dl filename
  Downloads the specified file, saving it in your Downloads folder.

You can navigate marks with Cmd-Shift-Up and Down-arrow keys.

Alert on next mark

iTerm2 can show an alert box when a mark appears. This is useful when you start a long-running command. Select Edit>Marks and Annotations>Alert on next mark (Cmd-Opt-A) after starting a command, and you can go do something else in another window or tab. When the command prompt returns, a modal alert will appear, calling attention to the finished job.

Command status

The mark on a command line will turn red if a command fails. You can right click the mark to view its return code.
Command history popup
You can view and search the command history with Session>Open Command History... (Shift-Cmd-;).
Autocomplete
Commands in command history are also added to Autocomplete (Cmd-;). If Preferences>General>Save copy/paste history and command history to disk is enabled, then command history will be preserved across runs of iTerm2 (up to 200 commands per user/hostname).
Toolbelt
A command history tool may be added to the toolbelt by selecting Toolbelt>Command History.

Recent Directories popup
You can view and search your recently and frequently used directories in Session>Open Recent Directories... (Cmd-Opt-/).

download with scp  - need install shell integration on remote host  

Default characters considered part of word for selection
/-+\~_.
https://medium.com/@jessesrsmith/five-tips-for-iterm-91db83cf4d4e

4. Paste History

This one can save a lot of time. To access everything you’ve pasted into iTerm, use ⌘⇧H and select the command you wish to paste again.

2. Clickable Links

A simple one: hold the  key and click on any URL. iTerm will open the link in a new browser tab. This is great for opening localhost windows after a dev server starts. 
http://teohm.com/blog/working-effectively-with-iterm2/
  • clear buffer Cmd + k
  • toggle maximize window Cmd + Alt + =
  • toggle full screen Cmd + Enter
  • make font larger Cmd + +
  • make font smaller Cmd + -
Launch iTerm, open iTerm > Preferences or just Cmd + ,.

Open tab/pane with current working directory

Under Profiles tab, go to General subtab, set Working Directory to “Reuse previous session’s directory”.

Enable Meta key

To enable Meta key for Bash readline editing e.g. Alt + b to move to previous word, under Profilestab, go to Keys subtab, set Left option key acts as: to “+Esc”.

Hotkey to toggle iTerm2

Under Keys tab, in Hotkey section, enable “Show/hide iTerm2 with a system-wide hotkey” and input your hotkey combination, e.g. I use Ctrl + Shift + L.
https://medium.com/@hlung/using-smart-selection-in-iterm2-to-make-asana-task-id-or-any-text-clickable-dddbbbe2bbe8
One thing I notice in iTerm2 is if we hold  and hover around texts, URLs will be highlighted and clickable. It would be nice if I can do this to other text as well. It turns out there’s a feature in iTerm2 that can help us — it’s called Smart Selection.

https://www.iterm2.com/documentation-smart-selection.html
You should be able to make iTerm.app your default terminal by selecting "Make Default" from the menu bar.


iTerm2 是最常用的终端应用,是 Terminal 应用的替代品。提供了诸如Split Panes一群实用特性。它默认的黑色背景让我毫不犹豫的抛弃了 Terminal。
安装:
brew cask install iterm2
感谢 brew-cask,我们可以通过命令行自动安装 iTerm2 了。
在终端里,除了可以用⌃E等快捷键(详见其他快捷键)之外,还可以使用⌥B⌥F等快捷键(具体可以参考这里)。前提是这样设置一下:
选择Iterm菜单 > Preferences > Profiles,选择你在使用的 Profile(默认是Default),在Keys标签页中把Left option (⌥) key acts asRight option (⌥) key acts as都设置成+ESC
在打开新的窗口/标签页的时候,默认情况下新窗口总是 HOME 目录,还需要我每次敲命令才能进入工作目录。如果想要这个新窗口在打开的时候就自动进入工作目录,需要如下设置:
选择Iterm菜单 > Preferences > Profiles,选择你在使用的 Profile(默认是Default),在General标签页中的Working Directory部分中选择Reuse previous seesion's directory
至此,Terminal 应用已经出色的完成了其历史使命。后面命令行就交给 iTerm2 啦。
在 iTerm2 中双击会自动选中对应的词,三击会选中对应的整行。选中的内容会自动进入剪贴板,不需要再按⌘C复制。
http://apple.stackexchange.com/questions/63000/how-to-highlight-errors-and-warnings-on-iterm-terminal-output
iTerm supports coloring of console output based on a set of regular expressions. You can set them up in Preferences > Profiles > Advanced > Triggers > Edit.
Here is my current set of regexes:
(?i:.*error.*)                     // Yellow on Black
(?i:.*(warning|warn).*)            // Orange on Black
(?i:.*FATAL.*)                     // White on Red
iTerm regexes in a profile’s Triggers

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts