Screen dynamic submenu

Hi all!

I’ve already announced this at IRC, and now I’m posting here :smiley:

I’ve written little perl script that makes dynamic menu with attached and/or deattached screen sessions. So, here we go. First, code you need to enter into your configs:

[code]AddToMenu MyMenu

  • Popup SubMenuScreen

DestroyMenu recreate SubMenuScreen
AddToMenu SubMenuScreen

  • DynamicPopupAction Function BuildScreenMenu

DestroyFunc BuildScreenMenu
AddToFunc BuildScreenMenu

  • I DestroyMenu recreate SubMenuScreen
  • I AddToMenu SubMenuScreen
  • I Piperead ‘echo “$HOME/.fvwm/bin/fvwm-screen-menu.pl”’ [/code]

And now the script:

[code]#!/usr/bin/perl -w
#################################

fvwm-screen-menu.pl

by: jsosic

#################################

use Shell qw(screen grep hostname);

Get list of detached/attached screen sessions and hostname

$s_detached_sessions = screen(’-list | grep Detached’);
$s_attached_sessions = screen(’-list | grep Attached’);
$hostname = hostname(’’);

regexps rule :wink:

$hostname=~s/\s//g;
$s_detached_sessions=~s/()|(|Detached|$hostname|^\s+)//g;
$s_attached_sessions=~s/()|(|Attached|$hostname|^\s+)//g;
$s_detached_sessions=~s/…\n//g;
$s_attached_sessions=~s/…\n//g;

Finally, here’s what we came for.

@ls_detached_sessions = split /\s+/, $s_detached_sessions;
foreach my $session (@ls_detached_sessions){
print " + “$session” Exec exec urxvtc -n screen -e screen -r $session.$hostname \n";
}

put separator if there are detached screens…

if ($s_detached_sessions ne “”){
print " + “” NoP\n";
}

Add some general stuff…

print " + “New Session” Exec exec urxvtc -n screen -e screen \n";
print " + “Reattach first” Exec exec urxvtc -n screen -e screen -d -RR \n";

put separator if there are attached screens…

if ($s_attached_sessions ne “”){
print " + “” NoP\n";
}

Little last minute addition: Attached sessions

@ls_attached_sessions = split /\s+/, $s_attached_sessions;
foreach my $session (@ls_attached_sessions){
print " + “$session” Exec exec urxvtc -n screen -e screen -d $session.$hostname \n";
}
[/code]

Also, don’t forget to chmod +x the script, and pinpoint it correctly in your config.

Happy screen-ing!

And a screenshot:

My dearest sir, you are simply awesome!
I have been trying for some time to do this but failed miserably all the times, thank you very much.

I’m glad that I’ve been able to help :smiley:

I know many of fvwm zealots will appretiate this one, and I wondered how nobody tought of this one earlier, and so I just code it.

Many of Fvwm zealots bow to sacred three: Fvwm, zsh, screen, and I’m one of them :smiley: If I had to drop one of the three, I wouldn’t know which one is less important to me :slight_smile:

They had, of course; just that they hadn’t made it explicitly known.

– Thomas Adam

Too bad I can’t demand patent rights on some ideas I never publicly announced… I would have been millionaire.

Here’s upgraded script - it now fixex bug with named screen sessions, thanx to Llukaz for pointing it out:

[code]#!/usr/bin/perl -w
#################################

fvwm-screen-menu.pl

by: jsosic

#################################

use Shell qw(screen grep hostname);

Get list of detached/attached screen sessions and hostname

$s_detached_sessions = screen(’-list | grep Detached’);
$s_attached_sessions = screen(’-list | grep Attached’);
$hostname = hostname(’’);

regexps rule :wink:

$hostname=~s/\s//g;
$s_detached_sessions=~s/()|(|Detached|$hostname|^\s+)//g;
$s_attached_sessions=~s/()|(|Attached|$hostname|^\s+)//g;
$s_detached_sessions=~s/^[0-9]{2,6}.//g;
$s_attached_sessions=~s/^[0-9]{2,6}.//g;
$s_detached_sessions=~s/…\n//g;
$s_attached_sessions=~s/…\n//g;

Finally, here’s what we came for.

@ls_detached_sessions = split /\s+/, $s_detached_sessions;
foreach my $session (@ls_detached_sessions){
print " + “$session” Exec exec urxvtc -n screen -e screen -r $session \n";
}

put separator if there are detached screens…

if ($s_detached_sessions ne “”){
print " + “” NoP\n";
}

Add some general stuff…

print " + “New Session” Exec exec urxvtc -n screen -e screen \n";
print " + “Reattach first” Exec exec urxvtc -n screen -e screen -d -RR \n";

put separator if there are attached screens…

if ($s_attached_sessions ne “”){
print " + “” NoP\n";
}

Little last minute addition: Attached sessions

@ls_attached_sessions = split /\s+/, $s_attached_sessions;
foreach my $session (@ls_attached_sessions){
print " + “$session” Exec exec urxvtc -n screen -e screen -d $session \n";
}
[/code]