mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 22:22:40 +00:00
feat: Moves window and workspace pickers to their own scripts.
This commit is contained in:
115
env/.local/scripts/hypr/workspace-picker
vendored
Executable file
115
env/.local/scripts/hypr/workspace-picker
vendored
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
THIS=$(basename ${BASH_SOURCE[0]})
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
Select from currently available workspaces.
|
||||
|
||||
If no options are specified, then the default behavior is to return the selected workspace id.
|
||||
|
||||
USAGE:
|
||||
|
||||
$ $THIS [OPTIONS] [ARGS...]
|
||||
|
||||
OPTIONS:
|
||||
|
||||
-n | --return-name: Return workspace name instead of id.
|
||||
|
||||
-s | --return-name-if-special: Return name if a special workspace, otherwise return the id.
|
||||
This option is useful when moving a workspace using 'hyprctl' with
|
||||
the selection.
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
return_name_if_special_flag="0"
|
||||
return_name_flag="0"
|
||||
uses_supplied_footer="0"
|
||||
uses_supplied_header="0"
|
||||
|
||||
fzf_opts=()
|
||||
rows=()
|
||||
workspaces=$(hyprctl workspaces -j | jq 'sort_by(.id)')
|
||||
SCRIPTS=${SCRIPTS}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-n" ]] || [[ $1 == "--return-name" ]]; then
|
||||
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")
|
||||
else
|
||||
fzf_opts+=("$1")
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -z $SCRIPTS ]]; then
|
||||
SCRIPTS=$HOME/.local/scripts
|
||||
fi
|
||||
|
||||
footer() {
|
||||
cat <<'EOF'
|
||||
_ __ __
|
||||
| | /| / /__ ____/ /__ ___ ___ ___ ________ ___
|
||||
| |/ |/ / _ \/ __/ '_/(_-</ _ \/ _ `/ __/ -_|_-<
|
||||
|__/|__/\___/_/ /_/\_\/___/ .__/\_,_/\__/\__/___/
|
||||
/_/
|
||||
EOF
|
||||
}
|
||||
|
||||
generate_rows() {
|
||||
readarray -t names <<<"$(echo "$workspaces" | jq -r '.[] | .name')"
|
||||
readarray -t ids <<<"$(echo "$workspaces" | jq -r '.[] | .id')"
|
||||
|
||||
for i in "${!names[@]}"; do
|
||||
rows+=("${ids[i]} | ${names[i]}")
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
[[ -z ${FZF_DEFAULT_OPTS} ]] &&
|
||||
[[ -f $SCRIPTS/catppuccin-colors ]] &&
|
||||
source $SCRIPTS/catppuccin-colors
|
||||
|
||||
generate_rows
|
||||
|
||||
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[@]}"
|
||||
)
|
||||
|
||||
[[ -z $sel ]] && exit 1
|
||||
|
||||
name=${sel##*| }
|
||||
id=${sel% |*}
|
||||
|
||||
if [[ $return_name_flag == "1" ]] ||
|
||||
([[ $return_name_if_special_flag == "1" ]] && [[ $name =~ ^special ]]); then
|
||||
echo "$name" && exit 0
|
||||
fi
|
||||
|
||||
echo "$id"
|
||||
Reference in New Issue
Block a user