feat: Moves launch or focus script and makes it so that it can also close a window based on pattern. Updates keybinds that use it.

This commit is contained in:
2025-10-03 09:58:05 -04:00
parent 50191dde0c
commit 8bb6d35acd
5 changed files with 71 additions and 38 deletions

61
env/.local/scripts/launch-or vendored Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
usage() {
cat <<EOF
Launch or focus / close a window based on pattern contained within the window
class name. (Default is to focus the window).
USAGE:
$ $(basename ${BASH_SOURCE[0]}) [OPTIONS] PATTERN [LAUNCH_CMD...]
OPTIONS:
-f | --focus: Focus the window matching the pattern, if it exists.
-c | --close: Close the window matching the pattern, if it exists.
-h | --help: Show this help page.
EOF
}
action="focuswindow"
pattern=""
launch_cmd=()
while [[ $# -gt 0 ]]; do
if [[ $1 == "-c" ]] || [[ $1 == "--close" ]]; then
action="closewindow"
elif [[ $1 == "-f" ]] || [[ $1 == "--focus" ]]; then
action="focuswindow"
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
usage && exit 0
elif [[ -z $pattern ]]; then
pattern=$1
else
launch_cmd+=("$1")
fi
shift
done
if [[ -z $pattern ]]; then
echo "[ERROR]: Must supply a pattern to match the window class."
usage && exit 1
elif [[ -z $launch_cmd ]]; then
echo "[ERROR]: Must supply a launch command to match the window class."
usage && exit 1
fi
address=$(hyprctl clients -j | jq -r ".[] | select(.class | contains(\"$pattern\")) | .address")
echo "Pattern: $pattern"
echo "Address: $address"
if [[ -n $address ]]; then
echo "Found window, dispatching action: $action"
hyprctl dispatch $action "address:$address"
else
echo "Launching..."
echo "'${launch_cmd[@]}'"
eval exec ${launch_cmd[@]}
fi

View File

@@ -1,28 +0,0 @@
#!/usr/bin/env bash
# Launch or focus a window based on a pattern contained within the
# window class name.
pattern=$1
launchCmd=${@:2}
if [[ -z $pattern ]]; then
echo "Error: Must supply a pattern to match the window class."
exit 1
fi
if [[ -z $launchCmd ]]; then
echo "Error: Must supply a launch command to match the window class."
exit 1
fi
address=$(hyprctl clients -j | jq -r ".[] | select(.class | contains(\"$pattern\")) | .address")
echo "Pattern: $pattern"
echo "Address: $address"
if [[ -n $address ]]; then
hyprctl dispatch focuswindow "address:$address"
else
eval exec $launchCmd
fi

View File

@@ -29,7 +29,7 @@ launched terminal, allowing you to launch with a specific mode turned on, any fl
EOF
}
window_class="com.ghostty.$(basename ${BASH_SOURCE[0]})"
window_class="com.ghostty.window-table"
window_padding_x="10"
clipboard_flag="0"
@@ -94,7 +94,8 @@ show_table_return_choice() {
fi
local ret=$(
printf '%s\n' "${rows[@]}" |
gum table --columns "$columns" --return-column $ret_column
fzf --footer="Workspace - Title - Address" --footer-label-pos=center
# gum table --columns "$columns" --return-column $ret_column
)
# remove spaces and quotes from result.