From fa6a482f2fc954b81b0a48bd4c86ec55e42aec6e Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Wed, 8 Oct 2025 16:34:39 -0400 Subject: [PATCH] feat: Begins workspacectl. --- .../hypr/utils/workspaces/workspace-picker | 130 ++++++++++++++++++ .../hypr/utils/workspaces/workspace-toggle | 99 +++++++++++++ .../hypr/utils/workspaces/workspacectl-launch | 65 +++++++++ env/.local/scripts/hypr/workspacectl | 66 +++++++++ 4 files changed, 360 insertions(+) create mode 100755 env/.local/scripts/hypr/utils/workspaces/workspace-picker create mode 100755 env/.local/scripts/hypr/utils/workspaces/workspace-toggle create mode 100755 env/.local/scripts/hypr/utils/workspaces/workspacectl-launch create mode 100755 env/.local/scripts/hypr/workspacectl diff --git a/env/.local/scripts/hypr/utils/workspaces/workspace-picker b/env/.local/scripts/hypr/utils/workspaces/workspace-picker new file mode 100755 index 0000000..ec1df48 --- /dev/null +++ b/env/.local/scripts/hypr/utils/workspaces/workspace-picker @@ -0,0 +1,130 @@ +#!/usr/bin/env bash + +set -e +set -o nounset +set -o pipefail + +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} +THIS_FILE=${BASH_SOURCE[0]} +LOG_LABEL=$(basename "$THIS_FILE") +THIS=${THIS:-$LOG_LABEL} +LOG_FILE=${LOG_FILE:-"/tmp/$LOG_LABEL.log"} +FZF_DEFAULT_OPTS=${FZF_DEFAULT_OPTS:-""} + +usage() { + cat < [FZF_OPTIONS] + +FLAGS: + + -n | --return-name: Return workspace name instead of id. + + -s | --return-name-if-special: Return name if a special workspace, otherwise return the id. + This option is useful when moving a workspace using 'hyprctl' with + the selection. + + -h | --help: Show this help page. + +NOTES: + +By default, we show a footer and header unless specifically passed in as extra arguments / options. +Any other options or arguments are passed directly to 'fzf'. + +EOF +} + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +footer() { + cat <<'EOF' + _ __ __ +| | /| / /__ ____/ /__ ___ ___ ___ ________ ___ +| |/ |/ / _ \/ __/ '_/(_- + +FLAGS: + -a | --active: Use the active workspace to hide all windows. + -h | --help: Show this help page. + +EOF +} + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_FILE" "$LOG_LABEL" + +workspace="" +state_file_prefix="/tmp/hypr_hide_state" + +while [[ $# -gt 0 ]]; do + if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then + usage && exit 0 + elif [[ $1 == "-a" ]] || [[ $1 == "--active" ]]; then + workspace=$(hyprctl -j activeworkspace | jq -r '.id') + else + workspace=$1 + fi + shift +done + +if [[ -z $workspace ]]; then + read -p "Workspace id: " workspace +fi + +if [[ -z $workspace ]]; then + log --error "No workspace supplied." && exit 1 +fi + +# File to store original workspace ID +STATE_FILE="${state_file_prefix}_${workspace}" + +# Check if we're currently hidden +if [[ -f "$STATE_FILE" ]]; then + # Restore windows + while read address; do + hyprctl dispatch movetoworkspace "$workspace,address:$address" + hyprctl dispatch workspace "$workspace" + done <"$STATE_FILE" + + rm "$STATE_FILE" +else + if [[ -f $STATE_FILE ]]; then + log --error "State file already exists for workspace, this could cause windows to get stuck hidden." + exit 1 + fi + # Hide all windows (move to special hidden workspace) + for win in $(hyprctl -j clients | jq -r ".[] | select(.workspace.id == $workspace) | .address"); do + log "Hidding address: '$win'" + hyprctl dispatch movetoworkspace "$HIDE_WS,address:$win" + hyprctl dispatch togglespecialworkspace "$HIDE_WS" + echo "$win" >>"$STATE_FILE" + done +fi diff --git a/env/.local/scripts/hypr/utils/workspaces/workspacectl-launch b/env/.local/scripts/hypr/utils/workspaces/workspacectl-launch new file mode 100755 index 0000000..4f8eefb --- /dev/null +++ b/env/.local/scripts/hypr/utils/workspaces/workspacectl-launch @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +set -e +set -o nounset +set -o pipefail + +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} +THIS_FILE=${BASH_SOURCE[0]} +LOG_LABEL=$(basename "$THIS_FILE") +THIS=${THIS:-$LOG_LABEL} +LOG_FILE=${LOG_FILE:-"/tmp/$LOG_LABEL.log"} +PARENT_COMMAND=${THIS// launch/} +if [[ -z PARENT_COMMAND ]]; then + PARENT_COMMAND="workspacectl" +fi + +default_class_name="com.ghostty.$PARENT_COMMAND" +default_window_padding_x="10" + +usage() { + cat < + +Run "$PARENT_COMMAND --help" for commands to launch in the terminal window. + +EOF +} + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +launch() { + ghostty --class="$default_class_name" \ + --window-padding-x="$default_window_padding_x" \ + --keybind="ctrl+c=quit" \ + -e "$SCRIPTS/hypr/workspacectl" "$@" +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_FILE" "$LOG_LABEL" + +args="$@" + +if [[ $args == "-h" ]] || [[ $args == "--help" ]]; then + usage && exit 0 +elif [[ $args =~ ^launch ]]; then + log --error "Invalid command, can not launch the command: '$args'." + exit 1 +elif [[ -z $args ]]; then + args="picker" +fi + +log "Launching with args: $args" +launch "${args[@]}" && exit $? diff --git a/env/.local/scripts/hypr/workspacectl b/env/.local/scripts/hypr/workspacectl new file mode 100755 index 0000000..3ef26c9 --- /dev/null +++ b/env/.local/scripts/hypr/workspacectl @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +set -e +set -o nounset +set -o pipefail + +SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} +THIS_FILE=${BASH_SOURCE[0]} +LOG_LABEL=$(basename "$THIS_FILE") +THIS=${THIS:-$LOG_LABEL} +LOG_FILE=${LOG_FILE:-"/tmp/$LOG_LABEL.log"} + +usage() { + cat < + +COMMANDS: + launch: Launches in a new terminal window. + picker: Shows a picker / stats about active workspaces. + toggle: Toggle visibility of all windows on a workspace. + +FLAGS: + -h | --help Show this page. + +Run "$THIS --help" for more information about a command. + +EOF +} + +# Logging utility function, use in place of echo. +log() { + logging log --source "$THIS_FILE" "$@" +} + +################################################################################ +# MAIN +################################################################################ + +# Setup logging file and label. +source "$SCRIPTS/hypr/logging" +setup-logging "$LOG_FILE" "$LOG_LABEL" + +while [[ $# -gt 0 ]]; do + if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then + usage && exit 0 + elif [[ $1 == "launch" ]]; then + shift + THIS="$THIS launch" "$SCRIPTS/hypr/utils/workspaces/workspacectl-launch" "$@" + exit $? + elif [[ $1 == "picker" ]]; then + shift + THIS="$THIS picker" "$SCRIPTS/hypr/utils/workspaces/workspace-picker" "$@" + exit $? + elif [[ $1 == "toggle" ]]; then + shift + THIS="$THIS toggle" "$SCRIPTS/hypr/utils/workspaces/workspace-toggle" "$@" + exit $? + fi + shift +done + +# If we made it here no commands were passed in / handled. +usage && exit 1