mirror of
https://github.com/duncs/clusterssh.git
synced 2025-07-03 18:03:23 +00:00
Add config to allow terminals to run in given dir
Add in terminal_chdir and terminal_chdir_path so that when terminals start they are run in a specific directory. Documentation to be added. Github issue #42
This commit is contained in:
parent
3fcc001cca
commit
ffe6a9d283
6 changed files with 110 additions and 32 deletions
1
Build.PL
1
Build.PL
|
@ -87,6 +87,7 @@ my $build = $class->new(
|
||||||
'Exception::Class' => '1.31',
|
'Exception::Class' => '1.31',
|
||||||
'Try::Tiny' => 0,
|
'Try::Tiny' => 0,
|
||||||
'Getopt::Long' => 0,
|
'Getopt::Long' => 0,
|
||||||
|
'File::Path' => 0,
|
||||||
},
|
},
|
||||||
build_requires => {
|
build_requires => {
|
||||||
'Test::Pod::Coverage' => 0,
|
'Test::Pod::Coverage' => 0,
|
||||||
|
|
1
Changes
1
Changes
|
@ -1,5 +1,6 @@
|
||||||
4.04_01 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
4.04_01 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
||||||
- Ensure documentation is generated using same perl as the build (Github issue #45)
|
- Ensure documentation is generated using same perl as the build (Github issue #45)
|
||||||
|
- New config file settings to allow terminals to run from different directories (Github issue #42)
|
||||||
|
|
||||||
4.04 2015-11-03 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
4.04 2015-11-03 Duncan Ferguson <duncan_ferguson@user.sf.net>
|
||||||
- Include bash completion script in distribution (Github issue #29)
|
- Include bash completion script in distribution (Github issue #29)
|
||||||
|
|
|
@ -37,6 +37,7 @@ use Net::hostent;
|
||||||
use Sys::Hostname;
|
use Sys::Hostname;
|
||||||
use English;
|
use English;
|
||||||
use Socket;
|
use Socket;
|
||||||
|
use File::Path qw(make_path);
|
||||||
|
|
||||||
# Notes on general order of processing
|
# Notes on general order of processing
|
||||||
#
|
#
|
||||||
|
@ -510,6 +511,38 @@ SWITCH: {
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub substitute_macros {
|
||||||
|
my ( $self, $svr, $text ) = @_;
|
||||||
|
|
||||||
|
return $text unless ( $self->config->{macros_enabled} eq 'yes' );
|
||||||
|
|
||||||
|
{
|
||||||
|
my $macro_servername = $self->config->{macro_servername};
|
||||||
|
( my $servername = $svr ) =~ s/\s+//;
|
||||||
|
$text =~ s!$macro_servername!$servername!xsmg;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $macro_hostname = $self->config->{macro_hostname};
|
||||||
|
my $hostname = $servers{$svr}{givenname};
|
||||||
|
$text =~ s!$macro_hostname!$hostname!xsmg;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $macro_username = $self->config->{macro_username};
|
||||||
|
my $username = $servers{$svr}{username};
|
||||||
|
$text =~ s!$macro_username!$username!xsmg;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $macro_newline = $self->config->{macro_newline};
|
||||||
|
$text =~ s!$macro_newline!$/!xsmg;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $macro_version = $self->config->{macro_version};
|
||||||
|
$text =~ s/$macro_version/$VERSION/xsmg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
sub send_text($@) {
|
sub send_text($@) {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $svr = shift;
|
my $svr = shift;
|
||||||
|
@ -518,34 +551,36 @@ sub send_text($@) {
|
||||||
$self->debug( 2, "servers{$svr}{wid}=$servers{$svr}{wid}" );
|
$self->debug( 2, "servers{$svr}{wid}=$servers{$svr}{wid}" );
|
||||||
$self->debug( 3, "Sending to '$svr' text:$text:" );
|
$self->debug( 3, "Sending to '$svr' text:$text:" );
|
||||||
|
|
||||||
# command macro substitution
|
$text = $self->substitute_macros( $svr, $text );
|
||||||
if ( $self->config->{macros_enabled} eq 'yes' ) {
|
|
||||||
|
|
||||||
# $svr contains a trailing space here, so ensure its stripped off
|
# # command macro substitution
|
||||||
{
|
# if ( $self->config->{macros_enabled} eq 'yes' ) {
|
||||||
my $macro_servername = $self->config->{macro_servername};
|
#
|
||||||
my $servername = $svr;
|
# # $svr contains a trailing space here, so ensure its stripped off
|
||||||
$servername =~ s/\s+//;
|
# {
|
||||||
$text =~ s/$macro_servername/$servername/xsmg;
|
# my $macro_servername = $self->config->{macro_servername};
|
||||||
}
|
# my $servername = $svr;
|
||||||
$text =~ s/%h/hostname()/xsmeg;
|
# $servername =~ s/\s+//;
|
||||||
|
# $text =~ s/$macro_servername/$servername/xsmg;
|
||||||
# use connection username, else default to current username
|
# }
|
||||||
{
|
# $text =~ s/%h/hostname()/xsmeg;
|
||||||
my $macro_username = $self->config->{macro_username};
|
#
|
||||||
my $username = $servers{$svr}{username};
|
# # use connection username, else default to current username
|
||||||
$username ||= getpwuid($UID);
|
# {
|
||||||
$text =~ s/$macro_username/$username/xsmg;
|
# my $macro_username = $self->config->{macro_username};
|
||||||
}
|
# my $username = $servers{$svr}{username};
|
||||||
{
|
# $username ||= getpwuid($UID);
|
||||||
my $macro_newline = $self->config->{macro_newline};
|
# $text =~ s/$macro_username/$username/xsmg;
|
||||||
$text =~ s/$macro_newline/\n/xsmg;
|
# }
|
||||||
}
|
# {
|
||||||
{
|
# my $macro_newline = $self->config->{macro_newline};
|
||||||
my $macro_version = $self->config->{macro_version};
|
# $text =~ s/$macro_newline/\n/xsmg;
|
||||||
$text =~ s/$macro_version/$VERSION/xsmg;
|
# }
|
||||||
}
|
# {
|
||||||
}
|
# my $macro_version = $self->config->{macro_version};
|
||||||
|
# $text =~ s/$macro_version/$VERSION/xsmg;
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
foreach my $char ( split( //, $text ) ) {
|
foreach my $char ( split( //, $text ) ) {
|
||||||
next if ( !defined($char) );
|
next if ( !defined($char) );
|
||||||
|
@ -724,6 +759,28 @@ sub open_client_windows(@) {
|
||||||
# Since this is the child, we can mark any server unresolved without
|
# Since this is the child, we can mark any server unresolved without
|
||||||
# affecting the main program
|
# affecting the main program
|
||||||
$servers{$server}{realname} .= "==" if ( !$realname );
|
$servers{$server}{realname} .= "==" if ( !$realname );
|
||||||
|
|
||||||
|
# If set, use the chdir path
|
||||||
|
if ( $self->config->{terminal_chdir} ) {
|
||||||
|
my $chdir_path = $self->substitute_macros( $server,
|
||||||
|
$self->config->{terminal_chdir_path} );
|
||||||
|
|
||||||
|
if ( !-d $chdir_path ) {
|
||||||
|
$self->debug( 1,
|
||||||
|
"Creating terminal directory path '$chdir_path'" );
|
||||||
|
make_path($chdir_path)
|
||||||
|
|| $self->debug( 0,
|
||||||
|
"WARNING: Could not create '$chdir_path'" );
|
||||||
|
}
|
||||||
|
$self->debug( 1,
|
||||||
|
"Changing directory to $chdir_path for terminal to $given_server_name"
|
||||||
|
);
|
||||||
|
chdir($chdir_path)
|
||||||
|
|| $self->debug( 0,
|
||||||
|
"WARNING: Could not change directory to '$chdir_path': $!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
my $exec = join( ' ',
|
my $exec = join( ' ',
|
||||||
$self->config->{terminal},
|
$self->config->{terminal},
|
||||||
$color,
|
$color,
|
||||||
|
@ -1681,11 +1738,14 @@ sub key_event {
|
||||||
$self->debug( 3, "matched combo" );
|
$self->debug( 3, "matched combo" );
|
||||||
if ( $event eq "KeyRelease" ) {
|
if ( $event eq "KeyRelease" ) {
|
||||||
$self->debug( 2, "Received hotkey: $hotkey" );
|
$self->debug( 2, "Received hotkey: $hotkey" );
|
||||||
$self->send_text_to_all_servers('%s')
|
$self->send_text_to_all_servers(
|
||||||
|
$self->config->{macro_servername} )
|
||||||
if ( $hotkey eq "key_clientname" );
|
if ( $hotkey eq "key_clientname" );
|
||||||
$self->send_text_to_all_servers('%h')
|
$self->send_text_to_all_servers(
|
||||||
|
$self->config->{macro_hostname} )
|
||||||
if ( $hotkey eq "key_localname" );
|
if ( $hotkey eq "key_localname" );
|
||||||
$self->send_text_to_all_servers('%u')
|
$self->send_text_to_all_servers(
|
||||||
|
$self->config->{macro_username} )
|
||||||
if ( $hotkey eq "key_username" );
|
if ( $hotkey eq "key_username" );
|
||||||
$self->add_host_by_name()
|
$self->add_host_by_name()
|
||||||
if ( $hotkey eq "key_addhost" );
|
if ( $hotkey eq "key_addhost" );
|
||||||
|
@ -2226,6 +2286,8 @@ the code until this time.
|
||||||
|
|
||||||
=item show_history
|
=item show_history
|
||||||
|
|
||||||
|
=item substitute_macros
|
||||||
|
|
||||||
=item terminate_host
|
=item terminate_host
|
||||||
|
|
||||||
=item toggle_active_state
|
=item toggle_active_state
|
||||||
|
|
|
@ -63,6 +63,9 @@ my %default_config = (
|
||||||
terminal_decoration_height => 10,
|
terminal_decoration_height => 10,
|
||||||
terminal_decoration_width => 8,
|
terminal_decoration_width => 8,
|
||||||
|
|
||||||
|
terminal_chdir_path => $ENV{HOME} . '/.clusterssh/work/%s',
|
||||||
|
terminal_chdir => 0,
|
||||||
|
|
||||||
console => 'console',
|
console => 'console',
|
||||||
console_args => '',
|
console_args => '',
|
||||||
rsh => 'rsh',
|
rsh => 'rsh',
|
||||||
|
|
|
@ -63,6 +63,7 @@ sub script {
|
||||||
my \$port=shift;
|
my \$port=shift;
|
||||||
my \$mstr=shift;
|
my \$mstr=shift;
|
||||||
my \$command="$comms $comms_args ";
|
my \$command="$comms $comms_args ";
|
||||||
|
my \$cwd=qx!pwd!;
|
||||||
open(PIPE, ">", \$pipe) or die("Failed to open pipe: \$!\\n");
|
open(PIPE, ">", \$pipe) or die("Failed to open pipe: \$!\\n");
|
||||||
print PIPE "\$\$:\$ENV{WINDOWID}"
|
print PIPE "\$\$:\$ENV{WINDOWID}"
|
||||||
or die("Failed to write to pipe: $!\\n");
|
or die("Failed to write to pipe: $!\\n");
|
||||||
|
@ -99,7 +100,10 @@ sub script {
|
||||||
\$command .= " \\\"$config_command\\\"";
|
\$command .= " \\\"$config_command\\\"";
|
||||||
}
|
}
|
||||||
\$command .= " ; $postcommand";
|
\$command .= " ; $postcommand";
|
||||||
warn("Running:\$command\\n"); # for debug purposes
|
# provide some info for debugging purposes
|
||||||
|
warn("Running: \\n");
|
||||||
|
warn(" pwd: \$cwd"); # already has newline
|
||||||
|
warn(" cmd: \$command\\n");
|
||||||
exec(\$command);
|
exec(\$command);
|
||||||
HERE
|
HERE
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ isa_ok( $config, 'App::ClusterSSH::Config' );
|
||||||
|
|
||||||
Readonly::Hash my %default_config => {
|
Readonly::Hash my %default_config => {
|
||||||
terminal => "xterm",
|
terminal => "xterm",
|
||||||
|
terminal_chdir => 0,
|
||||||
|
terminal_chdir_path => $ENV{HOME} . '/.clusterssh/work/%s',
|
||||||
terminal_args => "",
|
terminal_args => "",
|
||||||
terminal_title_opt => "-T",
|
terminal_title_opt => "-T",
|
||||||
terminal_colorize => 1,
|
terminal_colorize => 1,
|
||||||
|
@ -517,7 +519,10 @@ is( $trap->stderr,
|
||||||
|
|
||||||
note('Checking dump');
|
note('Checking dump');
|
||||||
$config = App::ClusterSSH::Config->new(
|
$config = App::ClusterSSH::Config->new(
|
||||||
send_menu_xml_file => $ENV{HOME} . '/.clusterssh/send_menu' );
|
send_menu_xml_file => $ENV{HOME} . '/.clusterssh/send_menu',
|
||||||
|
terminal_chdir_path => $ENV{HOME} . '/.clusterssh/work/%s',
|
||||||
|
);
|
||||||
|
|
||||||
trap {
|
trap {
|
||||||
$config->dump();
|
$config->dump();
|
||||||
};
|
};
|
||||||
|
@ -569,6 +574,8 @@ terminal=xterm
|
||||||
terminal_allow_send_events=-xrm '*.VT100.allowSendEvents:true'
|
terminal_allow_send_events=-xrm '*.VT100.allowSendEvents:true'
|
||||||
terminal_args=
|
terminal_args=
|
||||||
terminal_bg_style=dark
|
terminal_bg_style=dark
|
||||||
|
terminal_chdir=0
|
||||||
|
terminal_chdir_path=} . $ENV{HOME} . qq{/.clusterssh/work/%s
|
||||||
terminal_colorize=1
|
terminal_colorize=1
|
||||||
terminal_decoration_height=10
|
terminal_decoration_height=10
|
||||||
terminal_decoration_width=8
|
terminal_decoration_width=8
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue