Getting started with Tmux
linuxize.com
linuxize.com
- The Tao of tmux [0]
- A minimalist guide to tmux [1]
- Benefits of using tmux [2]
- tmux shortcuts & cheatsheet [3]
[0] https://leanpub.com/the-tao-of-tmux/read
[1] https://medium.com/actualize-network/a-minimalist-guide-to-t...
I also made a very succinct cheatsheet for tmux (along with a list of all the other key CLI commands for full stack engs):
https://github.com/nemild/cli_for_full_stack#user-content-tm...
Two years ago I finally changed over and I haven't looked back. At this point, when I encounter something where I only have screen I'm rather annoyed by it - and I've set my tmux key mapping to basically mimic what I've been using screen for the last 20 years.
For me, tmux replaced every single feature that I used in screen. On the other hand, I'd be genuinely happy if it existed on the older OSes I randomly have to frequent, even if it's understandably impossible.
People keep telling me that tmux is better (though I still don't understand why), but I lean heavily on chained bindings and haven't found a solution in tmux.
I have a crazy amount of automatic generating shell commands, so that I basically need bash --login to trigger anyways.
My session has 8 tabs, and one of the tabs (my primary) has 14 sub windows (frames?) showing all kinds of good busy information.
Admittedly, I'd hope to argue that if I keep sessions open that long I'm the problem.
`bind r attach-session -c "#{pane_current_path}"`
All the terminals I open start a new tmux session (left as an exercise to the reader). I change directory to whatever project I'm working on, hit `C-b r` and from then on all panes and and windows in that session will start in the correct directory. Saves me a lot of cd'ing.
https://raw.githubusercontent.com/jakobi/script-archive/mast...
http://cryptonector.com/2007/04/c-shell-pushdpopd-on-steroid...
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
https://github.com/mfarrugi/.dots/blob/master/tmux/.tmux.con...Edit: Added MacOs
I haven't gone so far as to change my default shell to tmux in the terminal emulator I use, for the sole reason that I imagine that I just don't need tmux every single time. In reality, 99% of the time the first thing I do when I restart my computer and open a terminal and run `tmux`, and start setting up my workspaces based on what I've been doing, naming windows, etc.
The top two features I use every day:
- keyboard-only selection + cut & paste between panes (yes, piping to xclip is good, but it's nice when you can just enter the right tmux mode, use emacs/vim keybindings to go up and copy out some text)
- easy/instant resizing and organizing of panes
- naming/breaking/moving/combining panes, to focus my efforts (something as simple as naming a window appropriately focuses my efforts inside that window)
An example of this is working with tools like `kubectl` that generate randomly named components that I have to list out @ the command line and do operations on, most of the time when I watch people deal with this in talks, they have to go and double-click-select or type things out.
Kinda hard to explain, but it’ll make sense if you look at the gh repo.
[It’s always driven my insane how kubernetes names its pods. They still haven’t implemented regex matching - there’s an issue on github related to that that went stale. For now I use a combjnation of selectors and old school unix regexes (awk, grep, etc) when I’m passing around kubectl commands that I need to work rgardless of whether the container has restarted or not]
I just downloaded and installed tmux-fingers with tpm, but it's doing a pretty terrible job of picking up on the right things... I'm assuming i need to put in the predefined regexes that would match pod names/ lines of the get output?
Realistically I suppose it’s only marginally faster than kubectl get po -o name and then manually copying.
For any project I work on frequently I set up aliases that wrap it anyway. As you already know kubectl doesn’t allow regex matching so I just do something like: kubectl delete pod “$(kubectl get po -l app=MY_APP_SELECTOR)”, etc. naturally your deploy needs granular selectors otherwise you need to further pipe to grep or awk
There are plugins for that! tmux-resurrec will restore your sessions on reboot, including directories and env vars. It can use vim and emacs sessions to restore your editors too. And you can also tell it other custom "safe" commands it is allowed to restore, which I use for stuff like repls.
I'm sure it's better now, but I don't keep that much stuff around so I don't think I'm too inefficient in not using it
I have tried to configure bash for better use it (including launching it automatically) but then gave up due to not enough gain. But I never saw a need to configure tmux itself.
I can't say the same about screen. At a minimum, there's an inherent incompatibility between it and emacs.
--------------------------------------------------------------------------------
## Control-^ (usually Control-Shift-6) is traditionally the only key chord not used by emacs
escape ^^^^
## disable all the 1970s era "flow control" operations so I can actually use emacs
defflow off
--------------------------------------------------------------------------------
The first line sets the prefix key to C-M-6 which is not used by emacs. The second turns off the "ctl-f" flow control stuff so emacs gets that chord. I then use emacs itself for all "window" management and terminal multiplexing.
I run urxvt.
I also have custom fixes for rxvt that I've built up over the years, both a custom terminfo file, and fixes for emacs' terminal mapping.
I'm willing to bet your "inherent incompatibility" is a terminfo or similar terminal code interpretation problem.
screen /dev/ttyUSB0 9600
in tmux. But recently I tried to switch to tmux and found a few useful configurations.1) I have alacritty as a terminal so no scrollback and no tabs (yeah there is a scrollback branch, but why duplicate functionality?) So my default setup right now is that alacritty (I use i3 so alacritty is bound to meta+enter) opens with this line (this way only one terminal can be opened and has always the same state)
tmux attach -d -t alacritty || tmux new -s alacritty
So I got scrollback and tabs. Also I added bind-key -n C-t new-window
bind-key -n C-PPage previous-window
bind-key -n C-NPage next-window
to the config so I can use it like any normal terminal with ctrl+t (new tab) and ctrl + pgup/down to switch between them. In theory I could even add shift with (C-S-t), but this somehow doesn't work for me and I found conflicting information on it and some outdated infos so I just stopped looking.The second configuration that I like to use is what everybody uses
2)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
to change the prefix to the sane ctrl+a screen default.Also setting colors is a must for neomutt and co
set -g default-terminal "tmux-256color"
I'm still experimenting with configs for my desktops and servers, but I'm feeling a bit more at home with tmux right now.Oh and for anyone who doesn't know of byobu check it out http://byobu.co/ it's a wrapper around screen and/or tmux and is easy for beginners and a nice change for everybody else.
Also I don't use ctrl+a but the home key so I'm missing nothing.
I now have something on Tmux with https://github.com/tmux-plugins/tmux-continuum .
That's one of the best things about Tmux: there's generally a way to get it to do what you need it to do. Or something close enough.
Currently tmux will adapt the size to the smallest (on each axis) client. This doesn't work well with persistent connections from a phone and PC since they typically have quite different window sizes.
In screen I hit ctrl-a + F to resize to current client and I miss it every time I use tmux.
Unfortunately I still prefer tmux, worth trying out if you haven't!
I don't think it's a reasonable requirement.
It is just an inconvenience, nothing huge, but big enough to obstruct my flow.
[0]: https://www.iterm2.com/documentation-tmux-integration.html
All-together it looks something like this: Open iTerm. autossh -t myRemoteHost "tmux -CC -A"
I especially like prefix + & to kill the whole window, prefix + , to rename window, and prefix + ":break-pane" to split the current pane into a new window.
I use something like the following in my .bashrc:
alias f='tmux attach -dt f || tmux new-session -s f'
That way I can recreate or attach to my usual session(s) without even taking my hands off home row.I think in older versions it was called mouse-mode,
I have no desktop application that performs at this level. So my hat's off to the tmux developers. Like many other great open source tools, it's a critical part of my toolset.
- nest tmuxes (up to three levels, with different prefix keys for each level)
- one tmux session per workspace (git clone, whatever)
- cscope on window zero of any workspace session
- use a CSCOPE_EDITOR that starts $EDITOR in a new, appropriately named tmux window in the same session, and returns control to cscope
- script the setup of my main session> Ctrl+a d
Looks like someone uses 'Ctrl+a' as his personal prefix and forgot to replace it in that part of the blog post ;-)
Background: I use 'Ctrl+a' myself (and hate it that tmux uses Ctrl+b by default).
Yeah, it's two handed but seems to have a nice rhythm to it for me (caps lock is control).
Useful for mobile devices with small screens.
Is there a way to get the count of total tmux sessions being run on any machine, for all users?
I can do "tmux ls" but that only returns for the current user.
Really improves development with cli tools.
I use Ctrl-J. So many C-* keys interfere with Emacs / readline.
I background tasks in the shell seldom enough (because I'm always in screen) that I don't regret ^Z being slightly less convenient. ^O is a fairly unknown but very useful insert-mode binding in vim, but I use emacs these days so I don't notice it being escaped.
Before I used separate escape keys, it was maddening trying to remember how many times to hit ^A to send commands to which nested session.