mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 14:12:41 +00:00
68 lines
1.7 KiB
Bash
Executable File
68 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
|
THIS_FILE=${BASH_SOURCE[0]}
|
|
THIS=$(basename $THIS_FILE)
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
|
|
Utility for getting fzf preview data.
|
|
|
|
USAGE:
|
|
|
|
$ $THIS [MODE] [ARG...]
|
|
|
|
MODES:
|
|
|
|
monitor <id>: Get monitor data.
|
|
window <address>: Get window data.
|
|
workspace <id>: Get workspace data.
|
|
utlis <name> <config>: Get utils-launcher data.
|
|
|
|
EOF
|
|
}
|
|
|
|
# Logging utility function, use in place of echo.
|
|
log() {
|
|
logging log --source "$THIS_FILE" "$@"
|
|
}
|
|
|
|
################################################################################
|
|
# MAIN
|
|
################################################################################
|
|
|
|
# Setup logging file and label.
|
|
source "$SCRIPTS/hypr/logging"
|
|
setup-logging "$THIS"
|
|
|
|
if [[ ! ${#@} -ge 2 ]]; then
|
|
log --error "Unexpected argument count: ${#@}, expected at least: 2"
|
|
usage && exit 1
|
|
fi
|
|
|
|
mode="$1"
|
|
# Remove single quotes from the arg.
|
|
arg="${2//\'/}"
|
|
|
|
if [[ $mode == "monitor" ]]; then
|
|
hyprctl monitors -j | jq -C ".[] | select(.id == $arg)"
|
|
elif [[ $mode == "window" ]]; then
|
|
hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\")"
|
|
elif [[ $mode == "workspace" ]]; then
|
|
hyprctl workspaces -j | jq -C ".[] | select(.id == $arg)"
|
|
elif [[ $mode == "utils" ]]; then
|
|
config="${3//\'/}"
|
|
if [[ ! -f $config ]]; then
|
|
log --error "No utility-launcher config found: $config"
|
|
exit 1
|
|
fi
|
|
desc=$(jq -C ".[] | select(.name == \"$arg\") | .description" $config)
|
|
exec=$(jq -C ".[] | select(.name == \"$arg\") | .exec" $config)
|
|
echo -e "\n${desc[@]}\n\n"
|
|
echo -e "\e[31mEXEC:\e[0m $exec\n"
|
|
else
|
|
log --error "Unexpected mode: $mode"
|
|
usage && exit 1
|
|
fi
|