screenie/0000755000000000000000000000000011737514010007621 500000000000000screenie/CHANGELOG0000644000000000000000000000111611737514010010752 00000000000000CHANGELOG ========= April 6th, 2012 (Jiri Nemecek) ------------------------------ FIX: Screenie failed to create jobs with quotes. (patch by Dmitry Smirnov) April 4th, 2012 (Jiri Nemecek) ------------------------------ Use user's default shell by default. (patch by Dmitry Smirnov) February 13th, 2011 (Jiri Nemecek) ---------------------------------- Documentation, manual page and release script. February 6th, 2011 (Jiri Nemecek) --------------------------------- First revision of the script written based on screenie by Marc O. Gloor (http://pubwww.fhzh.ch/~mgloor/screenie.html) screenie/INSTALL0000644000000000000000000000065411737514010010577 00000000000000This script should be fairly cross-system compatible, as almost any UNIX system contain Perl. INSTALLATION ============ Check the 'screenie' script to be executable (e.g. do 'chmod 0755 screenie'). Move the script into e.g. /usr/local/bin or add screenie's directory to PATH. To install the manual just copy manpage 'screenie.1' to your section 1 manpath, e.g. into /usr/local/share/man/man1 . Run 'screenie' on command-line. screenie/LICENCE0000644000000000000000000000021211737514010010521 00000000000000This program is free software but comes WITHOUT ANY WARRANTY. You can redistribute and/or modify it under the same terms as Perl itself. screenie/MD5SUM0000644000000000000000000000040111737514010010431 00000000000000874c95907629acadcf61faf4fffb793a CHANGELOG 33468fa31bb4f65f932fa910ea71cf34 INSTALL 06670559e9e77597e803d8fe3aaf7331 LICENCE 98a2f72f6671debdb9ef3e72512153aa README 2cfd4efc03c7178324d6fb0acf4cfa13 screenie b733b2d5c8777a14e909b71f06925b21 screenie.1 screenie/README0000644000000000000000000000036611737514010010426 00000000000000README ====== Screenie is a small and lightweight screen(1) wrapper designed to simplify session selection on a system with multiple screen sessions. It provides simple interactive menu to select existing screen session or to create a new one. screenie/screenie0000755000000000000000000001110011737514010011255 00000000000000#!/usr/bin/env perl # SCREEN(1) session handler (wrapper) # # Enhanced Perl-reimplementation of 'screenie' by Marc O. Gloor # (http://pubwww.fhzh.ch/~mgloor/screenie.html) # # 2010/02/06 - written by Jiri Nemecek (nemecekjirigmailcom) # # This program is free software but comes WITHOUT ANY WARRANTY. # You can redistribute and/or modify it under the same terms as Perl itself. my $SCREEN = 'screen'; # optionally configure location of screen $0 =~ s{^.*/}{}; if ( @ARGV ) { # non-interactive mode &help() if $ARGV[0] =~ /^-(?:h|-?help)$/; if ( $ARGV[0] eq '-j' ) { my $name = defined $ARGV[1] ? $ARGV[1] : ''; $name =~ tr/ /_/; my $job = $ARGV[2] || ''; my ( $code, $msg ) = &start_session ( $name, $job ); $code ? die "$msg\n" : exit 0; } else { warn 'Unknown parameters: ' . join ( ' ', @ARGV ) . "\n"; &help(); } } else { # interactive mode my ( $sessions, $error_msg, $selection ); while ( 1 ) { $sessions = &get_sessions(); &print_menu ( $sessions, $error_msg ); chomp ( $selection = lc <> ); exit 0 if $selection =~ /^[q0]$/; if ( $selection =~ /^[an]$/ ) { # new session my ( $name, $job ); print "Session name: "; chomp ( $name = <> ); print "Job: "; chomp ( $job = <> ); my ( $code, $msg ) = &start_session ( $name, $job || $ENV{'SHELL'} ); if ( $code ) { $error_msg = $msg; } else { $sessions = &get_sessions(); undef $error_msg; } } elsif ( $selection =~ /^(\d+)([dx])?$/ ) { # session selected my ( $id, $arg, $pid ) = ( $1, lc ( $2 || '' ), 0 ); ( $error_msg = "Incorrect selection: $selection\n" ), next unless $sessions->[$id-1]; $pid = $sessions->[$id-1]->[0]; my ( $code, $msg ) = &attach_session ( $pid, $arg ); $error_msg = $code ? $msg : undef; } else { # incorrect selection $error_msg = "Incorrect selection: $selection\n"; } } sleep 5; } exit 0; sub get_sessions { my @s = (); for ( split "\n", `$SCREEN -ls 2>&1` ) { next unless /^\s*(\d+)\.(.*?)\s+\((?:At|De)tached\)/; push @s, [ $1, $2 ]; } @s = sort { $a->[1] cmp $b->[1] } @s; # sort according to names return \@s; } # Attach session with pid $_[0]; optional arg $_[1] is one of [xd] # as described in menu for 'screen -x' and 'screen -rd' respectively. # Return ( code, message ), where # code - 0 for normal operation, screen exit code for unsuccessful session # resume attempt (session exited in the same second). # message - error message in case of error sub attach_session { my $cmd = "$SCREEN " . ( $_[1] && $_[1] eq 'x' ? '-x ' : $_[1] && $_[1] eq 'd' ? '-rd ' : '-r ' ); my $t0 = time(); my $std = `$cmd $_[0] 2>&1`; if ( $? ) { # non-zero exit status my ( $code, $t ) = ( $? >> 8, time() ); return ( $code, "Failed to attach session with PID $_[0]:\n$std" ) if $t0 == $t; # attachment failure return ( 0, '' ); } } # Return ( code, message ), where # code - 1 for empty session name, screen return code otherwise # message - error message in case of error sub start_session { return [ 1, 'Non-empty session name expected!' ] unless ( defined $_[0] and $_[0] !~ /^\s*$/ ); my $job = defined $_[1] ? $_[1] : ''; my $std = qx{$SCREEN -S "$_[0]" -dm $job 2>&1}; return ( $? >> 8, "Failed to start session: $std" ) if $?; return ( 0, '' ); } # Accepts arrayref parameter of the sessions (returned by get_sessions), # optional second parameter specifies a message to be printed first. sub print_menu { system 'clear' unless system 'which clear >/dev/null 2>&1'; my @scr_lines = (); my ( $maxl, $l ) = ( 0, 0 ); ( $l = length $_->[0] ) > $maxl && ( $maxl = $l ) for @{$_[0]}; for ( 0 .. $#{$_[0]} ) { push @scr_lines, sprintf "%2u) %${maxl}u.%s", $_+1, @{$_[0]->[$_]}[0,1]; } print < - non-interactive mode: create a new session. Licence & Author: Enhanced Perl-reimplementation of 'screenie' by Marc O. Gloor (http://pubwww.fhzh.ch/~mgloor/screenie.html) 2010/02/06 - written by Jiri Nemecek (nemecekjirigmailcom) This program is free software but comes WITHOUT ANY WARRANTY. You can redistribute and/or modify it under the same terms as Perl itself. EOHELP exit 1; } screenie/screenie.10000644000000000000000000000231011737514010011414 00000000000000.Dd Feb 2011 .Dt SCREENIE 1 .Os .Sh NAME .Nm screenie .Nd screen(1) session handler (wrapper) .Sh SYNOPSIS .Nm .Op -h|--help .Op -j Pa session_name Pa job .Sh DESCRIPTION .Nm is a small and lightweight \fBscreen(1)\fR wrapper designed to simplify session selection on a system with multiple screen sessions. .Nm provides simple interactive menu to select the existing screen session or to create a new one. .Sh OPTIONS .Bl -tag -width indent .It Fl h | -help show help .It Fl j Ar session_name job run screen jobs from command-line .El .Sh EXAMPLES Run in interactive mode: .Dl Nm .Pp Create a new detached session: .Dl Nm Fl j Pa stat Pa top .Pp .Sh LICENCE This program is free software but comes \fBWITHOUT ANY WARRANTY\fR. You can redistribute and/or modify it under the same terms as Perl itself. .Sh AUTHOR Written by Jiri Nemecek on February 6th, 2011. You can contact me via mail address nemecekjirigmailcom . This program is enhanced Perl-reimplementation of \fBscreenie\fR by Marc O. Gloor published on http://pubwww.fhzh.ch/~mgloor/screenie.html .Sh URL Released on sourceforge: http://sourceforge.net/projects/screenie .Sh BUGS Please report them in project bugtracker. .Sh "SEE ALSO" .Xr screen 1