summaryrefslogtreecommitdiff
path: root/home-manager/features/gui/desktops/niri/parts/selectors.nix
blob: 017314b751d3484ab5b633cf64fc0adb95486987 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
  config,
  pkgs,
  lib,
  ...
}: let
  cfg = config.features.gui.desktops.niri.parts.selectors;
  aes = config.aesthetics;
  defaultTerminal = config.default-applications.terminal-emulator;
in {
  options.features.gui.desktops.niri.parts.selectors.enable = lib.mkEnableOption "selectors";
  config = lib.mkIf cfg.enable {
    home.packages = with pkgs; [
      # Rebuild Loops
      (pkgs.writers.writeNuBin "os-rebuild-loop" ''
        try {nh os switch} ; while true {let continue = input "Rebuild? [Y/n] "; if (($continue | str downcase) == "y" or $continue == "") {try {nh os switch}} else {break}}
      '')
      (pkgs.writers.writeNuBin "home-rebuild-loop" ''
        try {nh home switch} ; while true {let continue = input "Rebuild? [Y/n] "; if (($continue | str downcase) == "y" or $continue == "") {try {nh home switch}} else {break}}
      '')

      # Tool Selector
      (
        pkgs.writers.writeNuBin "tool-selector"
        /*
        nu
        */
        ''
          # Tools
          let tools = {
            "rebuild nixos": {
              # footclient -H sudo nixos-rebuild switch --flake ($"~/Sync/setup#(hostname)" | path expand)
              ${defaultTerminal.runCliCommand} os-rebuild-loop
            }
            "rebuild home": {
              # foot -H home-manager switch --flake ($"~/Sync/setup#(whoami)@(hostname)" | path expand)
              ${defaultTerminal.runCliCommand} home-rebuild-loop
            }
            "update flake": {
              ${defaultTerminal.runCliCommand} nix flake update --flake ($"~/Sync/setup/" | path expand)
            }
            "manage wifi": {
              ${defaultTerminal.runTuiCommand} ${pkgs.impala}/bin/impala
            }
            "manage bluetooth": {
              ${defaultTerminal.runTuiCommand} ${lib.getExe pkgs.bluetui}
            }
            "manage displays": {
              ${lib.getExe wdisplays}
            }
            "create qr-code": {
              let temp_file = mktemp -t
              let qr_code_bin = ${lib.getExe pkgs.qrtool} encode (${pkgs.wl-clipboard}/bin/wl-paste)
              $qr_code_bin | ${pkgs.wl-clipboard}/bin/wl-copy
              $qr_code_bin | save -f $temp_file
              ${lib.getExe pkgs.imv} $temp_file
            }
            "steam big-picture": {
              rm -r ~/.steam
              gamescope -f --backend sdl -- steam -bigpicture
            }
          }

          # Logic
          let user_tool_choice = $tools
            | columns
            | to text
            | fuzzel -d --placeholder "Tools"
          if ($user_tool_choice != "") {
            do ($tools | get $user_tool_choice)
          }

        ''
      )

      # Wallpaper Selector
      (
        writers.writeNuBin "wallpaper-selector"
        /*
        nu
        */
        ''
          def main [
            --all-outputs # Change wallpaper for all outputs
            --randomize
          ] {
            mut wallpapers = {}
            for path in (ls ${aes.wallpapersDir}/**/* | where {|item| $item.type != dir} | get name) {
              $wallpapers = $wallpapers | insert ($path | path basename | split row "." | get 0) $path
            }
            mut prompt = "Wallpaper (current)"
            if $all_outputs {
              $prompt = "Wallpaper (all)"
            }
            mut wallpaper_path = ""
            if $randomize {
              $wallpaper_path = $wallpapers | get (
                $wallpapers
                  | columns
                  | shuffle
                  | get 0
              )
            } else {
              $wallpaper_path = $wallpapers | get (
                $wallpapers
                  | columns
                  | to text
                  | ${lib.getExe pkgs.fuzzel} -d --placeholder $prompt
              )
            }
            if $all_outputs {
              ${lib.getExe pkgs.swww} img $wallpaper_path -t wipe --transition-fps 60 --transition-angle 45
            } else {
              let focused_display = niri msg -j focused-output
                | from json
                | get name
              ${lib.getExe pkgs.swww} img $wallpaper_path -t wipe --transition-fps 60 --transition-angle 45 --outputs $focused_display
            }
          }
        ''
      )

      # Clipboard Selector
      (
        writers.writeNuBin "clipboard-selector" ''
          ${lib.getExe pkgs.cliphist} list
            | cut -f 2-
            | ${lib.getExe pkgs.fuzzel} --dmenu --placeholder "Clipboard"
            | ${pkgs.wl-clipboard}/bin/wl-copy
        ''
      )
    ];
  };
}