Add in 'command_pre' and 'command_post' configs

This allows for running commands before and after the comms method in
the command pipeline, such as setting up python virtual environments
and piping output through other commands
This commit is contained in:
Duncan Ferguson 2020-04-18 17:05:00 +01:00
parent 7fe7c69769
commit 82f88450d0
6 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,7 @@ Revision history for {{$dist->name}}
4.15 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net> 4.15 0000-00-00 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Include all utilies within each man page - Include all utilies within each man page
- Add in 'command_pre' and 'command_post' configuration options
4.14 2019-08-21 Duncan Ferguson <duncan_ferguson@user.sf.net> 4.14 2019-08-21 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Include README within the repository, not just created tar.gz files - Include README within the repository, not just created tar.gz files

15
README
View file

@ -346,6 +346,21 @@ FILES
Enable or disable alternative algorithm for calculating terminal Enable or disable alternative algorithm for calculating terminal
positioning. positioning.
command_pre =
command_post =
Add extra commands around the communication method. For example:
command_pre= . $HOME/virtualenvs/default/bin/active ;
command_post= | ct
would allow for using Python virtual envronments and then piping
all shell output through "chromaterm" for syntax highlighting.
Note: you must use appropriate command separators/terminators to
keep the meaning of the command pipline (such as ";" and "|"
between commands).
These are not put through macro parsing.
comms = ssh comms = ssh
Sets the default communication method (initially taken from the Sets the default communication method (initially taken from the
name of the program, but can be overridden here). name of the program, but can be overridden here).

View file

@ -98,6 +98,8 @@ my %default_config = (
history_height => 10, history_height => 10,
command => q{}, command => q{},
command_pre => q{},
command_post => q{},
hide_menu => 0, hide_menu => 0,
max_host_menu_items => 30, max_host_menu_items => 30,

View file

@ -700,6 +700,17 @@ would replace the <Alt-n> with the client's name in each window.}
'Enable or disable alternative algorithm for calculating terminal positioning.', 'Enable or disable alternative algorithm for calculating terminal positioning.',
); );
output '=item command_pre =';
output '=item command_post =';
output $self->loc(
q{Add extra commands around the communication method. For example:
command_pre= . $HOME/virtualenvs/default/bin/active ;
command_post= | ct
would allow for using Python virtual envronments and then piping all shell output through C<chromaterm> for syntax highlighting. Note: you must use appropriate command separators/terminators to keep the meaning of the command pipline (such as C<;> and C<|> between commands).
These are not put through macro parsing.});
output '=item comms = ' . $self->parent->config->{comms}; output '=item comms = ' . $self->parent->config->{comms};
output $self->loc( output $self->loc(
'Sets the default communication method (initially taken from the name of the program, but can be overridden here).' 'Sets the default communication method (initially taken from the name of the program, but can be overridden here).'

View file

@ -52,6 +52,8 @@ sub script {
} }
} }
my $command_pre = $config->{command_pre} || q{};
my $command_post = $config->{command_post} || q{};
my $comms = $config->{ $config->{comms} }; my $comms = $config->{ $config->{comms} };
my $comms_args = $config->{ $config->{comms} . '_args' }; my $comms_args = $config->{ $config->{comms} . '_args' };
my $config_command = $config->{command}; my $config_command = $config->{command};
@ -69,7 +71,7 @@ sub script {
my \$user=shift; my \$user=shift;
my \$port=shift; my \$port=shift;
my \$mstr=shift; my \$mstr=shift;
my \$command="$comms $comms_args "; my \$command="$command_pre $comms $comms_args";
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");
@ -105,6 +107,7 @@ sub script {
if("$config_command") { if("$config_command") {
\$command .= " \\\"$config_command\\\""; \$command .= " \\\"$config_command\\\"";
} }
\$command .= "$command_post";
\$command .= " ; $postcommand"; \$command .= " ; $postcommand";
# provide some info for debugging purposes # provide some info for debugging purposes
warn("Running: \$command\\n"); warn("Running: \$command\\n");

View file

@ -102,6 +102,8 @@ Readonly::Hash my %default_config => {
history_height => 10, history_height => 10,
command => q{}, command => q{},
command_pre => q{},
command_post => q{},
title => q{15CONFIG.T}, title => q{15CONFIG.T},
comms => q{ssh}, comms => q{ssh},
hide_menu => 0, hide_menu => 0,
@ -564,6 +566,8 @@ auto_close=5
auto_quit=yes auto_quit=yes
auto_wm_decoration_offsets=no auto_wm_decoration_offsets=no
cols=-1 cols=-1
command_post=
command_pre=
console=console console=console
console_args= console_args=
console_position= console_position=