2

I am currently using this to launch mutt or irssi:

urxvt -name Irssi/Mutt screen -r Irssi/Mutt

Currently I have to do the following before using my launcher:

screen -S Irssi/Mutt irssi/mutt + Ctrl-a-d

What I am looking to do is:

if [ test_to_see_if_the_screen_exit ]  # I need a way to the test
then
  urxvt -name Irssi/Mutt -e screen -r Irssi/Mutt
else
  create_the_screen_named_Irssi/Mutt_and_detach_it # I need a way to create it
  urxvt -name Irssi/Mutt -e screen -r Irssi/Mutt
endif

Does anyone have a solution?

Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71
Jacob Ilyane
  • 85
  • 1
  • 1
  • 6
  • well it's not an answer, rather suggestion, TMUX is much better than screen. I have used both screen and TMUX, and TMUX is much more user friendly and with many more flexibility – abasu May 16 '13 at 16:10
  • Do you have an example? – Jacob Ilyane May 16 '13 at 16:37
  • I have tmux, and in .bashrc, `alias t='tmux attach || tmux new'` this helps to either attach to an existing session, or create a new one. in a tmux session, you can have multiple windows each running separate program. So just replace `tmux new` with what you want. http://stackoverflow.com/questions/5609192/how-to-set-up-tmux-so-that-it-starts-up-with-specified-windows-opened this link will show you how to do that – abasu May 16 '13 at 16:52
  • That is pretty cool, I will surely try it. – Jacob Ilyane May 17 '13 at 19:49

2 Answers2

1

You can use screen -list | grep Irssi/Mutt to see if your session already exists.

But it's easier to just let screen figure out if the session exists:

screen -r Irssi/Mutt || screen -S Irssi/Mutt irssi/mutt

This will try to attach to an existing session, and create a new one if attaching fails (and you don't need to detach and reattach right away, just stay in the session).

To make urxvt run that, you'll have to specify sh explicitly:

urxvt -name Irssi/Mutt -e sh -c 'screen -r Irssi/Mutt || screen -S Irssi/Mutt irssi/mutt'
Sir Athos
  • 9,403
  • 2
  • 22
  • 23
1

Use screen -list or screen -ls to show your existing screens.

I would probably do your if...endif bit this way, though:

screen_opts=""
case $(screen -list Irssi/Mutt | awk '/Irssi/{print $NF}') in
  *Attached*) ;; # not sure what you would want here,
                 # but I would probably do 'screen_opts="-x"'...
  *Detached*) screen_opts="-r" ;;
  *) screen -wipe # if session is dead, clean it up
     screen_opts="-S Irssi/Mutt";;
esac
urxvt -name Irssi/Mutt -e screen ${screen_opts}
twalberg
  • 59,951
  • 11
  • 89
  • 84