aboutsummaryrefslogtreecommitdiff
path: root/gui/pkgs/uictrl.nix
blob: c85e2bcc9ab9bb28f2a3a331423c0a002c43bfe8 (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
{ stdenv, pkgs, ... }:

pkgs.writeTextFile {
  name        = "uictrl";
  executable  = true;
  destination = "/bin/uictrl";

  text = with pkgs; ''
    #!${fish}/bin/fish

    function cycle
        set nsp_ws     (${wmctrl}/bin/wmctrl -d | awk '{if ($9 == "NSP") {print $1}}')
        set current_ws (${wmctrl}/bin/wmctrl -d | awk '{if ($2 == "*")   {print $1}}')

        ${wmctrl}/bin/wmctrl -l | awk -v current_ws=$current_ws -v nsp_ws=$nsp_ws '{if ($2 > current_ws && $2 != nsp_ws) {print $2}}' | uniq
        ${wmctrl}/bin/wmctrl -l | awk -v current_ws=$current_ws -v nsp_ws=$nsp_ws '{if ($2 < current_ws && $2 != nsp_ws) {print $2}}' | uniq
    end

    switch $argv[1]
        case next
            ${wmctrl}/bin/wmctrl -s (cycle)[1]
        case prev
            ${wmctrl}/bin/wmctrl -s (cycle | tac)[1]
    end
  '';
}