Tmux has forever changed the way I write code [video]
youtube.com
youtube.com
I can have my code in pane 0 and my code console running a shell in pane 1, and simply use the send-keys command to execute the selected code (or line) instantly in pane 1.
I use this command more than 100 times per day.
I could have a rails console running below in a pane and send rails code directly from the file above.
Works with anything
Sorry, I don't get it. How can you only run selected code or lines individually without the full context of the program/project that code is part of?
Not a LISPer but apparently in that land you could actually have the program running and a REPL attached to it, in which case, you actually do have all the program at your disposal.
IIRC the docs said there were some edge cases, but I never ran into those.
In Python sometimes you can feed back the results of a function into some other function (when you are in the interactive shell), but usually they are nothing like Python code...
Now imagine instead of a empty rails shell, I had my server running there and I can set breakpoints. Or why not both a shell and a server?
I'm using this to send what's copied into the clipboard to the other target:
bind r run 'xsel -bo | tmux load-buffer -; tmux paste-buffer -t .+'Hear about `tmux` here and there, but so far not sure about the benefits. Any particular reason it's better over `screen` ?
https://www.gnu.org/software/screen/manual/screen.html#Regio...
tmux handles changing terminal sizes better than screen does. The config language is much easier to read and write. The status line looks a little nicer.
screen knowledge is still valuable as it is more commonly installed
If you use it heavily, then you may be hitting limitations and it would be worth experimenting with.
I find that I do most of the tmux-like things with multiple iterm windows instead, but I’m a lousy mouser.
Overview from the guide:
When you run "tmux -CC", a new tmux session is created. An iTerm2 window opens and it acts like a normal iTerm2 window. The difference is that when iTerm2 quits or the ssh session is lost, tmux keeps running. You can return to the host you were ssh'ed into and run "tmux -CC attach" and the iTerm2 windows will reopen in the same state they were in before.
It works with multiple panes, windows, etc. Worth trying out!Later, I switched to `byobu`, which started out as a wrapper around `screen` by Dustin Kirkland (of Ubuntu). At some point `byobu` switched to wrapping `tmux` to fix some corner cases/bugs, and it now prompts on first run whether or not you want `screen`-like ctrl-a behavior. https://linux.die.net/man/1/byobu-ctrl-a
The biggest complaints with screen is that the source code is a disaster, and it’s slow with lots of windows, and has put mouse support.
Tmux is very configurable, I used screen from 2005 until 2017 when I went all in on Tmux. My muscle memory couldn’t adapt though. So not all my Tmux bindings match screen.
The one thing kitty can't do, however, is have a remote session that keeps your workspace intact. I, and many other devs, purposely disconnect our development from any given machine we're on.
The majority of reboots or other disruptive behavior is because of desktop machines (for those of us that don't use Linux as our primary and only desktop OS); running the tmux session off another machine (even if its just a headless machine under our desk) minimizes disruption due to GPU/etc bullshit.
I will find out more info and come back.
If you use multiple OSs, tmux offers a consistency that paned terminals cannot offer.
wezterm seems actually legit, I didn't knew it. Thanks!
I went from gnome-terminal, konsole, multiple remote ssh sessions (tmux on the remote side for long running sporadic jobs like repairing databases), Windows Terminal, iterm, iterm2, kitty, putty, etc etc etc. From ancient Ubuntu (from CD-ROM giveaway era), to modern MacOS releases, from several Windows releases.
Happy camper of wezterm for the last 6 months. Alacritty as secondary, Windows Terminal on my gaming machine (wsl2 for some stuff).
Between them: still the same tmux config, just evolving, changing plugins, colors of the status pane, adding starship.rs to the mix. Very tempted to try zellij harder, but not sticking to any of these terminal interfaces provided me lots of flexibility and consistency.
[0] https://mbork.pl/2022-01-10_Simple_tmux_scripting_revisited
Since I work across actual Linux and WSL I really appreciate having something that's terminal agnostic like tmux since it means I don't have to have a separate set up when kitty isn't available.
I have always gone back to vim and tmux for everything I do.
Besides being able to SSH into a session, what does tmux really have to offer me, from people who use it?
Does it need to do anything other than that? I simply can't imagine not having that feature. The way I use computers would have to fundamentally and radically change.
I have long-running sessions on a personal server which I can access from any computer or mobile device I own, seamlessly. I can start compiling, put away the laptop, go do something, and come back to the complete job later. I can check the progress on my phone.
But, I don't actually bother with tmux on the laptop. You're right that the tiling features are not essential on their own (but do become useful in the context of a remote session).
I was hoping for some other awesome use cases of tmux, because I really want a reason to use it.
The pane thing looks nice until you start to use it. There is typically not enough space on the screen to have all useful information visible and then it's simply distracting.
I prefer to use multiple monitors and have terminals on fullscreen. I understand it's not always viable (space, cost etc.) then I still prefer to switch between fullscreen windows than use panes.
The same with code editor. I tried to split windows e.g. to see code side by side, but even if you have your code limited to 80 columns, you may still not be able to see the whole lines, so in the end it's just more faff.
If you switch full windows you can also train your short term memory, as you need to remember the context more and you can focus more.
But each to their own...
My tmux setup looks like this: one session - bunch of windows for different purposes (for example, developing different projects), no more than 10 so you can switch between them with digit shortcuts, renamed for convenience - each window may have several panes, usually one is maximized but you can "unmaximize" it and look what was printed in other panes before (so one usage of pane is a temporary buffer for output) or run something there.
I have always thought it was super sexy to have all these panes available with an editor, logs, debugger opened at the same time ; but the reality is that I cannot work with 20 characters columns.
I use a 4k display set to HiDPI (1080 lines) and simply switch between my full-screen panes.
Sometimes I will split my tmux window vertically because I can deal with fewer lines but I never split horizontally.
Most of the time I have two panes open (side-by-side, splitting the screen vertically). This is plenty of space on 23" monitor, and it even feels somewhat empty on 27". Sometimes I hide another plane (C-b z), especially if I need to switch into character mode and copy the contents of the terminal window. Another case when I need to hide other panes is when I need to read logs from journald and some of those have very long lines, and It's just very uncomfortable to have to move the pager left and right.
I also usually have 3-5 windows open. Eg. because I'm logged in as different users (so, I also rename the windows to help remember that).
Ultimately though, two panes is the way to have the editor open in one pane and something that the code written in the editor affects in the other. For example: one pane has Helm charts, another pane has kubectl running with some pre-configured environment and deploying / removing those charts. Or debugging a Python program, where in one pane I have the source and in another I'm running the program and giving instructions to the debugger. So, eg. once the debugger prints the location in the source it's at, you copy it and navigate to that location in another pane to examine the broader context.
> if you have your code limited to 80 columns, you may still not be able to see the whole lines
Are you like on a 13" laptop or something? If that's your working condition, it sucks for you anyways. It's just not a comfortable working environment. You can find a second-hand 23" monitor for a few bucks, sometimes nothing -- people might give it away as long as you collect it from them. And you don't need any super characteristic for programming... so, why not invest a little bit and make your life more comfortable?
I'm on a 4K 27" monitor, and I can easily squeeze two columns of code, each 120 characters long, and still have room for my project structure view. If I limited my code to 80 characters per line, I could fit 3 vertical columns.
My biggest annoyance is that vim doesn't really support multi process setups, but this can be somewhat fixed by opening vim in read-only mode by default (it won't complain about swap files).
There are some more configurations that I had to make, specifically for copying and pasting, but I should probably spend more time to code better integration (I would love it if Emacs could put things in tmux clipboard, so that I only use one paste command, similarly, I'd like that in tmux buffers all copying would put things in tmux clipboard instead of Emacs / terminal / tmux).
The reason for me to do it is that I have to work with my allocated resources in our datacenter, and I want to keep my workspace intact between the times I disconnect from it. Also, it's sometimes easier to work with an editor local to the filesystem where I need to edit the file vs using Tramp (esp. if the files are large). So, I typically go for vi in tmux (inside Emacs) when I need to edit something remotely. Even viewing long logs with Tramp isn't a great experience.
autossh is basically a wrapper script to keep a session established by reconnecting
mux () {
sessions=$(tmux list-sessions)
if echo $sessions | grep -q -P '^main:'
then
session_id=$$
tmux new-session -t main -s $session_id -d
if [ "z$1" != "z" ]
then
window=$(tmux new-window -d -P -- $@)
fi
tmux attach-session -t $session_id \; set-option destroy-unattached on \; select-window -t "$window"
else
tmux new-session -A -s main $@
fi
}
+ rofi (I know, heresy, choosing tmux session via X tool) attached to C-b s to search within window listI don't really use tmux for window/pane management, I have a window manager and my terminal emulator has panes and tabs. Each autossh session gets its own tmux session on the remote side.
Only one issue I had is that compared to screen default shortcuts are absolutely fucking awful for doing any kind of useful work so I had to remap most of them.
You can edit the code locally and deploy via ssh. Or you can edit the code via ssh; or you can run the entire IDE remotely via ssh.
It seems to me that it's not a huge win in productivity; like, it's not like it's something that's going to make me 10x more productive. I spend more time thinking about the problem than writing code, for non-trivial problems. And even when I write code, it seems that using emacs or this tmux setup wouldn't be a huge win. Even if that saved time adds up, a bunch of hours at the end of the year is not going to make a huge difference definitely not something that's going to fundamentally alter my career.
Chasing the perfect productive setup is a big sophisticated procrastination trap.
But tmux does bring in value. The fact it makes it possible to keep a remote session running even when you lose connectivity is worth learning at least 5% of that tool.
Different people have different preferences.
Do you take the same stance when your browser does the same? Have you disabled JS and embraced the digital amish lifestyle?
Yes, I do turn off JS in my browser.
I think a major problem in software development right now is the mindset you have. I want software that just does what it needs to and has as small of a footprint as it can to do that. I avoid topheavy software.
* look through menu items * click something * everything is frozen for 5 seconds, fan start whirring.
Yeah I know. Junk my computer, get a new one, I'll pass.