Tmux can be a pretty complex piece of software, but iTerm can basically wrap it all up into a nice package. You don't need to know anything at all about tmux to use iTerm's tmux integration.
If you're SSHed into a server that has tmux installed, try running `tmux -CC` on the server. It'll pop up a new window that looks and feels just like it's running natively (complete with tab support), except it's all tunneled over SSH.
And if you disconnect, you can just reconnect later and your windows will all come back in the same state as when you left them.
I use this one-liner to SSH into a server and reconnect (or start) a tmux session:
ssh -XY -F user@hostname -Ct \
'sh -l -c "exec tmux -CC -u new-session -AD -s remote"'
iTerm2's tmux integration makes SSH access to remote machines feel almost as native as using your machine locally. It's really a killer feature, and it made iTerm2 worth a donation for me.I’ll give the tmux -CC a go when I’m back at my machine, but what else does the integration do? I’m a heavy pane user - does the default split pane in tmux mode use tmux splitting for example?
Saves a bunch of time!
It checks if the remote has tmux first though:
function ssht() {
/usr/bin/ssh -t "$@" "which tmux 2>&1 > /dev/null && tmux -u -CC new -A -s default"
}
alias ssh=sshtwhy do I get: Can't open user config file <user@host-redacted>: No such file or directory
ssh user@hostname -Ct 'sh -l -c "exec tmux -CC -u new-session -AD -s remote"'pane 1: ssh <server>-1
pane 2: ssh <server>-2
pane 3: ssh <server>-3
pane 4: ssh <server>-4
function cluster_ssh() {
# Start a pane for every server
for server in $*; do
tmux split-window ssh $server
done;
# Same input to all panes
tmux setw synchronize-panes on;
# Init pane to background, tile layout
tmux break-pane -s 0 -d
tmux select-layout tiled
}
bash# cluster_ssh server-{01..10}.example.com
EDIT: made it a bit more complete, but you only need split and sync panes IMHO.It doesn't give you anything if you're already comfortable with tmux. But if you want your experience to "feel" more native, it's an awesome tool.
* imgcat: you can view images without leaving your terminal. Somehow this works even across SSH connections…
* Python scripting API: basically AppleScript for iTerm except it lets you touch pretty much everything and it's not soul-crushing to write. I have mine switch between themes based on the system appearance (which changes based on the time of day).
The source code[1] is quite simple to read (as long as you know Bash) but basically imgcat prints a special OSC[2] sequence (some bytes that tell the terminal to do something special) to stdout followed by the image data which iTerm then handles specially because of the OSC sequence, as far as SSH knows they're just some bytes that it needs to send (no different than running normal cat on a text file). You can kind of think of this as the opposite of what bracketed paste[3] does, in bracketed paste the terminal tells the program to treat some data specially but with imgcat the program tells the terminal to treat some data specially.
[1]: https://iterm2.com/utilities/imgcat
[2]: https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequen...
[3]: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-B...
Also check out tiv[1] which is an alternative that works with any unicode terminal.
Along with imgcat there’s it2dl. Downloads a file from the remote system browser-style. It’s much more convenient than scp, especially when several sessions deep.
-bash: imgcat: command not found
am I missing something? $ curl https://www.iterm2.com/utilities/imgcat > /something/on/your/path/imgcatIt used to be that hackers put their efforts into developing/maintaining tools like this as open source software.
My prompt command: https://github.com/paxswill/dotfiles/blob/c4c6d50123fc2535e2...
And PS0: https://github.com/paxswill/dotfiles/blob/c4c6d50123fc2535e2...
Basically the prompt command writes the current time stamp on the right edge of the window whenever the prompt is printed. Then PS0 overwrites that time stamp right before a command is executed.
If you want the time stamp on the left you can skip the prompt command and tput usage by using the \t escape code in PS1, but PS0 will need to be modified for the new location while still using tput.
https://gitlab.com/gnachman/iterm2/issues/4492
However, you could probably hack together a fix pretty easily with this:
https://github.com/BlueM/cliclick
Make it press cmd-shift-e as a Profile command.
iTerm2 is amazing. I've been using it for years daily and it is 100% one of the best, most reliable pieces of software in my toolkit, right next to Alfred.
Show you love for George and contribute to his Patreon[0]. We always love to complain about how to make money with open source on HN. I'd love to see him making a lot more than he does, if for no other reason than we can get more people working full time on the project and provide some redundancy for a critical tool we all love. I wish I could pay for it, but I guess Patreon works.
For example, I use these kinds of mappings:
nmap <D-j> <C-j>
nmap <D-k> <C-k>
nmap <D-h> <C-h>
nmap <D-l> <C-l>
nmap <C-[> <C-T>
nmap <D-]> <C-]>
nmap <D-[> <C-]>
nmap <D-p> :CtrlP pwd<cr>
nmap <D-r> :CtrlPBufTag<cr>
nmap <D-e> :CtrlPMRUFiles<cr>
This way, when on a Mac I can use cmd in place of ctrl for various commands I use all the time that are less convenient with ctrl.In my .gvimrc, I added the following to make sure that cmd-p and cmd-l don't get incercepted: "Disable the print key for MacVim" if has("gui_macvim") macmenu &File.Print key=<nop> macmenu &Tools.List\ Errors key=<nop> "macmenu &MacVim.Hide\ MacVim key=<nop> set macligatures endif
If there's any possible way to accomplish the same with iTerm, I'd give it another try!
Here's a screenshot http://snid.es/d156c6b7deea
In mine, under profiles/keys, I've set ⌘s to [17~
This is essentially F6, which I then bind in vim to
nnoremap <F6> :w<CR> imap <F6> <Esc>:w<CR>
I do this with a lot of ⌘ or otherwise unbindable settings (again, this only effects iterm2). This is how you can get iterm2 to pick up any keybinding and send it to vim as something else.
Then I went into the tmux rabbit hole, but I never really liked iTerm's integration so I don't use it.
Tmux is kind of like nohup, but for the whole shell. If you SSH into a terminal and start tmux, it'll give you a shell that survives disconnect/reconnect.
Tmux can also act sort-of like a tiling window manager for your shells. So you could have a few shells open, and maybe split your screen 50/50 between two shells, or 50/25/25 or something.
It's a pretty useful program if you spend a lot of your day SSHed into external machines (or if you like to work locally in a full-screen terminal window). It's also got some esoteric keybindings and a steep learning curve and it messes around with your mouse, scrollback, and copy-paste.
iTerm2's tmux integration ignores the disconnect/reconnect stuff (although if you reconnect, your session will just "come back" in whatever state it was when you disconnected). The killer feature is that it takes tmux's window-manager functions and maps them onto tabs and windows in the GUI app. This basically makes it look and feel like you're running iTerm from whatever machine you're logged into over SSH, except that what actually happens under the hood is a bunch of tmux magic.
The functionality I use the most in tmux is:
- attaching and detaching from a tmux session (e.g., for running machine learning jobs over SSH)
- having multiple terminals open inside of one
- scripting the setup of windows, panes, etc. for different projects I'm working on
I basically use vim and tmux as an IDE: my usual setup consists of one large pane consisting of vim and code, while two other panes are available for running git commands, starting servers, etc. Within one tmux session I separate different projects (e.g., frontend and backend) into tmux windows, and it's very easy to switch between panes, windows and sessions using keyboard shortcuts.
* Detach/reattach sessions. This is useful; I run a always connected IRC client on my home machine in a detached session, then reattach to it on the go or from work. Tip: http://enwp.org/Byobu_(software) / http://byobu.co has a vastly better out-of-the-box experience than plain tmux.
* Split screens. I never use it. My GUI terminal emulator software already can do that, but plain tabs or the window manager's features have always been sufficient.
* Connection multiplexing. SSH already does that for me, see `ControlMaster` and `ControlPath` in `man 5 ssh_config`.
It also lets you Command+Drag a path to get a usable file-handle to drop into other apps that handle file-related dropzones.
Demo video I made when I added the feature: https://vimeo.com/21872771
The other one being quicklook (space preview of files)
(Windows due to VS and the rest of MS resources/docs/tools, Linux due to its package management systems natively supporting just about anything you could ever need for development. For macOS to compete, you need a plethora of best-effort or paid tools that don’t come from Apple).
Sounds like you have a specific use case that requires you to use Windows and are projecting that on every other use case. There is a reason why Macs are used in a lot of development shops.
Then for me Cmd+D and Cmd+Shift+D (split with current profile) gives the same current directory.
I want new windows (which I rarely use) and new tabs to be my home directory, but split panes to be the directory I was in when I split. Works wonders.
I have messed with the colors and text rendering for literal hours over the last ten years and I genuinely cannot get it as clear and readable as Terminal.app which is a big part of the reason I always end up falling back to Terminal
You'll see two columns of options. The left column is titled "Basic Colors", the right is titled "ANSI Colors".
Under Basic Colors, click the color next to Foreground, and a color picker appears. Slide it to the lower-left: bright white.
Now it should be fixed. But if it didn't, repeat the same procedure for the White that's at the bottom of the column ANSI Colors.
https://github.com/dandavison/iterm2-dwim
From the README:
iterm2-dwim is a click handler for iTerm2. The aim is that you command-click on any file path, relative or absolute, and it opens the file in your editor. If there was a line number, your editor goes to that line. So, compiler/linter output, tracebacks, git output, etc.
Currently Emacs, PyCharm and Sublime are supported.
There are tons of proprietary escape codes, not least of all the incredibly useful one for "fireworks"! [1]
^[]1337;RequestAttention=fireworks^G
[1]: https://iterm2.com/documentation-escape-codes.html perl -e 'print "\e]1337;RequestAttention=fireworks\007\n"' echo -e "\x1B]1337;RequestAttention=fireworks\007"One thing I've been trying to get working in iTerm2 has been AWS profile badges. iTerm2 has the ability to use text "badges"[0] to give feedback about the current environment. I'm an AWS engineer and tend to switch between environments a lot, so I thought it would be great to use the badges functionality to let me know when I was in the production environment vs. say, the development environment. This seems pretty simple but I haven't been able to get it to work.
I've wondered whether it's possible to setup profile-specific (or folder-specific) aliases? I understand it might be zsh feature that I'm really after, but perhaps iTerm can solve it too?
In your .zshrc (or .bashrc), just use the value of $ITERM_PROFILE to set (or source a file containing) the aliases you want:
[[ $ITERM_PROFILE == “AWS” ]] && source ~/.aliases.aws
https://coderwall.com/p/h6yfda/use-and-to-jump-forwards-back...
`set -o vi` and then hit `<ESC>`. You now have vim motion-like controls to navigate on the command line:
- `b` goes back a word.
- `w` goes forward a word.
- `0` goes to the beginning of the line.
- `$` goes to the end of the line.
etc.
I put `set -o vi` in my rc file so I have it on by default.
You can configure Emacs when running from the terminal to respond to mouse input or to integrate with the system's clipboard. You make it run in server mode, via a Launchd config and you get instant startup times too.
iTerm2 also has built-in powerline glyphs. It was actually easier to configure Emacs's powerline package to work from the terminal than it was to work from the GUI version.
I also like iTerm2's tmux integration.
iTerm2 is one of the reasons why I won't abandon MacOS for my software development needs anytime soon.
I could run /usr/local/bin/hub browse -- commit abc123 without issue, but iTerm wasn't even changing to cursor when hovering over a hash and holding cmd.
Off/on again.
Please consider setting up recurrent donations to George Nachman [2] to support his work.