mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-15 06:32:40 +00:00
feat: Begin incorporating utility scripts into windowctl
This commit is contained in:
@@ -16,7 +16,7 @@ should_go_back="0"
|
|||||||
if [[ $# == 1 ]]; then
|
if [[ $# == 1 ]]; then
|
||||||
address="$1"
|
address="$1"
|
||||||
else
|
else
|
||||||
# If an address not supplied then read from stdin, which allows us to pipe into
|
# If an address not supplied then read from stdin, which allows us to pipe the address into
|
||||||
# this command.
|
# this command.
|
||||||
read -r address
|
read -r address
|
||||||
fi
|
fi
|
||||||
@@ -44,8 +44,10 @@ hypr_dispatch() {
|
|||||||
|
|
||||||
focus_window() {
|
focus_window() {
|
||||||
log "Focusing window, selection: $address"
|
log "Focusing window, selection: $address"
|
||||||
|
|
||||||
local name=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$address\") | .workspace.name")
|
local name=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$address\") | .workspace.name")
|
||||||
local active_workspace=$(hyprctl activewindow -j | jq -r ".workspace.name")
|
local active_workspace=$(hyprctl activewindow -j | jq -r ".workspace.name")
|
||||||
|
|
||||||
log "Window workspace: '$name', active workspace: '$active_workspace'"
|
log "Window workspace: '$name', active workspace: '$active_workspace'"
|
||||||
if [[ $name =~ ^special ]] && [[ ! $active_workspace == $name ]]; then
|
if [[ $name =~ ^special ]] && [[ ! $active_workspace == $name ]]; then
|
||||||
log "Toggling special workspace prior to focusing window."
|
log "Toggling special workspace prior to focusing window."
|
||||||
@@ -91,7 +93,60 @@ move_to_workspace() {
|
|||||||
xargs -I{} hyprctl dispatch "$action" "{},address:$address" >/dev/null 2>&1
|
xargs -I{} hyprctl dispatch "$action" "{},address:$address" >/dev/null 2>&1
|
||||||
|
|
||||||
return $?
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
make_selection() {
|
||||||
|
log "Prompting for window action..."
|
||||||
|
local choices=(
|
||||||
|
"Focus the selected window.:Focus window"
|
||||||
|
"Close the selected window.:Close window"
|
||||||
|
"Close the selected window and go back to the window list.:Close window and back"
|
||||||
|
"Move the selected window to another workspace, focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace"
|
||||||
|
"Move the selected window to another workspace, without focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace - silent"
|
||||||
|
"Copy the window address to the system clipboard:Copy to clipboard"
|
||||||
|
"Move back to window picker and reload windows.:Back"
|
||||||
|
"Quit:Quit"
|
||||||
|
)
|
||||||
|
local preview_action="$SCRIPTS/hypr/preview-stats window $address \"{title, workspace, address}\""
|
||||||
|
local choice=$(
|
||||||
|
printf "%s\n" "${choices[@]}" |
|
||||||
|
fzf --style=full --footer="$(action_footer)" \
|
||||||
|
--delimiter=':' --with-nth=2 \
|
||||||
|
--header="What should we do with the selected window?" \
|
||||||
|
--preview-label="[ Description ]" \
|
||||||
|
--preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $preview_action;"
|
||||||
|
)
|
||||||
|
# Exit if non-zero code returned from making selection.
|
||||||
|
[[ $? -gt 0 ]] && log --error "Unexpected fzf status: $?" && exit $?
|
||||||
|
# Set choice to just the action portion.
|
||||||
|
choice="${choice#*:}"
|
||||||
|
echo "$choice"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set appropriate flags based on the choice and perform the action on the window address.
|
||||||
|
handle_selection() {
|
||||||
|
local choice=""
|
||||||
|
read -r choice
|
||||||
|
log "Action Choice: $choice"
|
||||||
|
if [[ $choice == "Quit" ]]; then
|
||||||
|
exit 0
|
||||||
|
elif [[ $choice == "Close window" ]]; then
|
||||||
|
"$SCRIPTS/hypr/close-windows" "$address"
|
||||||
|
elif [[ $choice == "Close window and back" ]]; then
|
||||||
|
"$SCRIPTS/hypr/close-windows" "$address"
|
||||||
|
should_go_back="1"
|
||||||
|
elif [[ $choice == "Copy to clipboard" ]]; then
|
||||||
|
echo $address | wl-copy
|
||||||
|
elif [[ $choice == "Focus window" ]]; then
|
||||||
|
focus_window
|
||||||
|
elif [[ $choice == "Move to workspace" ]]; then
|
||||||
|
move_to_workspace
|
||||||
|
elif [[ $choice == "Move to workspace - silent" ]]; then
|
||||||
|
move_silent_flag="1"
|
||||||
|
move_to_workspace
|
||||||
|
elif [[ $choice == "Back" ]]; then
|
||||||
|
should_go_back="1"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -107,56 +162,7 @@ if [[ -z $address ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "Prompting for window action..."
|
make_selection | handle_selection
|
||||||
|
|
||||||
choices=(
|
|
||||||
"Focus the selected window.:Focus window"
|
|
||||||
"Close the selected window.:Close window"
|
|
||||||
"Close the selected window and go back to the window list.:Close window and back"
|
|
||||||
"Move the selected window to another workspace, focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace"
|
|
||||||
"Move the selected window to another workspace, without focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace - silent"
|
|
||||||
"Copy the window address to the system clipboard:Copy to clipboard"
|
|
||||||
"Move back to window picker and reload windows.:Back"
|
|
||||||
"Quit:Quit"
|
|
||||||
)
|
|
||||||
preview_action="$SCRIPTS/hypr/preview-stats window $address \"{title, workspace, address}\""
|
|
||||||
choice=$(
|
|
||||||
printf "%s\n" "${choices[@]}" |
|
|
||||||
fzf --style=full --footer="$(action_footer)" \
|
|
||||||
--delimiter=':' --with-nth=2 \
|
|
||||||
--header="What should we do with the selected window?" \
|
|
||||||
--preview-label="[ Description ]" \
|
|
||||||
--preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $preview_action;"
|
|
||||||
)
|
|
||||||
if [[ $? -gt 0 ]]; then
|
|
||||||
log --error "Unexpected fzf status: $?"
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set choice to just the action portion.
|
|
||||||
choice="${choice#*:}"
|
|
||||||
log "Action Choice: $choice"
|
|
||||||
|
|
||||||
# Set appropriate flags based on the choice and perform the action on the window address.
|
|
||||||
if [[ $choice == "Quit" ]]; then
|
|
||||||
exit 0
|
|
||||||
elif [[ $choice == "Close window" ]]; then
|
|
||||||
"$SCRIPTS/hypr/close-windows" "$address"
|
|
||||||
elif [[ $choice == "Close window and back" ]]; then
|
|
||||||
"$SCRIPTS/hypr/close-windows" "$address"
|
|
||||||
should_go_back="1"
|
|
||||||
elif [[ $choice == "Copy to clipboard" ]]; then
|
|
||||||
echo $address | wl-copy
|
|
||||||
elif [[ $choice == "Focus window" ]]; then
|
|
||||||
focus_window
|
|
||||||
elif [[ $choice == "Move to workspace" ]]; then
|
|
||||||
move_to_workspace
|
|
||||||
elif [[ $choice == "Move to workspace - silent" ]]; then
|
|
||||||
move_silent_flag="1"
|
|
||||||
move_to_workspace
|
|
||||||
elif [[ $choice == "Back" ]]; then
|
|
||||||
should_go_back="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: Maybe we just echo out a 'back' message.
|
# TODO: Maybe we just echo out a 'back' message.
|
||||||
if [[ $should_go_back == "1" ]]; then
|
if [[ $should_go_back == "1" ]]; then
|
||||||
|
|||||||
15
env/.local/scripts/hypr/windowctl
vendored
15
env/.local/scripts/hypr/windowctl
vendored
@@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
THIS_FILE=${BASH_SOURCE[0]}
|
THIS_FILE=${BASH_SOURCE[0]}
|
||||||
THIS=$(basename $THIS_FILE)
|
THIS=$(basename $THIS_FILE)
|
||||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||||
@@ -111,6 +115,13 @@ log() {
|
|||||||
logging log --source "$THIS_FILE" "$@"
|
logging log --source "$THIS_FILE" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Launch in a new terminal window.
|
||||||
|
launch() {
|
||||||
|
ghostty --class="$window_class" --window-padding-x="$window_padding_x" \
|
||||||
|
--keybind="ctrl+c=quit" \
|
||||||
|
-e "${BASH_SOURCE[0]}" "${launch_args[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
# Reset flags and selection.
|
# Reset flags and selection.
|
||||||
reset_flags() {
|
reset_flags() {
|
||||||
selected_value=""
|
selected_value=""
|
||||||
@@ -271,9 +282,7 @@ setup-logging "/tmp/$THIS.log" "$THIS"
|
|||||||
log "Starting with selected value: '$selected_value'"
|
log "Starting with selected value: '$selected_value'"
|
||||||
|
|
||||||
if [[ $launch_flag == "1" ]]; then
|
if [[ $launch_flag == "1" ]]; then
|
||||||
ghostty --class="$window_class" --window-padding-x="$window_padding_x" \
|
launch && exit 0
|
||||||
--keybind="ctrl+c=quit" \
|
|
||||||
-e "${BASH_SOURCE[0]}" "${launch_args[@]}"
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# Load colors if they haven't been loaded already.
|
# Load colors if they haven't been loaded already.
|
||||||
|
|||||||
Reference in New Issue
Block a user