mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
feat: Removes files from scripts/hypr that are now integrated into windowctl.
This commit is contained in:
147
env/.local/scripts/hypr/close-windows
vendored
147
env/.local/scripts/hypr/close-windows
vendored
@@ -1,147 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
# FIX: Fix args not set error, to be able to use this option.
|
||||
#set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
THIS_FILE=${BASH_SOURCE[0]}
|
||||
# Allows script name to be set when called from a parent script or defaults to filename.
|
||||
THIS=${THIS:-$(basename "$THIS_FILE")}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
Close window(s) by address or pattern mode.
|
||||
|
||||
USAGE:
|
||||
$ $THIS [OPTIONS] [MODE] [ARG...]
|
||||
|
||||
MODE:
|
||||
--all: Close all windows in all workspaces, any arguments are ignored.
|
||||
|
||||
-a | --active-workspace: Close all windows in the active workspace, any arguments are ignored.
|
||||
|
||||
-c | --class: Close all windows whose class contains one of the passed arguments.
|
||||
|
||||
-s | --special: Close all windows in special workspaces whose name matches on of the
|
||||
passed in arguments, or if no arguments are supplied then it will close
|
||||
all windows in all special workspaces.
|
||||
OPTIONS:
|
||||
--dry-run
|
||||
-h | --help: Show this help page.
|
||||
|
||||
NOTES:
|
||||
|
||||
If a mode is selected all arguments are treated for that mode, meaning only one mode
|
||||
runs. It does not work to mix modes / arguments.
|
||||
|
||||
If no modes are supplied then arguments are assumed to be window addresses and we will
|
||||
close all supplied window addresses.
|
||||
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
active_workspace_flag="0"
|
||||
all_flag="0"
|
||||
class_flag="0"
|
||||
dry_run_flag="0"
|
||||
special_flag="0"
|
||||
declare -a args=()
|
||||
declare -a addresses=()
|
||||
SCRIPTS="${SCRIPTS:-$HOME/.local/scripts}"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 =~ ^-a ]] || [[ $1 =~ ^--active-workspace ]]; then
|
||||
active_workspace_flag="1"
|
||||
elif [[ $1 =~ ^--all ]]; then
|
||||
all_flag="1"
|
||||
elif [[ $1 =~ ^-c ]] || [[ $1 =~ ^--class ]]; then
|
||||
class_flag="1"
|
||||
elif [[ $1 =~ ^--dry-run ]]; then
|
||||
dry_run_flag="1"
|
||||
elif [[ $1 =~ ^-h ]] || [[ $1 =~ ^--help ]]; then
|
||||
usage && exit 0
|
||||
elif [[ $1 =~ ^-s ]] || [[ $1 =~ ^--special ]]; then
|
||||
special_flag="1"
|
||||
else
|
||||
args+=("$1")
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
log() {
|
||||
logging log --source "$THIS_FILE" "$@"
|
||||
}
|
||||
|
||||
_select_addresses() {
|
||||
local property=$1
|
||||
local pattern=$2
|
||||
addresses+=("$(hyprctl clients -j | jq -r ".[] | select($property | contains(\"$pattern\")) | .address")")
|
||||
}
|
||||
|
||||
get_special_addresses() {
|
||||
|
||||
# If no arguments, then we add the "special" to the pattern args, which will
|
||||
# match all windows in any special workspace.
|
||||
# if [[ ${#args} == 0 ]]; then
|
||||
# args+=("special")
|
||||
# fi
|
||||
|
||||
for name in ${args[@]}; do
|
||||
log "Fetching addresses for special: $name"
|
||||
_select_addresses .workspace.name $name
|
||||
done
|
||||
}
|
||||
|
||||
close() {
|
||||
log "Closing window address: $1"
|
||||
if [[ $dry_run_flag == "0" ]]; then
|
||||
hyprctl dispatch closewindow "address:$1" >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
# Setup logging file and label
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "/tmp/$THIS.log" "$THIS"
|
||||
export LOG_ENABLE_DRY_RUN="$dry_run_flag"
|
||||
|
||||
if [[ $active_workspace_flag == "1" ]]; then
|
||||
# Set addresses to active workspace windows.
|
||||
id=$(hyprctl activeworkspace -j | jq -r '.id')
|
||||
log "Fetching addresses for active workspace: $id"
|
||||
addresses+=("$(hyprctl clients -j | jq -r ".[] | select(.workspace.id == $id) | .address")")
|
||||
|
||||
elif [[ $all_flag == "1" ]]; then
|
||||
# Set addresses to all window addresses.
|
||||
addresses+=("$(hyprctl clients -j | jq -r ".[] | .address")")
|
||||
|
||||
elif [[ $class_flag == "1" ]]; then
|
||||
# Set addresses to all windows containing the passed in classes.
|
||||
for c in ${args[@]}; do
|
||||
_select_addresses .class $c
|
||||
done
|
||||
|
||||
elif [[ $special_flag == "1" ]]; then
|
||||
|
||||
# Set addresses to all windows in the passed in special workspaces.
|
||||
get_special_addresses
|
||||
|
||||
elif [[ -n $args ]]; then
|
||||
# If no modes selected, then assume there were addresses passed in
|
||||
# as args.
|
||||
addresses=$args
|
||||
fi
|
||||
|
||||
# If no addresses at this point, then read from stdin, which allows addresses
|
||||
# to be piped in.
|
||||
if [[ ${#addresses} == 0 ]]; then
|
||||
log "No window addresses supplied, reading from stdin..."
|
||||
read -r addresses
|
||||
log "Addresses: ${addresses[@]}"
|
||||
fi
|
||||
|
||||
for address in ${addresses[@]}; do
|
||||
close $address
|
||||
done
|
||||
86
env/.local/scripts/hypr/window-picker
vendored
86
env/.local/scripts/hypr/window-picker
vendored
@@ -1,86 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
THIS=$(basename ${BASH_SOURCE[0]})
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
Select from currently available windows.
|
||||
|
||||
USAGE:
|
||||
|
||||
$ $THIS [OPTIONS] [ARGS...]
|
||||
|
||||
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)')
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 =~ ^--footer ]]; then
|
||||
uses_supplied_footer="1"
|
||||
fzf_opts+=("$1")
|
||||
else
|
||||
fzf_opts+=("$1")
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
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
|
||||
################################################################################
|
||||
|
||||
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/preview-stats window {1}"
|
||||
)
|
||||
status=$?
|
||||
|
||||
[[ -z $sel ]] && exit 1
|
||||
|
||||
# revove everything but the address portion.
|
||||
sel=${sel%%|*}
|
||||
echo "$sel"
|
||||
exit $status
|
||||
27
env/.local/scripts/hypr/window-toggle-floating
vendored
27
env/.local/scripts/hypr/window-toggle-floating
vendored
@@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Float's a window, setting it's height and width and centering.
|
||||
|
||||
# The percentage of the screen size for the floating window.
|
||||
WIDTH_PERCENT=80
|
||||
HEIGHT_PERCENT=40
|
||||
|
||||
floating=$(hyprctl activewindow -j | jq '.floating')
|
||||
|
||||
if [ "$floating" = "true" ]; then
|
||||
hyprctl dispatch togglefloating
|
||||
else
|
||||
monitor=$(hyprctl monitors -j | jq '.[] | select(.focused == true)')
|
||||
mw=$(echo "$monitor" | jq '.width')
|
||||
mh=$(echo "$monitor" | jq '.height')
|
||||
ms=$(echo "$monitor" | jq '.scale')
|
||||
|
||||
echo "scale: $ms"
|
||||
|
||||
neww=$(echo "scale=6; (($mw / $ms) * $WIDTH_PERCENT / 100)" | bc)
|
||||
newh=$(echo "scale=6; (($mh / $ms) * $HEIGHT_PERCENT / 100)" | bc)
|
||||
|
||||
hyprctl dispatch togglefloating &&
|
||||
hyprctl dispatch resizeactive exact $neww $newh &&
|
||||
hyprctl dispatch centerwindow
|
||||
fi
|
||||
Reference in New Issue
Block a user