diff --git a/env/.config/hypr/keybinds.conf b/env/.config/hypr/keybinds.conf index 1b66158..16e42f3 100644 --- a/env/.config/hypr/keybinds.conf +++ b/env/.config/hypr/keybinds.conf @@ -35,7 +35,7 @@ $housecallPro = https://pro.housecallpro.com/app/calendar_new bindd = $mainMod, SPACE, Application launcher, exec, $menu bindd = $mainMod, RETURN, New terminal, exec, $terminal bindd = $mainMod SHIFT, RETURN, New floating terminal, exec, $terminal --class=com.ghostty.float -bindd = $mainMod, TAB, Focus previous workspace, exec, $scripts/switch-to-workspace previous +bindd = $mainMod, TAB, Focus previous workspace, exec, $scripts/workspacectl switch --to previous bindd = $mainMod, A, [A]i - launch / focus, exec, $pwa --or-focus "https://chatgpt.com" bindd = $mainMod SHIFT, A, [A]i - new window, exec, $pwa "https://chatgpt.com" bindd = $mainMod, B, New [b]rowser, exec, $browser @@ -71,16 +71,16 @@ bindd = $mainMod, W, Close current window, killac bindd = $mainMod SHIFT, W, Close all windows in active workspace, exec, $scripts/windowctl close --active-workspace # Switch to workspaces with mainMod + [0-9] -bindd = $mainMod, 1, Switch to workspace [1], exec, $scripts/switch-to-workspace 1 -bindd = $mainMod, 2, Switch to workspace [2], exec, $scripts/switch-to-workspace 2 -bindd = $mainMod, 3, Switch to workspace [3], exec, $scripts/switch-to-workspace 3 -bindd = $mainMod, 4, Switch to workspace [4], exec, $scripts/switch-to-workspace 4 -bindd = $mainMod, 5, Switch to workspace [5], exec, $scripts/switch-to-workspace 5 -bindd = $mainMod, 6, Switch to workspace [6], exec, $scripts/switch-to-workspace 6 -bindd = $mainMod, 7, Switch to workspace [7], exec, $scripts/switch-to-workspace 7 -bindd = $mainMod, 8, Switch to workspace [8], exec, $scripts/switch-to-workspace 8 -bindd = $mainMod, 9, Switch to workspace [9], exec, $scripts/switch-to-workspace 9 -bindd = $mainMod, 0, Switch to workspace 1[0], exec, $scripts/switch-to-workspace 10 +bindd = $mainMod, 1, Switch to workspace [1], exec, $scripts/workspacectl switch --to 1 +bindd = $mainMod, 2, Switch to workspace [2], exec, $scripts/workspacectl switch --to 2 +bindd = $mainMod, 3, Switch to workspace [3], exec, $scripts/workspacectl switch --to 3 +bindd = $mainMod, 4, Switch to workspace [4], exec, $scripts/workspacectl switch --to 4 +bindd = $mainMod, 5, Switch to workspace [5], exec, $scripts/workspacectl switch --to 5 +bindd = $mainMod, 6, Switch to workspace [6], exec, $scripts/workspacectl switch --to 6 +bindd = $mainMod, 7, Switch to workspace [7], exec, $scripts/workspacectl switch --to 7 +bindd = $mainMod, 8, Switch to workspace [8], exec, $scripts/workspacectl switch --to 8 +bindd = $mainMod, 9, Switch to workspace [9], exec, $scripts/workspacectl switch --to 9 +bindd = $mainMod, 0, Switch to workspace 1[0], exec, $scripts/workspacectl switch --to 10 # Move all workspaces to a monitor bindd = $mainMod SHIFT, 1, Switch all workspaces to monitor [1], exec, $scripts/mv-all-workspaces-to-monitor 1 diff --git a/env/.local/scripts/hypr/switch-to-workspace b/env/.local/scripts/hypr/utils/workspaces/switch-to-workspace similarity index 69% rename from env/.local/scripts/hypr/switch-to-workspace rename to env/.local/scripts/hypr/utils/workspaces/switch-to-workspace index d871b34..91b4ac9 100755 --- a/env/.local/scripts/hypr/switch-to-workspace +++ b/env/.local/scripts/hypr/utils/workspaces/switch-to-workspace @@ -1,5 +1,6 @@ #!/usr/bin/env bash +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} THIS_FILE=${BASH_SOURCE[0]} LOG_LABEL=$(basename $THIS_FILE) LOG_FILE=${LOG_FILE:-/tmp/$LOG_LABEL.log} @@ -17,34 +18,49 @@ the workspace. USAGE: - $ $THIS [OPTIONS] -OPTIONS: +$ $THIS - -h | --help: Show this help page. +FLAGS: + -p | --previous: Switch to the previously active workspace. + -t | --to : Workspace to switch to. + -h | --help: Show this help page. EOF } +log() { + logging log --source "$THIS_FILE" "$@" +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_FILE" "$LOG_LABEL" + target_workspace="" active_workspace=$(hyprctl activewindow -j | jq -r '.workspace.name') -SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} while [[ $# -gt 0 ]]; do if [[ $1 =~ ^-h ]] || [[ $1 =~ ^--help ]]; then usage && exit 0 + elif [[ $1 =~ ^-t ]] || [[ $1 =~ ^--to ]]; then + target_workspace=$1 + elif [[ $1 =~ ^-p ]] || [[ $1 =~ ^--previous ]]; then + target_workspace="previous" else target_workspace=$1 fi shift done -log() { - logging log --source "$THIS_FILE" "$@" -} - -source "$SCRIPTS/hypr/logging" -setup-logging "$LOG_FILE" "$LOG_LABEL" +# Read from stdin if no workspace was supplied. +if [[ -z $target_workspace ]]; then + read -p "Workspace: " target_workspace +fi if [[ -z target_workspace ]]; then log --error "Must supply a workpsace to switch to." diff --git a/env/.local/scripts/hypr/workspacectl b/env/.local/scripts/hypr/workspacectl index 3ef26c9..8059847 100755 --- a/env/.local/scripts/hypr/workspacectl +++ b/env/.local/scripts/hypr/workspacectl @@ -20,6 +20,7 @@ USAGE: COMMANDS: launch: Launches in a new terminal window. picker: Shows a picker / stats about active workspaces. + switch: Switch to another workspace, handling special workspaces. toggle: Toggle visibility of all windows on a workspace. FLAGS: @@ -54,6 +55,11 @@ while [[ $# -gt 0 ]]; do shift THIS="$THIS picker" "$SCRIPTS/hypr/utils/workspaces/workspace-picker" "$@" exit $? + + elif [[ $1 == "switch" ]]; then + shift + THIS="$THIS switch" "$SCRIPTS/hypr/utils/workspaces/switch-to-workspace" "$@" + exit $? elif [[ $1 == "toggle" ]]; then shift THIS="$THIS toggle" "$SCRIPTS/hypr/utils/workspaces/workspace-toggle" "$@"