Make the --workspace optional by defaulting to the focused workspace.
If no option is given, i3-save-tree should default to the currently focused workspace. Specifying both --workspace and --output will still yield an error.
This commit is contained in:
parent
09e4fb716c
commit
d217cddb42
16
i3-save-tree
16
i3-save-tree
|
@ -13,6 +13,7 @@ use POSIX qw(locale_h);
|
||||||
use File::Find;
|
use File::Find;
|
||||||
use File::Basename qw(basename);
|
use File::Basename qw(basename);
|
||||||
use File::Temp qw(tempfile);
|
use File::Temp qw(tempfile);
|
||||||
|
use List::Util qw(first);
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use Pod::Usage;
|
use Pod::Usage;
|
||||||
use AnyEvent::I3;
|
use AnyEvent::I3;
|
||||||
|
@ -41,11 +42,7 @@ my $result = GetOptions(
|
||||||
|
|
||||||
die "Could not parse command line options" unless $result;
|
die "Could not parse command line options" unless $result;
|
||||||
|
|
||||||
if (!defined($workspace) && !defined($output)) {
|
if (defined($workspace) && defined($output)) {
|
||||||
die "One of --workspace or --output need to be specified";
|
|
||||||
}
|
|
||||||
|
|
||||||
unless (defined($workspace) ^ defined($output)) {
|
|
||||||
die "Only one of --workspace or --output can be specified";
|
die "Only one of --workspace or --output can be specified";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +54,15 @@ if (!$i3->connect->recv) {
|
||||||
die "Could not connect to i3";
|
die "Could not connect to i3";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_current_workspace {
|
||||||
|
my $current = first { $_->{focused} } @{$i3->get_workspaces->recv};
|
||||||
|
return $current->{name};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!defined($workspace) && !defined($output)) {
|
||||||
|
$workspace = get_current_workspace();
|
||||||
|
}
|
||||||
|
|
||||||
sub filter_containers {
|
sub filter_containers {
|
||||||
my ($tree, $pred) = @_;
|
my ($tree, $pred) = @_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue