summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configs/bash/default.nix13
-rw-r--r--pkgs/simple/xextras.nix19
2 files changed, 20 insertions, 12 deletions
diff --git a/configs/bash/default.nix b/configs/bash/default.nix
index 0ec6bf0..70c94da 100644
--- a/configs/bash/default.nix
+++ b/configs/bash/default.nix
@@ -23,18 +23,7 @@
case $UID in
${mylib.shell.escape (toString config.krebs.users.tv.uid)})
if test ''${SHLVL-1} = 1 && test -n "''${DISPLAY-}"; then
- _CURRENT_DESKTOP_NAME=''${_CURRENT_DESKTOP_NAME-$(
- ${pkgs.xorg.xprop}/bin/xprop -notype -root \
- 32i _NET_CURRENT_DESKTOP \
- 8s _NET_DESKTOP_NAMES \
- |
- ${pkgs.gnused}/bin/sed -r 's/.* = //;s/"//g;s/, /\a/g' |
- {
- read -r _NET_CURRENT_DESKTOP
- IFS=$'\a' read -ra _NET_DESKTOP_NAMES
- echo "''${_NET_DESKTOP_NAMES[$_NET_CURRENT_DESKTOP]}"
- }
- )}
+ _CURRENT_DESKTOP_NAME=''${_CURRENT_DESKTOP_NAME-$(${pkgs.xextras}/bin/net-current-desktop)}
case $_CURRENT_DESKTOP_NAME in
hrm)
cd ~/hrm
diff --git a/pkgs/simple/xextras.nix b/pkgs/simple/xextras.nix
new file mode 100644
index 0000000..c9c0308
--- /dev/null
+++ b/pkgs/simple/xextras.nix
@@ -0,0 +1,19 @@
+{ pkgs }:
+
+pkgs.write "xextras" {
+ "/bin/net-current-desktop".link =
+ pkgs.writeDash "net-current-desktop" ''
+ # SYNOPSIS
+ # net-current-desktop
+ #
+ ${pkgs.xorg.xprop}/bin/xprop -notype -root 32i _NET_CURRENT_DESKTOP 8s _NET_DESKTOP_NAMES |
+ ${pkgs.jq}/bin/jq -Rrs '
+ split("\n") | map(select(.!="") | split(" = ") | { name: .[0], value: .[1] }) | from_entries |
+ {
+ _NET_CURRENT_DESKTOP: (._NET_CURRENT_DESKTOP | tonumber),
+ _NET_DESKTOP_NAMES: (._NET_DESKTOP_NAMES | "[\(ltrimstr("._NET_DESKTOP_NAMES = "))]" | fromjson)
+ } |
+ ._NET_DESKTOP_NAMES[._NET_CURRENT_DESKTOP]
+ '
+ '';
+}