dotfiles/.config/zsh/.iterm2/it2tip
2022-06-22 11:34:03 +07:00

401 lines
20 KiB
Python
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import os
import sys
tips = [
{
"title": "Shell Integration",
"body": "The big new feature of iTerm2 version 3 is Shell Integration. Click “Learn More” for all the details.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Timestamps",
"body": "“View > Show Timestamps” shows the time (and date, if appropriate) when each line was last modified."
},
{
"title": "Password Manager",
"body": "Did you know iTerm2 has a password manager? Open it with “Window > Password Manager.” You can define a Trigger to open it for you at a password prompt in “Prefs > Profiles > Advanced > Triggers.”"
},
{
"title": "Open Quickly",
"body": "You can quickly search through your sessions with “View > Open Quickly” (⇧⌘O). You can type a query and sessions whose name, badge, current hostname, current user name, recent commands, and recent working directories match will be surfaced. It works best with Shell Integration so the user name, hostname, command, and directories can be known even while sshed.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Undo Close",
"body": "If you close a session, tab, or window by accident you can undo it with “Edit > Undo” (⌘Z). By default you have five seconds to undo, but you can adjust that timeout in “Prefs > Profiles > Session.”"
},
{
"title": "Annotations",
"body": "Want to mark up your scrollback history? Right click on a selection and choose “Annotate Selection” to add a personal note to it. Use “View > Show Annotations” to show or hide them, and look in “Edit > Marks and Annotations” for more things you can do."
},
{
"title": "Copy with Styles",
"body": "Copy a selection with ⌥⌘C to include styles such as colors and fonts. You can make this the default action for Copy in “Prefs > Advanced.”"
},
{
"title": "Inline Images",
"body": "iTerm2 can display images (even animated GIFs) inline.",
"url": "https://iterm2.com/images.html"
},
{
"title": "Automatic Profile Switching",
"body": "Automatic Profile Switching changes the current profile when the username, hostname, or directory changes. Set it up in “Prefs > Profiles > Advanced.” It requires Shell Integration to be installed.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Captured Output",
"body": "iTerm2 can act like an IDE using the Captured Output feature. When it sees text matching a regular expression you define, like compiler errors, it shows the matching lines in the Toolbelt. You can click to jump to the line in your terminal and double-click to perform an action like opening an editor to the line with the error.",
"url": "https://iterm2.com/captured_output.html"
},
{
"title": "Badges",
"body": "You can display a status message in the top right of your session in the background. Its called a “Badge.” If you install Shell Integration you can include info like user name, hostname, current directory, and more.",
"url": "https://iterm2.com/badges.html"
},
{
"title": "Dynamic Profiles",
"body": "Dynamic Profiles let you store your profiles as one or more JSON files. Its great for batch creating and editing profiles.",
"url": "https://iterm2.com/dynamic-profiles.html"
},
{
"title": "Advanced Paste",
"body": "“Edit > Paste Special > Advanced Paste” lets you preview and edit text before you paste. You get to tweak options, like how to handle control codes, or even to base-64 encode before pasting."
},
{
"title": "Zoom",
"body": "Ever wanted to focus on a block of lines without distraction, or limit Find to a single commands output? Select the lines and choose “View > Zoom In on Selection.” The sessions contents will be temporarily replaced with the selection. Press “esc” to unzoom."
},
{
"title": "Semantic History",
"body": "The “Semantic History” feature allows you to ⌘-click on a file or URL to open it."
},
{
"title": "Tmux Integration",
"body": "If you use tmux, try running “tmux -CC” to get iTerm2s tmux integration mode. The tmux windows show up as native iTerm2 windows, and you can use iTerm2s keyboard shortcuts. It even works over ssh!",
"url": "https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration"
},
{
"title": "Triggers",
"body": "iTerm2 can automatically perform actions you define when text matching a regular expression is received. For example, you can highlight text or show an alert box. Set it up in “Prefs > Profiles > Advanced > Triggers.”",
"url": "https://www.iterm2.com/documentation-triggers.html"
},
{
"title": "Smart Selection",
"body": "Quadruple click to perform Smart Selection. It figures out if youre selecting a URL, filename, email address, etc. based on prioritized regular expressions.",
"url": "https://www.iterm2.com/smartselection.html"
},
{
"title": "Instant Replay",
"body": "Press ⌥⌘B to step back in time in a terminal window. Use arrow keys to go frame by frame. Hold ⇧ and press arrow keys to go faster."
},
{
"title": "Hotkey Window",
"body": "You can have a terminal window open with a keystroke, even while in other apps. Click “Create a Dedicated Hotkey Window” in “Prefs > Keys.”"
},
{
"title": "Hotkey Window",
"body": "Hotkey windows can stay open after losing focus. Turn it on in “Window > Pin Hotkey Window.”"
},
{
"title": "Cursor Guide",
"body": "The cursor guide is a horizontal line that follows your cursor. You can turn it on in “Prefs > Profiles > Colors” or toggle it with the ⌥⌘; shortcut."
},
{
"title": "Shell Integration: Alerts",
"body": "The Shell Integration feature lets you ask to be alerted (⌥⌘A) when a long-running command completes.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Cursor Blink Rate",
"body": "You can configure how quickly the cursor blinks in “Prefs > Advanced.”"
},
{
"title": "Shell Integration: Navigation",
"body": "The Shell Integration feature lets you navigate among shell prompts with ⇧⌘↑ and ⇧⌘↓.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Shell Integration: Status",
"body": "The Shell Integration feature puts a blue arrow next to your shell prompt. If you run a command that fails, it turns red. Right click on it to get the running time and status.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Shell Integration: Selection",
"body": "With Shell Integration installed, you can select the output of the last command with ⇧⌘A.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Bells",
"body": "The dock icon shows a count of the number of bells rung and notifications posted since the app was last active."
},
{
"title": "Shell Integration: Downloads",
"body": "If you install Shell Integration on a machine you ssh to, you can right click on a filename (for example, in the output of “ls”) and choose “Download with scp” to download the file.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Find Your Cursor",
"body": "Press ⌘/ to locate your cursor. Its fun!"
},
{
"title": "Customize Smart Selection",
"body": "You can edit Smart Selection regular expressions in “Prefs > Profiles > Advanced > Smart Selection.”",
"url": "https://www.iterm2.com/smartselection.html"
},
{
"title": "Smart Selection Actions",
"body": "Assign an action to a Smart Selection rule in “Prefs > Profiles > Advanced > Smart Selection > Edit Actions.” They go in the context menu and override semantic history on ⌘-click.",
"url": "https://www.iterm2.com/smartselection.html"
},
{
"title": "Visual Bell",
"body": "If you want the visual bell to flash the whole screen instead of show a bell icon, you can turn that on in “Prefs > Advanced.”"
},
{
"title": "Tab Menu",
"body": "Right click on a tab to change its color, close tabs after it, or to close all other tabs."
},
{
"title": "Tags",
"body": "You can assign tags to your profiles, and by clicking “Tags>” anywhere you see a list of profiles you can browse those tags."
},
{
"title": "Tag Hierarchy",
"body": "If you put a slash in a profiles tag, that implicitly defines a hierarchy. You can see it in the Profiles menu as nested submenus."
},
{
"title": "Downloads",
"body": "iTerm2 can download files by base-64 encoding them. Click “Learn More” to download a shell script that makes it easy.",
"url": "https://iterm2.com/download.sh"
},
{
"title": "Command Completion",
"body": "If you install Shell Integration, ⇧⌘; helps you complete commands. It remembers the commands youve run on each host that has Shell Integration installed. It knows how often that command was run and how recently to help make the best suggestions.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Recent Directories",
"body": "iTerm2 remembers which directories you use the most on each host that has Shell Integration installed. Theres a Toolbelt tool to browse them, and ⌥⌘/ gives you a popup sorted by frequency and recency of use.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Favorite Directories",
"body": "If you have Shell Integration installed, you can “star” a directory to keep it always at the bottom of the Recent Directories tool in the Toolbelt. Right click and choose “Toggle Star.”",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Shell Integration History",
"body": "Install Shell Integration and turn on “Prefs > General > Save copy/paste and command history to disk” to remember command history per host across restarts of iTerm2.",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Paste File as Base64",
"body": "Copy a file to the pasteboard in Finder and then use “Edit > Paste Special > Paste File Base64-Encoded” for easy uploads of binary files. Use ”base64 -D” (or -d on Linux) on the remote host to decode it."
},
{
"title": "Split Panes",
"body": "You can split a tab into multiple panes with ⌘D and ⇧⌘D."
},
{
"title": "Adjust Split Panes",
"body": "Resize split panes with the keyboard using ^⌘-Arrow Key."
},
{
"title": "Move Cursor",
"body": "Hold ⌥ and click to move your cursor. It works best with Shell Integration installed (to avoid sending up/down arrow keys to your shell).",
"url": "https://iterm2.com/shell_integration.html"
},
{
"title": "Edge Windows",
"body": "You can tell your profile to create windows that are attached to one edge of the screen in “Prefs > Profiles > Window.” You can resize them by dragging the edges."
},
{
"title": "Tab Color",
"body": "You can assign colors to tabs in “Prefs > Profiles > Colors,” or in the View menu."
},
{
"title": "Rectangular Selection",
"body": "Hold ⌥⌘ while dragging to make a rectangular selection."
},
{
"title": "Multiple Selection",
"body": "Hold ⌘ while dragging to make multiple discontinuous selections."
},
{
"title": "Dragging Panes",
"body": "Hold ⇧⌥⌘ and drag a session into another session to create or change split panes."
},
{
"title": "Cursor Boost",
"body": "Adjust Cursor Boost in “Prefs > Profiles > Colors” to make all colors more muted, except the cursor. Use a bright white cursor and it pops!"
},
{
"title": "Minimum Contrast",
"body": "Adjust “Minimum Contrast” in “Prefs > Profiles > Colors” to ensure text is always legible regardless of text/background color combination."
},
{
"title": "Tabs",
"body": "Normally, new tabs appear at the end of the tab bar. Theres a setting in “Prefs > Advanced” to place them next to your current tab."
},
{
"title": "Base Conversion",
"body": "Right-click on a number and the context menu shows it converted to hex or decimal as appropriate."
},
{
"title": "Saved Searches",
"body": "In “Prefs > Keys” you can assign a keystroke to a search for a regular expression with the “Find Regular Expression…” action."
},
{
"title": "Find URLs",
"body": "Search for URLs using “Edit > Find > Find URLs.” Navigate search results with ⌘G and ⇧⌘G. Open the current selection with ⌥⌘O."
},
{
"title": "Triggers",
"body": "The “instant” checkbox in a Trigger allows it to fire while the cursor is on the same line as the text that matches your regular expression."
},
{
"title": "Soft Boundaries",
"body": "Turn on “Edit > Selection Respects Soft Boundaries” to recognize split pane dividers in programs like vi, emacs, and tmux so you can select multiple lines of text."
},
{
"title": "Select Without Dragging",
"body": "Single click where you want to start a selection and ⇧-click where you want it to end to select text without dragging."
},
{
"title": "Smooth Window Resizing",
"body": "Hold ^ while resizing a window and it wont snap to the character grid: you can make it any size you want."
},
{
"title": "Pasting Tabs",
"body": "If you paste text containing tabs, youll be asked if you want to convert them to spaces. Its handy at the shell prompt to avoid triggering filename completion."
},
{
"title": "Bell Silencing",
"body": "Did you know? If the bell rings too often, youll be asked if youd like to silence it temporarily. iTerm2 cares about your comfort."
},
{
"title": "Profile Search",
"body": "Every list of profiles has a search field (e.g., in ”Prefs > Profiles.”) You can use various operators to restrict your search query. Click “Learn More” for all the details.",
"url": "https://iterm2.com/search_syntax.html"
},
{
"title": "Color Schemes",
"body": "The online color gallery features over one hundred beautiful color schemes you can download.",
"url": "https://www.iterm2.com/colorgallery"
},
{
"title": "ASCII/Non-Ascii Fonts",
"body": "You can have a separate font for ASCII versus non-ASCII text. Enable it in “Prefs > Profiles > Text.”"
},
{
"title": "Coprocesses",
"body": "A coprocess is a job, such as a shell script, that has a special relationship with a particular iTerm2 session. All output in a terminal window (that is, what you see on the screen) is also input to the coprocess. All output from the coprocess acts like text that the user is typing at the keyboard.",
"url": "https://iterm2.com/coprocesses.html"
},
{
"title": "Touch Bar Customization",
"body": "You can customize the touch bar by selecting “View > Customize Touch Bar.” You can add a tab bar for full-screen mode, a user-customizable status button, and you can even define your own touch bar buttons in Prefs > Keys. Theres also a new shell integration tool to customize touch bar function key labels."
},
{
"title": "Ligatures",
"body": "If you use a font that supports ligatures, you can enable ligature support in Prefs > Profiles > Text."
},
{
"title": "Floating Hotkey Window",
"body": "New in 3.1: You can configure your hotkey window to appear over other apps full screen windows. Turn on “Floating Window” in “Prefs > Profiles > Keys > Customize Hotkey Window.”"
},
{
"title": "Multiple Hotkey Windows",
"body": "New in 3.1: You can have multiple hotkey windows. Each profile can have one or more hotkeys."
},
{
"title": "Double-Tap Hotkey",
"body": "New in 3.1: You can configure a hotkey window to open on double-tap of a modifier in “Prefs > Profiles > Keys > Customize Hotkey Window.”"
},
{
"title": "Buried Sessions",
"body": "You can “bury” a session with “Session > Bury Session.” It remains hidden until you restore it by selecting it from “Session > Buried Sessions > Your session.”"
},
{
"title": "Python API",
"body": "You can add custom behavior to iTerm2 using the Python API.",
"url": "https://iterm2.com/python-api"
},
{
"title": "Status Bar",
"body": "You can add a configurable status bar to your terminal windows.",
"url": "https://iterm2.com/3.3/documentation-status-bar.html"
},
{
"title": "Minimal Theme",
"body": "Try the “Minimal” and “Compact” themes to reduce visual clutter. You can set it in “Prefs > Appearance > General.”"
},
{
"title": "Session Titles",
"body": "You can configure which elements are present in session titles in “Prefs > Profiles > General > Title.”"
},
{
"title": "Tab Icons",
"body": "Tabs can show an icon indicating the current application. Configure it in “Prefs > Profiles > General > Icon.”"
},
{
"title": "Drag Window by Tab",
"body": "Hold ⌥ while dragging a tab to move the window. This is useful in the Compact and Minimal themes, which have a very small area for dragging the window."
},
{
"title": "Composer",
"body": "Press ⇧⌘. to open the Composer. It gives you a scratchpad to edit a command before sending it to the shell."
},
{
"title": "Shell Integration: Uploads",
"body": "If you install Shell Integration on a machine you ssh to, you can drag-drop from Finder into the remote host by holding ⌥ while dragging. The destination directory is determined by where you drop the file in the terminal window: run cd foo, then drop the file below the cd command, and the file will go into the foo directory.",
"url": "https://iterm2.com/shell_integration.html"
}
]
home = os.getenv("XDG_DATA_HOME")
if not home:
home = "~"
RCFILE = os.path.expanduser(os.path.join(home, '.it2totd'))
def last_index():
try:
with open(RCFILE) as f:
lines = f.readlines()
return int(lines[0].rstrip())
except:
return -1
def print_tip(i):
def dcs(args):
return "\x1bP" + ";".join(args)
def osc(args):
term = os.getenv("TERM")
if term.startswith("screen"):
return dcs(["tmux", "\x1b\x1b]"]) + ";".join(args) + "\a\x1b\\"
else:
return "\x1b]" + ";".join(args) + "\x1b\\"
tip = tips[i]
print(f'iTerm2 tip - {tip["title"]}:')
print(tip["body"])
if "url" in tip:
print("Learn more: " + osc(["8", "", tip["url"]]) + tip["url"] + osc(["8", "", ""]))
def save_index(i):
with open(RCFILE, "w") as f:
f.write(str(i))
i = last_index() + 1
if i >= len(tips) and len(sys.argv) > 1 and sys.argv[1] == "-w":
i = 0
if i < len(tips):
print_tip(i)
save_index(i)