Friday, August 8, 2008

My .screenrc

Hello and Welcome to my Blog. This is my first post and I would like to share my .screenrc file with you.
This .screen file is located in my homedir. With this screenrc you can navigate through different tabs by pressing ` (backtick located to the left of 1 on most keyboards) and then the tab you wan to navigate to. Originally you would press ctrl+a and tab you want to navigate to. Use ` (backtick) shift+A to rename your current tab. You can also google for more screen goodies since I don't cover all of them here.

EDIT: If you copy and paste the below text into a file and call it .screenrc you will get errors. You can get the file on pastebin here and paste it into a text editor (nano/pico/vi/vim/gedit/kwrite/kate/etc...)


.screenrc




vbell off
startup_message off
# create a status line at the bottom of the screen. this will show the titles and locations of
# all screen windows you have open at any given time
hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]%{=b C}[ %m/%d %c ]%{W}'
# bind some function keys (k1 == F1, etc) for fast navigation through screen windows
#
#
bindkey -k k2 prev
bindkey -k k3 next
# This changes the default control character (normally ^a) to something else
# (i do this to ease the use of nested screens so command characters dont conflict with each other)
escape `` #"^Ff"
# set the ssh-agent on my workstation to forward my ssh key through my screen windows
#. .keychain/$HOSTNAME-sh
# this will log screen errors to a daily log under the speficied directory
logfile /home/$USER/logs/screen_%y-%m-%d_%0c

screen -t irc /bin/sh -c "if [ $USER != 'root' ]; then irssi -c niven.freenode.net; fi;bash"
screen -t sudoscrn /bin/sh -c "sudo screen -c '/etc/screenrc';bash"
screen -t luser@box /bin/sh -c "ssh luser@box;bash"
screen -t mysql /bin/sh -c "if [ $USER != 'root' ]; then mysql else mysql -u root -p; fi;bash"
screen -t python /bin/sh -c "python"
screen -t bash
screen -t bash
screen -t bash
screen -t arpwatch /bin/sh -c "arpwatch;bash"
screen -t top /bin/sh -c "top;bash"
#shelltitle "$ |bash"

# these last 2 lines are to set the focus on startup (which screen window we look at when screen finishes starting)
focus
select 1



I like to run screen within screen, so I have a seperate screenrc loaded from /etc/screenrc via -c flag

Screen is definitely a life saver when you are working in terminal and need to suddenly close it for some reason.
To list all active screen sessions type: screen -ls
To reattach to a detached session find the the session first with the command above and then type: screen -r ####.pts-#
Note: replace #'s with your session number
To reattach to an already active screen session and have it close where ever it's open and reattach in the current terminal type: screen -raAD
I use this alot. More than screen -r

If you have a KeySpan you can also use screen to connect to serial devices.
If you're connecting to a headless machine with a KeySpan you can just type: screen /dev/ttyUSB0 115200

Note: You may need to change your baud rate and/or parity bit based on the device you connect to.

Or you can just use minicom for this. But I prefer screen more personally.

Enjoy, I hope this helps someone.

No comments: