mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
feat: Begins workspacectl.
This commit is contained in:
130
env/.local/scripts/hypr/utils/workspaces/workspace-picker
vendored
Executable file
130
env/.local/scripts/hypr/utils/workspaces/workspace-picker
vendored
Executable file
@@ -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 <<EOF
|
||||
|
||||
Select from currently available workspaces. If no options are specified, then the default behavior is
|
||||
to return the selected workspace id.
|
||||
|
||||
USAGE:
|
||||
|
||||
$ $THIS <flags> [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'
|
||||
_ __ __
|
||||
| | /| / /__ ____/ /__ ___ ___ ___ ________ ___
|
||||
| |/ |/ / _ \/ __/ '_/(_-</ _ \/ _ `/ __/ -_|_-<
|
||||
|__/|__/\___/_/ /_/\_\/___/ .__/\_,_/\__/\__/___/
|
||||
/_/
|
||||
EOF
|
||||
}
|
||||
|
||||
prompt_for_selection() {
|
||||
|
||||
local rows=()
|
||||
local fzf_opts=$1
|
||||
local sel=""
|
||||
local workspaces=$(hyprctl workspaces -j | jq 'sort_by(.id)')
|
||||
|
||||
readarray -t names <<<"$(echo "$workspaces" | jq -r '.[] | .name')"
|
||||
readarray -t ids <<<"$(echo "$workspaces" | jq -r '.[] | .id')"
|
||||
|
||||
for i in "${!names[@]}"; do
|
||||
rows+=("${ids[i]}|${names[i]}")
|
||||
done
|
||||
|
||||
log "Showing workspace picker / stats..."
|
||||
|
||||
sel=$(
|
||||
printf "%s\n" "${rows[@]}" |
|
||||
fzf --style=full "${fzf_opts[@]}" --delimiter='|' --with-nth=2 \
|
||||
--preview-label='[ Workspace Stats ]' \
|
||||
--preview='$SCRIPTS/hypr/utils/fzf/preview-stats workspace {1}'
|
||||
)
|
||||
|
||||
echo "$sel"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
# Setup logging file and label.
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||
|
||||
return_name_if_special_flag="0"
|
||||
return_name_flag="0"
|
||||
uses_supplied_footer="0"
|
||||
fzf_opts=()
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage && exit 0
|
||||
elif [[ $1 == "-n" ]] || [[ $1 == "--return-name" ]]; then
|
||||
return_name_flag="1"
|
||||
elif [[ $1 == "-s" ]] || [[ $1 == "--return-name-if-special" ]]; then
|
||||
return_name_if_special_flag="1"
|
||||
elif [[ $1 =~ ^--footer ]]; then
|
||||
uses_supplied_footer="1"
|
||||
fzf_opts+=("$1")
|
||||
else
|
||||
fzf_opts+=("$1")
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
# Load fzf color scheme if it's not been setup yet.
|
||||
[[ -z ${FZF_DEFAULT_OPTS} ]] &&
|
||||
[[ -f $SCRIPTS/catppuccin-colors ]] &&
|
||||
source $SCRIPTS/catppuccin-colors
|
||||
|
||||
if [[ $uses_supplied_footer == "0" ]]; then
|
||||
fzf_opts+=("--footer=$(footer)")
|
||||
fi
|
||||
|
||||
sel=$(prompt_for_selection "${fzf_opts[@]}")
|
||||
name=${sel##*\|}
|
||||
id=${sel%%\|*}
|
||||
|
||||
if [[ $return_name_flag == "1" ]] ||
|
||||
([[ $return_name_if_special_flag == "1" ]] && [[ $name =~ ^special ]]); then
|
||||
echo "$name" && exit 0
|
||||
fi
|
||||
|
||||
echo "$id"
|
||||
99
env/.local/scripts/hypr/utils/workspaces/workspace-toggle
vendored
Executable file
99
env/.local/scripts/hypr/utils/workspaces/workspace-toggle
vendored
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# TODO: This works / was adapted to work with mutliple workspaces, but with this
|
||||
# implementation then we don't know the last workspace that was hidden, and after
|
||||
# hiding windows the original workspace doesn't technically exist (it seems), but
|
||||
# stays visible because a special workspace is displayed overtop of it. This should
|
||||
# either be reverted to only work on one workspace, or perhaps write a temp file with
|
||||
# last workspace (as the orginal), but also have a picker that shows all workspaces
|
||||
# with hidden windows, but I honestly not sure how useful it is to hide windows on
|
||||
# multiple workspaces at once is.
|
||||
|
||||
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"}
|
||||
|
||||
# Workspace to hide everything in
|
||||
HIDE_WS=${HIDE_WS:-"special:hidden"}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Toggle the visibility of all windows on a given workspace.
|
||||
|
||||
USAGE:
|
||||
|
||||
$ $THIS <flags> <workspace-id>
|
||||
|
||||
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
|
||||
65
env/.local/scripts/hypr/utils/workspaces/workspacectl-launch
vendored
Executable file
65
env/.local/scripts/hypr/utils/workspaces/workspacectl-launch
vendored
Executable file
@@ -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 <<EOF
|
||||
Launches a $PARENT_COMMAND command in a new terminal window. If a command
|
||||
is not supplied, then we will launch the workspace picker.
|
||||
|
||||
USAGE:
|
||||
$ $THIS <command> <flags>
|
||||
|
||||
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 $?
|
||||
66
env/.local/scripts/hypr/workspacectl
vendored
Executable file
66
env/.local/scripts/hypr/workspacectl
vendored
Executable file
@@ -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 <<EOF
|
||||
Utilities for managing workspaces.
|
||||
|
||||
USAGE:
|
||||
$ $THIS <command> <flags>
|
||||
|
||||
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 <command> --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
|
||||
Reference in New Issue
Block a user