summaryrefslogtreecommitdiff
path: root/bin/i3-fresh-workspace
blob: 89a5de489c4e83164230e43964e2c4cfeb993bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl

use strict;
use warnings;

use JSON;
use List::Util "first";

my @all_workspaces = (
    "1",     "2",      "3",      "4",     "5",     "6",
    "7",     "8",      "9",      "10",    "11:F1", "12:F2",
    "13:F3", "14:F4",  "15:F5",  "16:F6", "17:F7", "18:F8",
    "19:F9", "20:F10", "21:F11", "22:F12"
);

my %current_names = map +($_->{name}, undef),
  @{ decode_json `i3-msg -t get_workspaces` };

my $next_free_workspace
  = first { not exists $current_names{$_} } @all_workspaces;

if ($next_free_workspace) {
    if (grep /--send/, @ARGV) {
        # Send it there but don't change focus.  User can use 'move
        # container to workspace back_and_forth' binding to move any
        # other wanted containers over there, before finally switching
        # the view with 'workspace back_and_forth'
        system
	  "i3-msg move container to workspace $next_free_workspace >/dev/null";
    } else {
        system "i3-msg workspace $next_free_workspace >/dev/null";
    }
}

# added for the benefit of ~/src/dotfiles/bin/debian-ftp-master
print "$next_free_workspace\n";