mirror of
https://github.com/duncs/clusterssh.git
synced 2025-07-03 18:03:23 +00:00
Add in config for macro's
Allow for changing macro strings. Also add option in UI to enable/disable macro processing
This commit is contained in:
parent
803a13d7a5
commit
3fa50f0b49
5 changed files with 150 additions and 51 deletions
5
Changes
5
Changes
|
@ -2,9 +2,10 @@
|
||||||
- Fixed macros (%u, %s, %h, %n) not doing multiple replacements
|
- Fixed macros (%u, %s, %h, %n) not doing multiple replacements
|
||||||
- Add in key shortcut for username macro (ALT-u)
|
- Add in key shortcut for username macro (ALT-u)
|
||||||
- Add in key shortcut for local hostname macro (ALT-l)
|
- Add in key shortcut for local hostname macro (ALT-l)
|
||||||
- Fixed a bug with 'show history' key shortcut
|
- Fix a bug with 'show history' key shortcut
|
||||||
- Fixed "uninitialised errors in hash element" bug [clusterssh support-requests:#38]
|
- Fix "uninitialised errors in hash element" bug [clusterssh support-requests:#38]
|
||||||
- Fixed the default cluster not being opened
|
- Fixed the default cluster not being opened
|
||||||
|
- Add in toggle for macros
|
||||||
|
|
||||||
2013-04-16 Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.02_01
|
2013-04-16 Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.02_01
|
||||||
- Refactured file loading code
|
- Refactured file loading code
|
||||||
|
|
37
bin/cssh
37
bin/cssh
|
@ -494,6 +494,24 @@ Default key sequence to retile host windows. See below notes on shortcuts.
|
||||||
Default key sequence to send username to client. See below notes
|
Default key sequence to send username to client. See below notes
|
||||||
on shortcuts.
|
on shortcuts.
|
||||||
|
|
||||||
|
=item macro_servername = %s
|
||||||
|
|
||||||
|
=item macro_hostname = %h
|
||||||
|
|
||||||
|
=item macro_username = %u
|
||||||
|
|
||||||
|
=item macro_newline = %n
|
||||||
|
|
||||||
|
=item macro_version = %v
|
||||||
|
|
||||||
|
Change the replacement macro used when either using a 'Send' menu item, or when
|
||||||
|
pasting text into the main console.
|
||||||
|
|
||||||
|
=item macros_enabled = yes
|
||||||
|
|
||||||
|
Enable or disable macro replacement. Note: this affects pasting into the
|
||||||
|
main console, items on the 'Send' menu and key_clientname, key_localname, key_servername and key_username.
|
||||||
|
|
||||||
=item max_addhost_menu_cluster_items = 6
|
=item max_addhost_menu_cluster_items = 6
|
||||||
|
|
||||||
Maximum number of entries in the 'Add Host' menu cluster list before
|
Maximum number of entries in the 'Add Host' menu cluster list before
|
||||||
|
@ -659,10 +677,25 @@ This (optional) file contains items to populate the send menu. The
|
||||||
default entry could be written as:
|
default entry could be written as:
|
||||||
|
|
||||||
<send_menu>
|
<send_menu>
|
||||||
<menu title="Hostname">
|
<menu title="Use Macros">
|
||||||
|
<toggle/>
|
||||||
|
<accelerator>ALT-p</accelerator>
|
||||||
|
</dmenu>
|
||||||
|
<menu title="Remote Hostname">
|
||||||
<command>%s</command>
|
<command>%s</command>
|
||||||
<accelerator>ALT-n</accelerator>
|
<accelerator>ALT-n</accelerator>
|
||||||
</menu>
|
</menu>
|
||||||
|
<menu title="Local Hostname">
|
||||||
|
<command>%s</command>
|
||||||
|
<accelerator>ALT-l</accelerator>
|
||||||
|
</menu>
|
||||||
|
<menu title="Username">
|
||||||
|
<command>%u</command>
|
||||||
|
<accelerator>ALT-u</accelerator>
|
||||||
|
</menu>
|
||||||
|
<menu title="Test Text">
|
||||||
|
<command>echo "ClusterSSH Version: %v%n</command>
|
||||||
|
</menu>
|
||||||
</send_menu>
|
</send_menu>
|
||||||
|
|
||||||
Submenus can also be specified as follows:
|
Submenus can also be specified as follows:
|
||||||
|
@ -689,7 +722,7 @@ B<Caveats:>
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
The following replacement macros are available:
|
The following replacement macros are available (note: these can be changed in the configuration file):
|
||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
|
|
|
@ -388,9 +388,6 @@ sub resolve_names(@) {
|
||||||
my ( $self, @servers ) = @_;
|
my ( $self, @servers ) = @_;
|
||||||
logmsg( 2, 'Resolving cluster names: started' );
|
logmsg( 2, 'Resolving cluster names: started' );
|
||||||
|
|
||||||
use Data::Dump qw(dump);
|
|
||||||
warn dump \@servers;
|
|
||||||
|
|
||||||
foreach (@servers) {
|
foreach (@servers) {
|
||||||
my $dirty = $_;
|
my $dirty = $_;
|
||||||
my $username = q{};
|
my $username = q{};
|
||||||
|
@ -533,6 +530,7 @@ SWITCH: {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub send_text($@) {
|
sub send_text($@) {
|
||||||
|
my $self = shift;
|
||||||
my $svr = shift;
|
my $svr = shift;
|
||||||
my $text = join( "", @_ );
|
my $text = join( "", @_ );
|
||||||
|
|
||||||
|
@ -540,22 +538,33 @@ sub send_text($@) {
|
||||||
logmsg( 3, "Sending to '$svr' text:$text:" );
|
logmsg( 3, "Sending to '$svr' text:$text:" );
|
||||||
|
|
||||||
# command macro substitution
|
# command macro substitution
|
||||||
|
if ( $self->config->{macros_enabled} eq 'yes' ) {
|
||||||
|
|
||||||
# $svr contains a trailing space here, so ensure its stripped off
|
# $svr contains a trailing space here, so ensure its stripped off
|
||||||
{
|
{
|
||||||
|
my $macro_servername = $self->config->{macro_servername};
|
||||||
my $servername = $svr;
|
my $servername = $svr;
|
||||||
$servername =~ s/\s+//;
|
$servername =~ s/\s+//;
|
||||||
$text =~ s/%s/$servername/xsmg;
|
$text =~ s/$macro_servername/$servername/xsmg;
|
||||||
}
|
}
|
||||||
$text =~ s/%h/hostname()/xsmeg;
|
$text =~ s/%h/hostname()/xsmeg;
|
||||||
|
|
||||||
# use connection username, else default to current username
|
# use connection username, else default to current username
|
||||||
{
|
{
|
||||||
|
my $macro_username = $self->config->{macro_username};
|
||||||
my $username = $servers{$svr}{username};
|
my $username = $servers{$svr}{username};
|
||||||
$username ||= getpwuid($UID);
|
$username ||= getpwuid($UID);
|
||||||
$text =~ s/%u/$username/xsmg;
|
$text =~ s/$macro_username/$username/xsmg;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $macro_newline = $self->config->{macro_newline};
|
||||||
|
$text =~ s/$macro_newline/\n/xsmg;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
my $macro_version = $self->config->{macro_version};
|
||||||
|
$text =~ s/$macro_version/$VERSION/xsmg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$text =~ s/%n/\n/xsmg;
|
|
||||||
|
|
||||||
foreach my $char ( split( //, $text ) ) {
|
foreach my $char ( split( //, $text ) ) {
|
||||||
next if ( !defined($char) );
|
next if ( !defined($char) );
|
||||||
|
@ -598,10 +607,11 @@ sub send_text($@) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub send_text_to_all_servers {
|
sub send_text_to_all_servers {
|
||||||
|
my $self = shift;
|
||||||
my $text = join( '', @_ );
|
my $text = join( '', @_ );
|
||||||
|
|
||||||
foreach my $svr ( keys(%servers) ) {
|
foreach my $svr ( keys(%servers) ) {
|
||||||
send_text( $svr, $text )
|
$self->send_text( $svr, $text )
|
||||||
if ( $servers{$svr}{active} == 1 );
|
if ( $servers{$svr}{active} == 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1407,7 +1417,7 @@ sub create_windows() {
|
||||||
|
|
||||||
# now sent it on
|
# now sent it on
|
||||||
foreach my $svr ( keys(%servers) ) {
|
foreach my $svr ( keys(%servers) ) {
|
||||||
send_text( $svr, $paste_text )
|
$self->send_text( $svr, $paste_text )
|
||||||
if ( $servers{$svr}{active} == 1 );
|
if ( $servers{$svr}{active} == 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1616,11 +1626,11 @@ sub key_event {
|
||||||
logmsg( 3, "matched combo" );
|
logmsg( 3, "matched combo" );
|
||||||
if ( $event eq "KeyRelease" ) {
|
if ( $event eq "KeyRelease" ) {
|
||||||
logmsg( 2, "Received hotkey: $hotkey" );
|
logmsg( 2, "Received hotkey: $hotkey" );
|
||||||
send_text_to_all_servers('%s')
|
$self->send_text_to_all_servers('%s')
|
||||||
if ( $hotkey eq "key_clientname" );
|
if ( $hotkey eq "key_clientname" );
|
||||||
send_text_to_all_servers('%h')
|
$self->send_text_to_all_servers('%h')
|
||||||
if ( $hotkey eq "key_localname" );
|
if ( $hotkey eq "key_localname" );
|
||||||
send_text_to_all_servers('%u')
|
$self->send_text_to_all_servers('%u')
|
||||||
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" );
|
||||||
|
@ -1760,16 +1770,27 @@ sub populate_send_menu_entries_from_xml {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $command = undef;
|
|
||||||
my $accelerator = undef;
|
my $accelerator = undef;
|
||||||
if ( $menu_ref->{command} ) {
|
|
||||||
$command = sub {
|
|
||||||
send_text_to_all_servers( $menu_ref->{command}[0] );
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if ( $menu_ref->{accelerator} ) {
|
if ( $menu_ref->{accelerator} ) {
|
||||||
$accelerator = $menu_ref->{accelerator};
|
$accelerator = $menu_ref->{accelerator};
|
||||||
}
|
}
|
||||||
|
if ( $menu_ref->{toggle} ) {
|
||||||
|
$menus{send}->checkbutton(
|
||||||
|
-label => 'Use Macros',
|
||||||
|
-variable => \$self->config->{macros_enabled},
|
||||||
|
-offvalue => 'no',
|
||||||
|
-onvalue => 'yes',
|
||||||
|
-accelerator => $accelerator,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $command = undef;
|
||||||
|
if ( $menu_ref->{command} ) {
|
||||||
|
$command = sub {
|
||||||
|
$self->send_text_to_all_servers(
|
||||||
|
$menu_ref->{command}[0] );
|
||||||
|
};
|
||||||
|
}
|
||||||
$menu->command(
|
$menu->command(
|
||||||
-label => $menu_ref->{title},
|
-label => $menu_ref->{title},
|
||||||
-command => $command,
|
-command => $command,
|
||||||
|
@ -1777,6 +1798,7 @@ sub populate_send_menu_entries_from_xml {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -1788,21 +1810,46 @@ sub populate_send_menu {
|
||||||
if ( !-r $self->config->{send_menu_xml_file} ) {
|
if ( !-r $self->config->{send_menu_xml_file} ) {
|
||||||
logmsg( 2, 'Using default send menu' );
|
logmsg( 2, 'Using default send menu' );
|
||||||
|
|
||||||
|
$menus{send}->checkbutton(
|
||||||
|
-label => 'Use Macros',
|
||||||
|
-variable => \$self->config->{macros_enabled},
|
||||||
|
-offvalue => 'no',
|
||||||
|
-onvalue => 'yes',
|
||||||
|
-accelerator => $self->config->{key_macros_enable},
|
||||||
|
);
|
||||||
|
|
||||||
$menus{send}->command(
|
$menus{send}->command(
|
||||||
-label => 'Remote Hostname',
|
-label => 'Remote Hostname',
|
||||||
-command => [ \&send_text_to_all_servers, '%s' ],
|
-command => sub {
|
||||||
|
$self->send_text_to_all_servers(
|
||||||
|
$self->config->{macro_servername} );
|
||||||
|
},
|
||||||
-accelerator => $self->config->{key_clientname},
|
-accelerator => $self->config->{key_clientname},
|
||||||
);
|
);
|
||||||
$menus{send}->command(
|
$menus{send}->command(
|
||||||
-label => 'Local Hostname',
|
-label => 'Local Hostname',
|
||||||
-command => [ \&send_text_to_all_servers, '%h' ],
|
-command => sub {
|
||||||
|
$self->send_text_to_all_servers(
|
||||||
|
$self->config->{macro_hostname} );
|
||||||
|
},
|
||||||
-accelerator => $self->config->{key_localname},
|
-accelerator => $self->config->{key_localname},
|
||||||
);
|
);
|
||||||
$menus{send}->command(
|
$menus{send}->command(
|
||||||
-label => 'Username',
|
-label => 'Username',
|
||||||
-command => [ \&send_text_to_all_servers, '%u' ],
|
-command => sub {
|
||||||
|
$self->send_text_to_all_servers(
|
||||||
|
$self->config->{macro_username} );
|
||||||
|
},
|
||||||
-accelerator => $self->config->{key_username},
|
-accelerator => $self->config->{key_username},
|
||||||
);
|
);
|
||||||
|
$menus{send}->command(
|
||||||
|
-label => 'Test Text',
|
||||||
|
-command => sub {
|
||||||
|
$self->send_text_to_all_servers( 'echo ClusterSSH Version: '
|
||||||
|
. $self->config->{macro_version}
|
||||||
|
. $self->config->{macro_newline} );
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logmsg(
|
logmsg(
|
||||||
|
@ -1951,11 +1998,6 @@ sub run {
|
||||||
|
|
||||||
# = $self->resolve_names( @default );
|
# = $self->resolve_names( @default );
|
||||||
= $self->resolve_names( $self->cluster->get_tag('default') );
|
= $self->resolve_names( $self->cluster->get_tag('default') );
|
||||||
warn "blip";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
warn "blop";
|
|
||||||
warn scalar $self->cluster->get_tag('default');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ my %default_config = (
|
||||||
key_history => "Alt-h",
|
key_history => "Alt-h",
|
||||||
key_localname => "Alt-l",
|
key_localname => "Alt-l",
|
||||||
key_retilehosts => "Alt-r",
|
key_retilehosts => "Alt-r",
|
||||||
|
key_macros_enable => "Alt-p",
|
||||||
key_paste => "Control-v",
|
key_paste => "Control-v",
|
||||||
key_username => "Alt-u",
|
key_username => "Alt-u",
|
||||||
mouse_paste => "Button-2",
|
mouse_paste => "Button-2",
|
||||||
|
@ -82,6 +83,13 @@ my %default_config = (
|
||||||
command => q{},
|
command => q{},
|
||||||
max_host_menu_items => 30,
|
max_host_menu_items => 30,
|
||||||
|
|
||||||
|
macros_enabled => 'yes',
|
||||||
|
macro_servername => '%s',
|
||||||
|
macro_hostname => '%h',
|
||||||
|
macro_username => '%u',
|
||||||
|
macro_newline => '%n',
|
||||||
|
macro_version => '%v',
|
||||||
|
|
||||||
max_addhost_menu_cluster_items => 6,
|
max_addhost_menu_cluster_items => 6,
|
||||||
menu_send_autotearoff => 0,
|
menu_send_autotearoff => 0,
|
||||||
menu_host_autotearoff => 0,
|
menu_host_autotearoff => 0,
|
||||||
|
|
15
t/15config.t
15
t/15config.t
|
@ -38,6 +38,7 @@ Readonly::Hash my %default_config => {
|
||||||
key_history => "Alt-h",
|
key_history => "Alt-h",
|
||||||
key_localname => "Alt-l",
|
key_localname => "Alt-l",
|
||||||
key_retilehosts => "Alt-r",
|
key_retilehosts => "Alt-r",
|
||||||
|
key_macros_enable => "Alt-p",
|
||||||
key_paste => "Control-v",
|
key_paste => "Control-v",
|
||||||
key_username => "Alt-u",
|
key_username => "Alt-u",
|
||||||
mouse_paste => "Button-2",
|
mouse_paste => "Button-2",
|
||||||
|
@ -85,6 +86,13 @@ Readonly::Hash my %default_config => {
|
||||||
comms => q{ssh},
|
comms => q{ssh},
|
||||||
max_host_menu_items => 30,
|
max_host_menu_items => 30,
|
||||||
|
|
||||||
|
macros_enabled => 'yes',
|
||||||
|
macro_servername => '%s',
|
||||||
|
macro_hostname => '%h',
|
||||||
|
macro_username => '%u',
|
||||||
|
macro_newline => '%n',
|
||||||
|
macro_version => '%v',
|
||||||
|
|
||||||
max_addhost_menu_cluster_items => 6,
|
max_addhost_menu_cluster_items => 6,
|
||||||
menu_send_autotearoff => 0,
|
menu_send_autotearoff => 0,
|
||||||
menu_host_autotearoff => 0,
|
menu_host_autotearoff => 0,
|
||||||
|
@ -495,11 +503,18 @@ key_addhost=Control-Shift-plus
|
||||||
key_clientname=Alt-n
|
key_clientname=Alt-n
|
||||||
key_history=Alt-h
|
key_history=Alt-h
|
||||||
key_localname=Alt-l
|
key_localname=Alt-l
|
||||||
|
key_macros_enable=Alt-p
|
||||||
key_paste=Control-v
|
key_paste=Control-v
|
||||||
key_quit=Control-q
|
key_quit=Control-q
|
||||||
key_retilehosts=Alt-r
|
key_retilehosts=Alt-r
|
||||||
key_username=Alt-u
|
key_username=Alt-u
|
||||||
lang=en
|
lang=en
|
||||||
|
macro_hostname=%h
|
||||||
|
macro_newline=%n
|
||||||
|
macro_servername=%s
|
||||||
|
macro_username=%u
|
||||||
|
macro_version=%v
|
||||||
|
macros_enabled=yes
|
||||||
max_addhost_menu_cluster_items=6
|
max_addhost_menu_cluster_items=6
|
||||||
max_host_menu_items=30
|
max_host_menu_items=30
|
||||||
menu_host_autotearoff=0
|
menu_host_autotearoff=0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue