Auto-adapts sway workspace routing to however many monitors are connected (laptop vs. desktop) instead of hardcoding output names.
34 lines
880 B
Bash
Executable File
34 lines
880 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
workspace=$(swaymsg -t get_workspaces -r | jq -c '.[] | select(.focused)')
|
|
number=$(jq -r '.num' <<<"$workspace")
|
|
current_name=$(jq -r '.name' <<<"$workspace")
|
|
|
|
if (( number < 1 )); then
|
|
notify-send -a Waybar -u low "Workspace rename" \
|
|
"The focused workspace does not have a numeric identity."
|
|
exit 1
|
|
fi
|
|
|
|
current_label=${current_name#"$number:"}
|
|
if [[ "$current_label" == "$current_name" ]]; then
|
|
current_label=
|
|
else
|
|
current_label=${current_label# }
|
|
fi
|
|
|
|
label=$(printf '%s\n' "$current_label" | wofi --dmenu \
|
|
--prompt "Name workspace $number (blank resets)" \
|
|
--lines 1) || exit 0
|
|
|
|
label=${label//$'\n'/ }
|
|
if [[ -z "${label//[[:space:]]/}" ]]; then
|
|
new_name=$number
|
|
else
|
|
new_name="$number: $label"
|
|
fi
|
|
|
|
quoted_name=$(jq -Rrn --arg name "$new_name" '$name | @json')
|
|
swaymsg "rename workspace to $quoted_name" >/dev/null
|