From 47527d7175eb1fba90151446f8d50f458814ce94 Mon Sep 17 00:00:00 2001 From: ashmartin1810 Date: Tue, 19 Aug 2025 20:30:00 +0530 Subject: [PATCH] Feat: Improved Workspace_action.sh and added relative workspace support. ## Problem The previous script didnt take into account for relative workspaces, and my previous pull request was... bad. ## Fix Added smart branching to detect if the target is a literal number(1,2,90), or a relative number(+1, -20) or a string target. ## Bugs None. ive been stress testing it since the last 2 days, --- .../hypr/hyprland/scripts/workspace_action.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.config/hypr/hyprland/scripts/workspace_action.sh b/.config/hypr/hyprland/scripts/workspace_action.sh index a43badfc8..d1e64f8b3 100755 --- a/.config/hypr/hyprland/scripts/workspace_action.sh +++ b/.config/hypr/hyprland/scripts/workspace_action.sh @@ -1,2 +1,17 @@ -#!/usr/bin/env bash -hyprctl dispatch "$1" $(((($(hyprctl activeworkspace -j | jq -r .id) - 1) / 10) * 10 + $2)) +curr_workspace="$(hyprctl activeworkspace -j | jq -r ".id")" ##parses json output of hyprctl activeworkspace on the active monitor +dispatcher="$1" +shift ##Any dispatcher that hyprland supports, the shift shifts the target such that target is now in $1, not $2 + +if [[ -z "${dispatcher}" || "${dispatcher}" == "--help" || "${dispatcher}" == "-h" || -z "$1" ]]; then + echo "Usage: $0 " + exit 1 +fi +if [[ "$1" == *"+"* || "$1" == *"-"* ]]; then ##pattern matching (works with r+1 and +1 only aswell) + hyprctl dispatch "${dispatcher}" "$1" ##$1 = workspace id since we shifted earlier. +elif [[ "$1" =~ ^[0-9]+$ ]]; then ##Regex matching + target_workspace=$(((($curr_workspace - 1) / 10 ) * 10 + $1)) + hyprctl dispatch "${dispatcher}" "${target_workspace}" +else + hyprctl dispatch "${dispatcher}" "$1" ##Incase the target in a string, required for special workspaces. + exit 1 +fi