summaryrefslogtreecommitdiff
path: root/scripts/desktop/sway-ftp-master
blob: 5ac66a2ea7ccc5006c98cfe0cb177b4d1288aceb (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl

# sway-ftp-master -- set up some windows for doing work on Debian's ftp-master
#
# Copyright (C) 2019, 2021 Sean Whitton
#
# GPL-3 or later

use 5.032;
use strict;
use warnings;

use JSON;

sub walk_tree (&$) {
    my ($pred, $tree) = @_;
    $pred->($tree) and return $tree;
    map &walk_tree($pred, $_), $tree->{nodes}->@*, $tree->{floating_nodes}->@*;
}

sub title_exists {
    my $name = shift;
    walk_tree { $_->{name} and $_->{name} eq $name }
    decode_json `swaymsg -t get_tree`;
}

sub marked_exists {
    my $mark = shift;
    walk_tree { grep $_ eq $mark, $_->{marks}->@* }
    decode_json `swaymsg -t get_tree`;
}

sub focus_title { system "swaymsg", qq|[title="$_[0]"]|, "focus" }

sub focus_marked { system "swaymsg", qq|[con_mark="$_[0]"]|, "focus" }

if (marked_exists "dak") {
    focus_marked "dak";
} else {
    # first establish a control socket, so that the two interactive ssh
    # connections don't race to do this and one of them disables multiplexing
    system "ssh", "-fN", "ftp-master.debian.org";

    # start Emacs on ftp-master
    system "ssh", "ftp-master.debian.org", "pgrep", "-u", "spwhitton",
      "emacs", "||", "ssh", "ftp-master.debian.org", "emacs", "--daemon", "&";

    my ($first) = `~/src/dotfiles/scripts/desktop/fresh-workspace`;

    fork // die "couldn't fork"
      or exec "foot", "--override=locked-title=yes",
      "--title=ftp-master dak command session",
      "ssh-and-tmux", "ftp-master.debian.org", "dak";
    sleep 0.3 until marked_exists "dak";
    focus_marked "dak";

    fork // die "couldn't fork"
      or exec "foot", "--override=locked-title=yes",
      "--title=ftp-master GNU mc session",
      "ssh-and-tmux", "ftp-master.debian.org", "mc";
    sleep 0.3 until marked_exists "mc";
    focus_marked "mc";

    system "emacsclient", "-c", "-a", "", "-n", "-e",
      '(progn (switch-to-buffer "*NEW notes*") (text-mode))';
    sleep 0.3 until title_exists "*NEW notes*";
    focus_title "\\*NEW notes\\*";

    # currently we implement only the layout the X11 script chose for melete

    system "swaymsg",
      "move down,",
      "focus up,",
      "focus left,",
      "move right,",
      "move right,",
      "move right,",
      "split v,",
      "layout tabbed,",
      "resize set width 35,",
      "focus left,",
      "split v,",
      "layout tabbed,",
      "resize set height 65,",
      "focus right";
}