Hi. I'm jon.404, a Unix/Linux/Database/Openstack/Kubernetes Administrator, AWS/GCP/Azure Engineer, mathematics enthusiast, and amateur philosopher. This is where I rant about that which upsets me, laugh about that which amuses me, and jabber about that which holds my interest most: *nix.
Scripting tmux made easy
Posted 04-27-2011 at 12:11 PM by rocket357
I recently discovered cwm and fell head over heels for it. Then later I discovered tmux, and suddenly my desktop goals are starting to look ultimately like they're possible. My days of running fluxbox are long gone (though running konsole and scripting it were pretty fun...I can't justify installing KDE for one application =\ ).
Here's my dream: I want a simple, efficient, keyboard-oriented desktop that doesn't take up much resources and allows me to get work done. The work I do is primarily done over ssh, so I have to have some kind of way to keep xterms (or whatever) in order. I have to have a "method to the madness" with these terminals. I couldn't bring myself to install KDE so I could run tabbed konsole in cwm...the mere thought of it segfaults my brain.
I looked at a few ports to see if an alternative was available that sported lower dependency and runtime overhead, and I found a few, but nothing that really caught my attention. Then I found tmux.
Ok, tmux is just like screen with funky keybindings. I'll give you that. It gives the same attach/detach functionality and works with multiple windows/panes. But what's important here is that tmux has one of the side bonuses of cwm...it's in OpenBSD base and is audited.
Ok, so you run Linux. Awesome. You should run screen, because it's basically the same thing as tmux, only your distro probably has it pre-installed. That's great.
But I prefer tmux...it's in base (audited), doesn't require any additional packages or dependencies, and I like the default keybindings.
Alright, so let's try some stuff out with tmux...
First off, we'll run tmux within xterm (again, no extra dependencies/overhead). I'm not *terribly* fond of xterm's default black on white color scheme, so I setup some defaults for the window that's going to run tmux. I put this in my .xinitrc:
xterm -bg black -fg green -aw +cm -cr white -ms white +sb -bc -g 279x80+0+0 -e "tmux attach" &
This starts an xterm with black background, green text, and white cursor, makes it fullscreen on my left monitor, and runs tmux in it. This is a great start, but let's work a bit on tmux, shall we?
In .tmux.conf you can set any tmux commands you want to setup a "default" environment for tmux. I changed a few colors (with green text in xterm, the status bar doesn't stand out, so I changed it to blue, then changed the "active window border" to blue as well so it stands out, too). Aside from that, the commands I have in .tmux.conf are just to create default Windows/panes and populate them with various programs and ssh sessions.
Here's my .tmux.conf:
This leaves me with the left most pane in the right top and right bottom panes open for running commands. Screenshot here.
Here's my dream: I want a simple, efficient, keyboard-oriented desktop that doesn't take up much resources and allows me to get work done. The work I do is primarily done over ssh, so I have to have some kind of way to keep xterms (or whatever) in order. I have to have a "method to the madness" with these terminals. I couldn't bring myself to install KDE so I could run tabbed konsole in cwm...the mere thought of it segfaults my brain.
I looked at a few ports to see if an alternative was available that sported lower dependency and runtime overhead, and I found a few, but nothing that really caught my attention. Then I found tmux.
Ok, tmux is just like screen with funky keybindings. I'll give you that. It gives the same attach/detach functionality and works with multiple windows/panes. But what's important here is that tmux has one of the side bonuses of cwm...it's in OpenBSD base and is audited.
Ok, so you run Linux. Awesome. You should run screen, because it's basically the same thing as tmux, only your distro probably has it pre-installed. That's great.
But I prefer tmux...it's in base (audited), doesn't require any additional packages or dependencies, and I like the default keybindings.
Alright, so let's try some stuff out with tmux...
First off, we'll run tmux within xterm (again, no extra dependencies/overhead). I'm not *terribly* fond of xterm's default black on white color scheme, so I setup some defaults for the window that's going to run tmux. I put this in my .xinitrc:
xterm -bg black -fg green -aw +cm -cr white -ms white +sb -bc -g 279x80+0+0 -e "tmux attach" &
This starts an xterm with black background, green text, and white cursor, makes it fullscreen on my left monitor, and runs tmux in it. This is a great start, but let's work a bit on tmux, shall we?
In .tmux.conf you can set any tmux commands you want to setup a "default" environment for tmux. I changed a few colors (with green text in xterm, the status bar doesn't stand out, so I changed it to blue, then changed the "active window border" to blue as well so it stands out, too). Aside from that, the commands I have in .tmux.conf are just to create default Windows/panes and populate them with various programs and ssh sessions.
Here's my .tmux.conf:
Code:
# setting x and y explicitly because tmux has a default # during startup that makes percentage splits not work # correctly, resulting in panes being sized wrong new -d -swork -x 279 -y 80 # set all of our global options # set the status bar colors/options... set -g status-bg blue set -g status-fg white set -g status-keys vi # set window colors/options... setw -g mode-keys vi setw -g automatic-rename off setw -g pane-active-border-bg blue setw -g pane-active-border-fg white setw -g pane-border-fg white # First Window...let's call it "WORK" renamew -t 0 WORK # pane splits take place from the top and right... # if I splitw -h, it's a horizontal split that causes left/right panes # if I splitw -v, it's a vertical split that causes top/bottom panes # -p splits based on percentage **of the current pane**!! splitw -hp 80 # 80% split...80% on the right and the right is now active selectp -L # select the LEFT pane send su enter # iftop requires root...I'll enter the password manually later selectp -R # back to the RIGHT pane now splitw -vp 32 # split the pane 32% on the bottom. bottom is active. splitw -hp 32 # split the bottom pane 32% on the right. right is active. send mp3blaster enter # well alrighty then...gotta have tunes, yeah? send f1; send f3; send f6; send f7; # being OCD here with mp3blaster selectp -L # back to the LEFT bottom pane splitw -hp 60 # split the pane 60% on the right. right is active (bottom middle) send top enter # I used to run conky...meh. top ftw. send C # "C" for BSD top is the same as "c" for top in Linux selectp -U # now the top pane's turn to be chopped up... splitw -hp 50 # let's split it in two, shall we? send 'ssh skynet' enter # Yeah, that's my main OpenBSD server's name send 'cd /scripts/bin' enter # this works because I have key-based ssh setup
Total Comments 0