Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So I am a big fan of the multiplexers like GNU Screen and Tmux, but even using Screen for years now I still recognize that there are many things there I don't know (and I only use Tmux for a couple of months so its worse).

What configs and tips and tricks you use on those software (both or on each one, doesn't matter)?

I use this as my screen config (I think I adapted this from Ubuntu's default screenrc):

shell -$SHELL
startup_message off
defscrollback 1000
hardstatus alwayslastline '%{= wk}%?%-Lw%?%{r}(%{k}%n*%f%t%?(%u)%?%{r})%{k}%?%+Lw%?%?%= %m/%d %C%A'
activity ''
termcapinfo xterm* 'hs:ts=\\E]2;:fs=\\007:ds=\\E]2;screen\\007'

It's a simple config to keep the status bar showing with some colors, but I am sure that there are more things I can do with screen and Tmux and would love to know it.

share|improve this question
    
zombie qr keeps window open even if process is dead and allows q to close it or r to resurrect process. Useful for software verification. –  Ency May 2 '11 at 19:44
add comment

4 Answers 4

This may be a bit simple for this crowd, but I found it useful to add this to the end of .profile, so that when I log in remotely via ssh, I get to read the MOTD, then switch to screen.

if [ -n "$SSH_TTY" ]
then
        read -p "Press <ENTER> to continue." enterkey
        exec /usr/bin/screen -D -R
fi
share|improve this answer
add comment

I have this in my .bashrc. If you're not running screen this function just calls ssh as usual when executed. If you are running inside screen (and you haven't changed the default $TERM) it first sets the window name to the remote host (together with any optional parameters). It's very handy to keep track of remote connections when you have many open, which is frequent in our line of work I think.

function ssh () {
if [ $TERM = "screen-bce" ]
    then
    screen -X title "$*" 
    /usr/bin/ssh $*
else
    /usr/bin/ssh $*
fi
}

I also use bind ^A windowlist -b for easy access to the window list (just tap ctrl-A twice).

Easy ssh-agent support for all windows:

setenv SSH_AUTH_SOCK $HOME/.screen-ssh-agent
screen 10 ssh-agent -a $SSH_AUTH_SOCK $SHELL

Then in any window you do ssh-add just once when you start a new session.

Finally, when attaching to a remote screen session from within another screen session, you can use screen -x -e ^Vv to set the control sequence to CTRL-V (for example). This avoids having to chain CTRL-As to control the remote session.

share|improve this answer
add comment

You might consider byobu, which is essentially a collection of hundreds of tips, tricks, configurations, keybindings, status scripts, and best practices oriented around screen and tmux.

share|improve this answer
add comment

Even though I started using tmux for panes, I still use screen to multiplex the windows within. tmux supposedly has this functionality, but swapping panes from one window to another is not intuitive to me, nor can two attached tmux viewers be viewing different windows within the same daemon (screen -x behavior), thus the screen-in-tmux solution. These are two tmux.conf binds that took me the longest to figure out and I use every day.

The first, bind M (ctrl-b shift-M), toggles tmux between mouse pane-picker and mouse highlight/copy. You can still copy/paste in pane-pick mode, but you must hold shift (and if you get into the habit of that, copy/paste in any other application will make you a bit miserable, let me tell you). The macro also makes it visually obvious which mode is currently selected.

bind M set mouse-select-pane \; if '[ "`tmux show -v mouse-select-pane`"= "on" ]' "set status-bg cyan \; set pane-active-border-bg cyan" "set status-bg green \; set pane-active-border-bg default"

The second, bind C-L (ctrl-b ctrl-l), will take any layout of 4 panes and turn it into my preferred layout. Often times, I will find I have hit ctrl-d in a pane I thought was inside screen to close it, but instead there was no screen session and it closed the pane. Since my layout is v-split, h-split, v-split and some resizing, if I accidentally closed any but the last window, it becomes a pain (no pun intended) to close any intermediate panes between the one I need to recreate and the last, then re-create and resize the panes, and finally re-attach any screen sessions I may have had to detach when killing panes. With this macro, I can create a new pane, ctrl-b { (the default bind for swap-pane -U) until it is back in the right order, then hit the macro and everything is back to normal. My preferred layout is not likely the same as yours, so once you have a layout you like, use the list-windows command to get a layout string like the one below.

bind C-L select-layout a18e,155x94,0,0[155x18,0,0,6,155x75,0,19{81x75,0,19,31,73x75,82,19[73x22,82,19,32,73x52,82,42,33]}]

If that's too naive for your taste, there is always tmuxinator for pane management.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.