mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
feat: Fixes missing window-picker script that got deleted.
This commit is contained in:
91
env/.local/scripts/hypr/utils/windows/window-picker
vendored
Executable file
91
env/.local/scripts/hypr/utils/windows/window-picker
vendored
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
THIS=${THIS:-$(basename ${BASH_SOURCE[0]})}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
Select from currently available windows, returning the selected window's address.
|
||||
|
||||
USAGE:
|
||||
|
||||
$ $THIS <flags> [FZF_OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-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
|
||||
}
|
||||
|
||||
uses_supplied_footer="0"
|
||||
|
||||
fzf_opts=()
|
||||
rows=()
|
||||
window_data=$(hyprctl clients -j | jq 'sort_by(.workspace.id)')
|
||||
|
||||
footer() {
|
||||
cat <<'EOF'
|
||||
_ ___ __
|
||||
| | /| / (_)__ ___/ /__ _ _____
|
||||
| |/ |/ / / _ \/ _ / _ \ |/|/ (_-<
|
||||
|__/|__/_/_//_/\_,_/\___/__,__/___/
|
||||
EOF
|
||||
}
|
||||
|
||||
generate_rows() {
|
||||
|
||||
readarray -t addresses <<<"$(echo "$window_data" | jq -r '.[] | .address')"
|
||||
readarray -t titles <<<$(echo "$window_data" | jq -r '.[] | .title')
|
||||
|
||||
# Zip into rows.
|
||||
for i in "${!addresses[@]}"; do
|
||||
rows+=("${addresses[i]}|${titles[i]}")
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 =~ ^--footer ]]; then
|
||||
uses_supplied_footer="1"
|
||||
fzf_opts+=("$1")
|
||||
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage && exit 0
|
||||
else
|
||||
fzf_opts+=("$1")
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $uses_supplied_footer == "0" ]]; then
|
||||
fzf_opts+=("--footer=$(footer)")
|
||||
fi
|
||||
|
||||
generate_rows
|
||||
|
||||
sel=$(
|
||||
printf '%s\n' "${rows[@]}" |
|
||||
fzf --style=full "${fzf_opts[@]}" \
|
||||
--preview-label='[ Window Stats ]' --delimiter='|' --with-nth=2 \
|
||||
--preview='$SCRIPTS/hypr/utils/fzf/preview-stats window {1}'
|
||||
)
|
||||
status=$?
|
||||
|
||||
[[ -z $sel ]] && exit 1
|
||||
|
||||
# revove everything but the address portion.
|
||||
sel=${sel%%|*}
|
||||
echo "$sel"
|
||||
exit $status
|
||||
@@ -50,7 +50,7 @@ handle_selected_value() {
|
||||
}
|
||||
|
||||
prompt_for_window_selection() {
|
||||
local selected_value=$("$SCRIPTS/hypr/window-picker")
|
||||
local selected_value=$("$SCRIPTS/hypr/utils/windows/window-picker")
|
||||
local status=$?
|
||||
if [[ $status -ne 0 ]]; then
|
||||
exit $status
|
||||
|
||||
Reference in New Issue
Block a user