summaryrefslogtreecommitdiff
path: root/toggles
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-03 21:41:26 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-03 21:41:26 +1100
commitf8a6e84aa9b9229a1b527dcd1c662c1068759dd8 (patch)
tree0893be4c5101a49dfbea6af52ad865d5e3f91481 /toggles
parentcompletions: add for shell toggle cmd (diff)
downloadcaelestia-cli-f8a6e84aa9b9229a1b527dcd1c662c1068759dd8.tar.gz
caelestia-cli-f8a6e84aa9b9229a1b527dcd1c662c1068759dd8.tar.bz2
caelestia-cli-f8a6e84aa9b9229a1b527dcd1c662c1068759dd8.zip
toggles: refactor to have config
Config is in $XDG_CONFIG_HOME/caelestia/scripts.json Selector is a jq selector using hyprland client data Spawn is a command passed to uwsm app Action is either spawn, move, or both Extra cond is an extra shell command to check whether to do action (for easy disabling just put false or empty action)
Diffstat (limited to 'toggles')
-rwxr-xr-xtoggles/communication.fish12
-rwxr-xr-xtoggles/music.fish8
-rwxr-xr-xtoggles/sysmon.fish7
-rwxr-xr-xtoggles/todo.fish7
-rw-r--r--toggles/util.fish31
5 files changed, 26 insertions, 39 deletions
diff --git a/toggles/communication.fish b/toggles/communication.fish
deleted file mode 100755
index 7237d4b..0000000
--- a/toggles/communication.fish
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/fish
-
-. (dirname (status filename))/util.fish
-
-spawn-or-move '.class == "equibop"' communication equibop
-
-# Has whatsapp firefox profile
-if grep -q 'Name=whatsapp' ~/.mozilla/firefox/profiles.ini
- spawn-or-move '.class == "whatsapp"' communication firefox --name whatsapp -P whatsapp 'https://web.whatsapp.com'
-end
-
-hyprctl dispatch togglespecialworkspace communication
diff --git a/toggles/music.fish b/toggles/music.fish
deleted file mode 100755
index 95f2c0d..0000000
--- a/toggles/music.fish
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/fish
-
-. (dirname (status filename))/util.fish
-
-move-client '.class == "feishin"' music
-move-client '.class == "Spotify" or .initialTitle == "Spotify" or .initialTitle == "Spotify Free"' music
-
-hyprctl dispatch togglespecialworkspace music
diff --git a/toggles/sysmon.fish b/toggles/sysmon.fish
deleted file mode 100755
index d30e278..0000000
--- a/toggles/sysmon.fish
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/fish
-
-. (dirname (status filename))/util.fish
-
-spawn-client '.class == "btop" and .title == "btop" and .workspace.name == "special:sysmon"' foot -a 'btop' -T 'btop' -- btop
-
-hyprctl dispatch togglespecialworkspace sysmon
diff --git a/toggles/todo.fish b/toggles/todo.fish
deleted file mode 100755
index db189bb..0000000
--- a/toggles/todo.fish
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/fish
-
-. (dirname (status filename))/util.fish
-
-spawn-or-move '.class == "Todoist"' todo todoist
-
-hyprctl dispatch togglespecialworkspace todo
diff --git a/toggles/util.fish b/toggles/util.fish
index 4d7df2c..f02dc73 100644
--- a/toggles/util.fish
+++ b/toggles/util.fish
@@ -1,4 +1,6 @@
-function move-client -a selector -a workspace
+. (dirname (status filename))/../util.fish
+
+function move-client -a selector workspace
if hyprctl -j clients | jq -e 'first(.[] | select('$selector')).workspace.name != "special:'$workspace'"' > /dev/null
# Window not in correct workspace
set -l window_addr (hyprctl -j clients | jq -r 'first(.[] | select('$selector')).address')
@@ -6,16 +8,35 @@ function move-client -a selector -a workspace
end
end
-function spawn-client -a selector
+function spawn-client -a selector spawn
# Spawn if doesn't exist
hyprctl -j clients | jq -e "first(.[] | select($selector))" > /dev/null
set -l stat $status
if test $stat != 0
- uwsm app -- $argv[2..] & disown
+ eval "uwsm app -- $spawn & disown"
end
test $stat != 0 # Exit 1 if already exists
end
-function spawn-or-move -a selector -a workspace
- spawn-client $selector $argv[3..] || move-client $selector $workspace
+function jq-var -a op json
+ jq -rn --argjson json "$json" "\$json | $op"
+end
+
+function toggle-workspace -a workspace
+ set -l apps (get-config "toggles.$workspace.apps")
+
+ for i in (seq 0 (math (jq-var 'length' "$apps") - 1))
+ set -l app (jq-var ".[$i]" "$apps")
+ set -l action (jq-var '.action' "$app")
+ set -l selector (jq-var '.selector' "$app")
+ set -l extra_cond (jq-var '.extraCond' "$app")
+
+ test $extra_cond = null && set -l extra_cond true
+ if eval $extra_cond
+ string match -qe -- 'spawn' $action && spawn-client $selector (jq-var '.spawn' "$app")
+ string match -qe -- 'move' $action && move-client $selector $workspace
+ end
+ end
+
+ hyprctl dispatch togglespecialworkspace $workspace
end