Skip to content

Commit

Permalink
Merge pull request #6 from zdykstra/poe
Browse files Browse the repository at this point in the history
Purge on exit
  • Loading branch information
zdykstra authored Mar 28, 2020
2 parents 40e34ee + 85eeb0d commit fa35481
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ If the default option is acceptable, you do not need to define it again in a con
* `on_connect (default[])`: When operating in single-window-mode, define an array of tmux commands to be sent to the cloned session to which you are attached. This option is only executed when `swm` is true.
* `persist (default 10s)`: Set the SSH `ControlPersist` option for control master connections.
* `prettyps (default 1)`: Control the process name on the command line, reducing it to `binaryname session@host`.
* `poe (default none)`: Enable purge-on-exit for `ephemeral` or `all` sessions. This will execute a `kill-session` against the session on exit.
* `reconnect (default 1)`: Attempt to reconnect to the remote host and re-open windows if SSH drops. This is useful for laptops that are suspended frequently.
* `selector (default: rofi -dmenu -i)`: Define the menu command, used for picking a session / session action.
* `skipnw (default 0)`: Do not launch a new terminal when a new window is created in tmux.
Expand Down
32 changes: 31 additions & 1 deletion tmuxc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ GetOptions(
"exitlast|E" => \$cli{exitlast},
"print|o" => \$cli{printOptions},
"swm|w" => \$cli{swm},
"ephemeral|S" => sub {
"poe|P=s" => sub {
( undef, my $scope ) = @_;
unless ( $scope =~ m/(none|ephemeral|any)/ ) {
print "Invalid purge on exit scope: $scope\n";
exit;
} else {
$cli{poe} = $scope;
}
},
"ephemeral|S" => sub {
$cliAction = \&EphemeralSession;
},
"session|s=s" => sub {
Expand Down Expand Up @@ -537,6 +546,19 @@ MAINEND:

END {
exit if $noclean;

if ( ( $config->{poe} eq "any" )
or ( $config->{ephemeral} and $config->{poe} eq "ephemeral" ) )
{
my @cmd = buildCommand( $host, [ $config->{tmux_bin}, qw(kill-session -t), $config->{session}, ] );
Log( LOG_DEBUG, "Killing session $config->{session}" );
qx(@cmd);

@cmd = buildCommand( $host, [ $config->{tmux_bin}, qw(kill-session -t), $config->{control}, ] );
Log( LOG_DEBUG, "Killing control session $config->{control}" );
qx(@cmd);
}

kill 'INT', @children if scalar(@children);
CleanExit;
}
Expand Down Expand Up @@ -577,6 +599,7 @@ sub LoadConfig {
"prettyps" => 1,
"swm" => 0,
"on_connect" => [qw()],
"poe" => "none",
);

# Read in the config file
Expand Down Expand Up @@ -620,6 +643,9 @@ sub LoadConfig {

my $sess = $config->{session};

# Record if this is an ephemeral session
$config->{ephemeral} = ( defined( $config->{hosts}{$chost}{$sess} ) ) ? 0 : 1;

# Look up a number of keys that can be set at different levels
# If no value can be found, use a sane default
foreach my $key ( keys %defaultOptions ) {
Expand Down Expand Up @@ -1512,6 +1538,10 @@ Open up a menu listing sessions from the .tmuxc.conf file that aren't running.
Open up a menu listing control options. If one instance is running, the command is executed on that instance. If multiple are running, prompt the running sessions.
=item B<--poe|P>
Enable purge-on-exit for sessions of type 'none', 'ephemeral' or 'all'. This executes a I<kill-session> against the session on tmuxc exit.
=item B<--singlemenu|M>
Open up a menu listing control options. The options take the form of session@host % <action>, and are shown as a single-depth menu. Smart pagers (rofi, bemenu, etc) allow you to type partial words in any order to narrow down the option to execute.
Expand Down

0 comments on commit fa35481

Please sign in to comment.