/ modules / home / programs / television.nix
television.nix
  1  {
  2    config,
  3    ...
  4  }:
  5  {
  6    programs.television = {
  7      enable = true;
  8      enableZshIntegration = true;
  9      enableBashIntegration = true;
 10  
 11      settings = {
 12        tick_rate = 50;
 13        default_channel = if config.programs.nix-search-tv.enable then "nix-search-tv" else "files";
 14  
 15        ui = {
 16          ui_scale = 120;
 17          scrollbar = true;
 18          theme = "gruvbox dark";
 19          orientation = "landscape";
 20          use_nerd_font_icons = true;
 21        };
 22  
 23        actions = {
 24          edit = {
 25            mode = "fork";
 26            command = "nvim '{}'";
 27            description = "Open selected file in editor";
 28          };
 29        };
 30  
 31        keybindings = {
 32          ctrl-g = "quit";
 33          alt-x = "toggle_help";
 34          ctrl-enter = "actions:edit";
 35        };
 36      };
 37  
 38      # channels = {
 39      # platformio = {
 40      #   metadata = {
 41      #     name = "pio";
 42      #     description = "PlatformIO CLI";
 43      #     requirements = [
 44      #       "pio"
 45      #       "jq"
 46      #     ];
 47      #   };
 48  
 49      #   ui.preview_panel = {
 50      #     enabled = true;
 51      #     size = 60;
 52      #   };
 53  
 54      #   preview = {
 55      #     header = "{split:\t:2}";
 56      #     command = ''
 57      #       cmd="{split:\t:0}"
 58      #       sub="{split:\t:1}"
 59  
 60      #       if [ "$cmd" = "boards" ]; then
 61      #         pio boards
 62      #         exit 0
 63      #       fi
 64  
 65      #       if [ "$cmd" = "settings" ] && [ "$sub" = "get" ]; then
 66      #         pio settings get
 67      #         exit 0
 68      #       fi
 69  
 70      #       if [ "$cmd" = "device" ] && [ "$sub" = "list-mdns" ]; then
 71      #         pio device list --mdns --json-output \
 72      #           | jq -r '
 73      #               def esc($code): "\u001b[" + $code + "m";
 74      #               def head($s): esc("1;33") + $s + esc("0");
 75      #               def cell($s): esc("0;36") + ($s | tostring) + esc("0");
 76      #               def rpad($n): . + (" " * ($n - length));
 77  
 78      #               (if type == "array" then . else [] end) as $rows_raw
 79      #               | ($rows_raw | map([(.type // ""), (.name // ""), (.ip // ""), (.port // "")])) as $rows
 80      #               | ["Type", "Name", "IP", "Port"] as $hdr
 81      #               | ($rows | map(.[0] | tostring)) as $c0
 82      #               | ($rows | map(.[1] | tostring)) as $c1
 83      #               | ($rows | map(.[2] | tostring)) as $c2
 84      #               | ($rows | map(.[3] | tostring)) as $c3
 85      #               | ($c0 + [$hdr[0]] | map(length) | max? // 0) as $w0
 86      #               | ($c1 + [$hdr[1]] | map(length) | max? // 0) as $w1
 87      #               | ($c2 + [$hdr[2]] | map(length) | max? // 0) as $w2
 88      #               | ($c3 + [$hdr[3]] | map(length) | max? // 0) as $w3
 89      #               | if ($rows | length) == 0 then
 90      #                   head("No devices found")
 91      #                 else
 92      #                   (head($hdr[0] | rpad($w0)) + "  " + head($hdr[1] | rpad($w1)) + "  " + head($hdr[2] | rpad($w2)) + "  " + head($hdr[3] | rpad($w3)))
 93      #                   + "\n"
 94      #                   + ($rows
 95      #                     | map(
 96      #                         cell(.[0] | rpad($w0)) + "  " +
 97      #                         cell(.[1] | rpad($w1)) + "  " +
 98      #                         cell(.[2] | rpad($w2)) + "  " +
 99      #                         cell(.[3] | tostring)
100      #                       )
101      #                     | join("\n")
102      #                   )
103      #                 end
104      #             '
105      #         exit 0
106      #       fi
107  
108      #       if [ "$cmd" = "device" ] && [ "$sub" = "list-serial" ]; then
109      #         pio device list --serial --json-output \
110      #           | jq -r '
111      #               def esc($code): "\u001b[" + $code + "m";
112      #               def head($s): esc("1;33") + $s + esc("0");
113      #               def cell($s): esc("0;36") + ($s | tostring) + esc("0");
114      #               def rpad($n): . + (" " * ($n - length));
115  
116      #               (if type == "array" then . else [] end) as $rows_raw
117      #               | ($rows_raw | map([(.port // ""), (.description // ""), (.hwid // "")])) as $rows
118      #               | ["Port", "Description", "HWID"] as $hdr
119      #               | ($rows | map(.[0] | tostring)) as $c0
120      #               | ($rows | map(.[1] | tostring)) as $c1
121      #               | ($rows | map(.[2] | tostring)) as $c2
122      #               | ($c0 + [$hdr[0]] | map(length) | max? // 0) as $w0
123      #               | ($c1 + [$hdr[1]] | map(length) | max? // 0) as $w1
124      #               | ($c2 + [$hdr[2]] | map(length) | max? // 0) as $w2
125      #               | if ($rows | length) == 0 then
126      #                   head("No devices found")
127      #                 else
128      #                   (head($hdr[0] | rpad($w0)) + "  " + head($hdr[1] | rpad($w1)) + "  " + head($hdr[2] | rpad($w2)))
129      #                   + "\n"
130      #                   + ($rows
131      #                     | map(
132      #                         cell(.[0] | rpad($w0)) + "  " +
133      #                         cell(.[1] | rpad($w1)) + "  " +
134      #                         cell(.[2] | tostring)
135      #                       )
136      #                     | join("\n")
137      #                   )
138      #                 end
139      #             '
140      #         exit 0
141      #       fi
142  
143      #       if [ "$cmd" = "team" ] && [ "$sub" = "list" ]; then
144      #         pio team list --json-output \
145      #           | jq -r '
146      #               def esc($code): "\u001b[" + $code + "m";
147      #               def head($s): esc("1;33") + $s + esc("0");
148      #               def cell($s): esc("0;36") + ($s | tostring) + esc("0");
149      #               def rpad($n): . + (" " * ($n - length));
150  
151      #               (if type == "object" then . else null end) as $root
152      #               | (if $root == null then [] else ($root | to_entries) end) as $orgs
153      #               | [ $orgs[] | .key as $org | (.value // [])[] | [ $org, (.name // ""), ((.members // []) | length | tostring), (.description // "") ] ] as $rows
154      #               | ["Org", "Team", "Members", "Description"] as $hdr
155      #               | ($rows | map(.[0] | tostring)) as $c0
156      #               | ($rows | map(.[1] | tostring)) as $c1
157      #               | ($rows | map(.[2] | tostring)) as $c2
158      #               | ($rows | map(.[3] | tostring)) as $c3
159      #               | ($c0 + [$hdr[0]] | map(length) | max? // 0) as $w0
160      #               | ($c1 + [$hdr[1]] | map(length) | max? // 0) as $w1
161      #               | ($c2 + [$hdr[2]] | map(length) | max? // 0) as $w2
162      #               | ($c3 + [$hdr[3]] | map(length) | max? // 0) as $w3
163      #               | if ($rows | length) == 0 then
164      #                   head("No teams found")
165      #                 else
166      #                   (head($hdr[0] | rpad($w0)) + "  " + head($hdr[1] | rpad($w1)) + "  " + head($hdr[2] | rpad($w2)) + "  " + head($hdr[3] | rpad($w3)))
167      #                   + "\n"
168      #                   + ($rows
169      #                     | map(
170      #                         cell(.[0] | rpad($w0)) + "  " +
171      #                         cell(.[1] | rpad($w1)) + "  " +
172      #                         cell(.[2] | rpad($w2)) + "  " +
173      #                         cell(.[3] | tostring)
174      #                       )
175      #                     | join("\n")
176      #                   )
177      #                 end
178      #             '
179      #         exit 0
180      #       fi
181  
182      #       pio "$cmd" "$sub" --json-output \
183      #         | jq -r '
184      #             def esc($code): "\u001b[" + $code + "m";
185      #             def title($s): esc("1;33") + $s + esc("0");
186      #             def value($s): esc("0;36") + ($s | tostring) + esc("0");
187      #             def value_green($s): esc("0;32") + ($s | tostring) + esc("0");
188      #             def section($s): esc("1;35") + $s + esc("0");
189      #             def rpad($n): . + (" " * ($n - length));
190      #             def row($t; $v; $w): title($t | rpad($w)) + "  " + value($v);
191      #             def row_pair($pair; $w): row($pair[0]; $pair[1]; $w);
192  
193      #             if (has("profile") and has("packages")) then
194      #               . as $root
195      #               | ($root.profile) as $profile
196      #               | [
197      #                   ["Username", ($profile.username // "")],
198      #                   ["Email", ($profile.email // "")],
199      #                   [
200      #                     "Name",
201      #                     ([ $profile.firstname, $profile.lastname ]
202      #                       | map(select(. != null and . != ""))
203      #                       | join(" "))
204      #                   ]
205      #                 ] as $profile_rows
206      #               | [
207      #                   ["User ID", ($root.user_id // "")],
208      #                   [
209      #                     "Expires",
210      #                     (if ($root.expire_at | type) == "number" then
211      #                       ($root.expire_at | strftime("%Y-%m-%d"))
212      #                     else
213      #                       ($root.expire_at // "")
214      #                     end)
215      #                   ]
216      #                 ] as $meta_rows
217      #               | ($profile_rows + $meta_rows | map(.[0] | length) | max? // 0) as $w
218      #               | ($root.packages // []) as $packages
219      #               | ($packages | map((.title // .name // "Package") | length) | max? // 0) as $pw
220      #               | (
221      #                   section("Profile")
222      #                   + "\n"
223      #                   + ($profile_rows | map(row_pair(. ; $w)) | join("\n"))
224      #                   + "\n\n"
225      #                   + section("Packages")
226      #                   + "\n"
227      #                   + (
228      #                       if ($packages | length) == 0 then
229      #                         row("Packages"; "None"; $w)
230      #                       else
231      #                         ($packages
232      #                           | map([ (.title // .name // "Package"), (.description // "") ])
233      #                           | map(title(.[0] | rpad($pw)) + "  " + value_green(.[1]))
234      #                           | join("\n")
235      #                         )
236      #                       end
237      #                     )
238      #                   + "\n\n"
239      #                   + section("Meta")
240      #                   + "\n"
241      #                   + ($meta_rows | map(row_pair(. ; $w)) | join("\n"))
242      #                 )
243      #             else
244      #               . as $root
245      #               | ($root | to_entries | map(.value.title | length) | max? // 0) as $w
246      #               | $root
247      #               | to_entries[]
248      #               | row(.value.title; .value.value; $w)
249      #             end
250      #           '
251      #     '';
252  
253      #     source = {
254      #       ansi = false;
255      #       display = "{split:\t:2}";
256      #       output = "{split:\t:0} {split:\t:1}";
257      #       command = ''
258      #         printf "system\tinfo\tsystem info\n"
259      #         printf "account\tshow\taccount show\n"
260      #         printf "team\tlist\tteam list\n"
261      #         printf "device\tlist-mdns\tdevice list mdns\n"
262      #         printf "device\tlist-serial\tdevice list serial\n"
263      #         printf "settings\tget\tsettings get\n"
264      #         printf "boards\t\tboards\n"
265      #       '';
266      #     };
267      #   };
268      # };
269      # };
270    };
271  }