desktop-utils/scripts/workspaces.sh
2024-06-03 11:56:16 +02:00

34 lines
854 B
Bash
Executable file

#!/usr/bin/env bash
# Check if an argument is provided
if [[ -z $1 ]]; then
# echo "Error: Number argument is missing."
exit 1
fi
# Retrieve the argument value
new_workspace=$1
if [[ $new_workspace == special:* ]]; then
hyprctl dispatch togglespecialworkspace "${new_workspace:8}"
exit 0
fi
# Validate if the argument is a number
if ! [[ $new_workspace =~ ^-?[0-9]+$ ]]; then
# echo "Error: Invalid number argument."
exit 1
fi
while read -r i a f;do
workspace[$a]=$i
if [[ $f == true ]]; then
active=$i
fi
done < <(hyprctl monitors -j | jq -r '.[]|"\(.id) \(.activeWorkspace.id) \(.focused)"')
if [[ ${workspace[$new_workspace]} ]]; then
hyprctl dispatch swapactiveworkspaces $active ${workspace[$new_workspace]}
else
hyprctl --batch "dispatch moveworkspacetomonitor $new_workspace $active ; dispatch workspace $new_workspace"
fi