mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 14:12:41 +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"
|
||||
|
||||
20
env/.local/scripts/hypr/workspace-picker
vendored
20
env/.local/scripts/hypr/workspace-picker
vendored
@@ -32,7 +32,6 @@ EOF
|
||||
return_name_if_special_flag="0"
|
||||
return_name_flag="0"
|
||||
uses_supplied_footer="0"
|
||||
uses_supplied_header="0"
|
||||
|
||||
fzf_opts=()
|
||||
rows=()
|
||||
@@ -44,9 +43,6 @@ while [[ $# -gt 0 ]]; do
|
||||
return_name_flag="1"
|
||||
elif [[ $1 == "-s" ]] || [[ $1 == "--return-name-if-special" ]]; then
|
||||
return_name_if_special_flag="1"
|
||||
elif [[ $1 =~ ^--header ]]; then
|
||||
uses_supplied_header="1"
|
||||
fzf_opts+=("$1")
|
||||
elif [[ $1 =~ ^--footer ]]; then
|
||||
uses_supplied_footer="1"
|
||||
fzf_opts+=("$1")
|
||||
@@ -73,9 +69,11 @@ EOF
|
||||
generate_rows() {
|
||||
readarray -t names <<<"$(echo "$workspaces" | jq -r '.[] | .name')"
|
||||
readarray -t ids <<<"$(echo "$workspaces" | jq -r '.[] | .id')"
|
||||
readarray -t monitors <<<"$(echo "$workspaces" | jq -r '.[] | .monitor')"
|
||||
readarray -t windows <<<"$(echo "$workspaces" | jq -r '.[] | .windows')"
|
||||
|
||||
for i in "${!names[@]}"; do
|
||||
rows+=("${ids[i]} | ${names[i]}")
|
||||
rows+=("${ids[i]}|${monitors[i]}|${windows[i]}|${names[i]}")
|
||||
done
|
||||
}
|
||||
|
||||
@@ -93,19 +91,17 @@ if [[ $uses_supplied_footer == "0" ]]; then
|
||||
fzf_opts+=("--footer=$(footer)")
|
||||
fi
|
||||
|
||||
if [[ $uses_supplied_header == "0" ]]; then
|
||||
fzf_opts+=("--header=Id | Name")
|
||||
fi
|
||||
|
||||
sel=$(
|
||||
printf "%s\n" "${rows[@]}" |
|
||||
fzf --style=full "${fzf_opts[@]}"
|
||||
fzf --style=full "${fzf_opts[@]}" \
|
||||
--delimiter='|' --with-nth=4 --preview-label='[ Workspace Stats ]' \
|
||||
--preview='printf "Name: {4}\nID: {1}\nWindows: {2}\nMonitor: {3}"'
|
||||
)
|
||||
|
||||
[[ -z $sel ]] && exit 1
|
||||
|
||||
name=${sel##*| }
|
||||
id=${sel% |*}
|
||||
name=${sel##*\|}
|
||||
id=${sel%%\|*}
|
||||
|
||||
if [[ $return_name_flag == "1" ]] ||
|
||||
([[ $return_name_if_special_flag == "1" ]] && [[ $name =~ ^special ]]); then
|
||||
|
||||
Reference in New Issue
Block a user