photo
Jordan Sissel
geek

Mon, 29 Dec 2003

xterm -e screen? Something better...

I got tired of losing my terminal sessions whenever I decided I needed to restart X for some reason, or one of my assclown dorm-mates decides to ctrl+alt+backspace my X session. So, instead of enabling DontZap in my XF86Config, I figured I would just use screen to compensate. This wasn't enough, seeing as xterm -e screen would just start up a new screen session completely ignoring the current detached ones and thus defeating the purpose of using screen for convenience. Thus, I wrote a two line script to fix this problem:
#!/bin/sh

SESSION=`screen -ls | grep '(Detached)$' | sed -ne '1p' | awk '{print $1}'`
[ -z "$SESSION" ] && screen || screen -x "$SESSION"

What this does is look for the first detached screen session listed by screen -ls and use it to attach to. If there are no currently-detached screen sessions running it'll start up a new one and running your default shell.

Ok, so how is this useful? Put the script above in a file called "attach" and throw it in ~/bin/ (make that directory if you have to). Make sure you chmod 755 ~/bin/attach! Now change the way you open terminals in your windowmanager to:

xterm -e ~/bin/attach [other xterm opts here] 

And you're good to go :)

Comments: 0 (view comments)
Tags:
Permalink: /productivity/97
posted at: 03:14

Search this site

Navigation

Metadata

Home About Resume My Code (SVN)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< December 2003 >
SuMoTuWeThFrSa
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
28293031   

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati