mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
feat: Adds preview windows to window and workspace pickers.
This commit is contained in:
45
env/.local/scripts/hypr/window-picker
vendored
45
env/.local/scripts/hypr/window-picker
vendored
@@ -11,9 +11,6 @@ USAGE:
|
||||
|
||||
$ $THIS [OPTIONS] [ARGS...]
|
||||
|
||||
OPTIONS:
|
||||
--show-window-class: Include window class in the table.
|
||||
|
||||
NOTES:
|
||||
|
||||
By default, we show a footer and header unless specifically passed in as extra arguments / options.
|
||||
@@ -22,24 +19,17 @@ Any other options or arguments are passed directly to 'fzf'.
|
||||
EOF
|
||||
}
|
||||
|
||||
show_window_class_flag="0"
|
||||
uses_supplied_footer="0"
|
||||
uses_supplied_header="0"
|
||||
|
||||
fzf_opts=()
|
||||
rows=()
|
||||
window_data=$(hyprctl clients -j | jq 'sort_by(.workspace.name)')
|
||||
window_data=$(hyprctl clients -j | jq 'sort_by(.workspace.id)')
|
||||
SCRIPTS=${SCRIPTS}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 =~ ^--header ]]; then
|
||||
uses_supplied_header="1"
|
||||
fzf_opts+=("$1")
|
||||
elif [[ $1 =~ ^--footer ]]; then
|
||||
if [[ $1 =~ ^--footer ]]; then
|
||||
uses_supplied_footer="1"
|
||||
fzf_opts+=("$1")
|
||||
elif [[ $1 =~ ^--show-window-class ]]; then
|
||||
show_window_class_flag="1"
|
||||
else
|
||||
fzf_opts+=("$1")
|
||||
fi
|
||||
@@ -59,16 +49,6 @@ footer() {
|
||||
EOF
|
||||
}
|
||||
|
||||
header() {
|
||||
local columns="Workspace | Title | Address"
|
||||
|
||||
if [[ $show_window_class_flag == "1" ]]; then
|
||||
columns="Workspace | Title | Class | Address"
|
||||
fi
|
||||
|
||||
echo "$columns"
|
||||
}
|
||||
|
||||
generate_rows() {
|
||||
|
||||
readarray -t addresses <<<"$(echo "$window_data" | jq -r '.[] | .address')"
|
||||
@@ -76,13 +56,9 @@ generate_rows() {
|
||||
readarray -t titles <<<$(echo "$window_data" | jq -r '.[] | .title')
|
||||
readarray -t workspaces <<<$(echo "$window_data" | jq -r '.[] | .workspace.name')
|
||||
|
||||
# Zip into a new comma separated values
|
||||
# Zip into rows.
|
||||
for i in "${!addresses[@]}"; do
|
||||
if [[ $show_window_class_flag == "1" ]]; then
|
||||
rows+=("${workspaces[i]} | ${titles[i]} | ${classes[i]} | ${addresses[i]}")
|
||||
else
|
||||
rows+=("${workspaces[i]} | ${titles[i]} | ${addresses[i]}")
|
||||
fi
|
||||
rows+=("${workspaces[i]}=>${titles[i]}=>${classes[i]}=>${addresses[i]}")
|
||||
done
|
||||
}
|
||||
|
||||
@@ -98,13 +74,14 @@ if [[ $uses_supplied_footer == "0" ]]; then
|
||||
fzf_opts+=("--footer=$(footer)")
|
||||
fi
|
||||
|
||||
if [[ $uses_supplied_header == "0" ]]; then
|
||||
fzf_opts+=("--header=$(header)")
|
||||
fi
|
||||
|
||||
generate_rows
|
||||
|
||||
sel=$(printf '%s\n' "${rows[@]}" | fzf --style=full "${fzf_opts[@]}")
|
||||
sel=$(
|
||||
printf '%s\n' "${rows[@]}" |
|
||||
fzf --style=full "${fzf_opts[@]}" \
|
||||
--preview-label='[ Window Stats ]' --delimiter='=>' --with-nth=2 \
|
||||
--preview='echo -e "Title: {2}\nClass: {3}\nWorkspace: {1}\nAddress: {4}"'
|
||||
)
|
||||
|
||||
[[ -z $sel ]] && exit 1
|
||||
|
||||
@@ -112,5 +89,5 @@ sel=$(printf '%s\n' "${rows[@]}" | fzf --style=full "${fzf_opts[@]}")
|
||||
sel=${sel//\"/}
|
||||
sel=${sel// /}
|
||||
# revove everything but the address portion.
|
||||
sel=${sel##*|}
|
||||
sel=${sel##*=>}
|
||||
echo "$sel"
|
||||
|
||||
Reference in New Issue
Block a user