mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-17 07:32:37 +00:00
Compare commits
4 Commits
78e40a9401
...
7024182f49
| Author | SHA1 | Date | |
|---|---|---|---|
|
7024182f49
|
|||
|
7aec9d1610
|
|||
|
5946a177fb
|
|||
|
7c08fec16b
|
29
env/.local/scripts/hypr/close-windows
vendored
29
env/.local/scripts/hypr/close-windows
vendored
@@ -1,5 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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]}
|
THIS_FILE=${BASH_SOURCE[0]}
|
||||||
# Allows script name to be set when called from a parent script or defaults to filename.
|
# Allows script name to be set when called from a parent script or defaults to filename.
|
||||||
THIS=${THIS:-$(basename "$THIS_FILE")}
|
THIS=${THIS:-$(basename "$THIS_FILE")}
|
||||||
@@ -43,8 +48,8 @@ all_flag="0"
|
|||||||
class_flag="0"
|
class_flag="0"
|
||||||
dry_run_flag="0"
|
dry_run_flag="0"
|
||||||
special_flag="0"
|
special_flag="0"
|
||||||
args=()
|
declare -a args=()
|
||||||
addresses=()
|
declare -a addresses=()
|
||||||
SCRIPTS="${SCRIPTS:-$HOME/.local/scripts}"
|
SCRIPTS="${SCRIPTS:-$HOME/.local/scripts}"
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@@ -61,7 +66,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
elif [[ $1 =~ ^-s ]] || [[ $1 =~ ^--special ]]; then
|
elif [[ $1 =~ ^-s ]] || [[ $1 =~ ^--special ]]; then
|
||||||
special_flag="1"
|
special_flag="1"
|
||||||
else
|
else
|
||||||
args+=($1)
|
args+=("$1")
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
@@ -80,9 +85,9 @@ get_special_addresses() {
|
|||||||
|
|
||||||
# If no arguments, then we add the "special" to the pattern args, which will
|
# If no arguments, then we add the "special" to the pattern args, which will
|
||||||
# match all windows in any special workspace.
|
# match all windows in any special workspace.
|
||||||
if [[ ${#args} == 0 ]]; then
|
# if [[ ${#args} == 0 ]]; then
|
||||||
args+=("special")
|
# args+=("special")
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
for name in ${args[@]}; do
|
for name in ${args[@]}; do
|
||||||
log "Fetching addresses for special: $name"
|
log "Fetching addresses for special: $name"
|
||||||
@@ -119,18 +124,22 @@ elif [[ $class_flag == "1" ]]; then
|
|||||||
done
|
done
|
||||||
|
|
||||||
elif [[ $special_flag == "1" ]]; then
|
elif [[ $special_flag == "1" ]]; then
|
||||||
|
|
||||||
# Set addresses to all windows in the passed in special workspaces.
|
# Set addresses to all windows in the passed in special workspaces.
|
||||||
get_special_addresses
|
get_special_addresses
|
||||||
|
|
||||||
else
|
elif [[ -n $args ]]; then
|
||||||
# If no modes selected, then assume there were addresses passed in
|
# If no modes selected, then assume there were addresses passed in
|
||||||
# as args.
|
# as args.
|
||||||
addresses=("$args")
|
addresses=$args
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If no addresses at this point, then read from stdin, which allows addresses
|
||||||
|
# to be piped in.
|
||||||
if [[ ${#addresses} == 0 ]]; then
|
if [[ ${#addresses} == 0 ]]; then
|
||||||
log --warning "No windows found."
|
log "No window addresses supplied, reading from stdin..."
|
||||||
exit 0
|
read -r addresses
|
||||||
|
log "Addresses: ${addresses[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for address in ${addresses[@]}; do
|
for address in ${addresses[@]}; do
|
||||||
|
|||||||
6
env/.local/scripts/hypr/logging
vendored
6
env/.local/scripts/hypr/logging
vendored
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
LOG_FILE=(${LOG_FILE:-})
|
LOG_FILE=(${LOG_FILE:-})
|
||||||
LOG_INVOCATION_ID=${LOG_INVOCATION_ID:-}
|
LOG_INVOCATION_ID=${LOG_INVOCATION_ID:-}
|
||||||
LOG_LABEL=(${LOG_LABEL:-})
|
LOG_LABEL=${LOG_LABEL:-()}
|
||||||
# Run in dry run mode, which just prints to the console and does
|
# Run in dry run mode, which just prints to the console and does
|
||||||
# not log to the files.
|
# not log to the files.
|
||||||
LOG_ENABLE_DRY_RUN=${LOG_ENABLE_DRY_RUN:-"0"}
|
LOG_ENABLE_DRY_RUN=${LOG_ENABLE_DRY_RUN:-"0"}
|
||||||
@@ -111,7 +111,7 @@ logging() {
|
|||||||
|
|
||||||
# Also log errors and warning messages to the console.
|
# Also log errors and warning messages to the console.
|
||||||
if [[ $error_flag == "1" ]] || [[ $warn_flag == "1" ]]; then
|
if [[ $error_flag == "1" ]] || [[ $warn_flag == "1" ]]; then
|
||||||
echo -e "[id: $LOG_INVOCATION_ID]: $msg"
|
echo -e "[id: $LOG_INVOCATION_ID]$msg"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Dry run mode, so just log to the console
|
# Dry run mode, so just log to the console
|
||||||
@@ -144,7 +144,7 @@ setup-logging() {
|
|||||||
LOG_FILE+=("$file")
|
LOG_FILE+=("$file")
|
||||||
LOG_INVOCATION_ID=${LOG_INVOCATION_ID:-$RANDOM}
|
LOG_INVOCATION_ID=${LOG_INVOCATION_ID:-$RANDOM}
|
||||||
|
|
||||||
if [[ -n "$LOG_LABEL" ]]; then
|
if [[ -n $LOG_LABEL ]]; then
|
||||||
LOG_LABEL+=("${LOG_LABEL[@]}=>$label")
|
LOG_LABEL+=("${LOG_LABEL[@]}=>$label")
|
||||||
else
|
else
|
||||||
LOG_LABEL+=("$label")
|
LOG_LABEL+=("$label")
|
||||||
|
|||||||
48
env/.local/scripts/hypr/preview-stats
vendored
48
env/.local/scripts/hypr/preview-stats
vendored
@@ -15,11 +15,17 @@ USAGE:
|
|||||||
|
|
||||||
MODES:
|
MODES:
|
||||||
|
|
||||||
monitor <id>: Get monitor data.
|
monitor <id> <keys>: Get monitor data, optionally providing keys to return.
|
||||||
window <address>: Get window data.
|
window <address> <keys>: Get window data, optionally providing keys to return.
|
||||||
workspace <id>: Get workspace data.
|
workspace <id> <keys>: Get workspace data, optionally providing keys to return.
|
||||||
utlis <name> <config>: Get utils-launcher data.
|
utlis <name> <config>: Get utils-launcher data.
|
||||||
|
|
||||||
|
EXAMPLE:
|
||||||
|
|
||||||
|
Here's an example of getting window data, but only returning "title", "workspace", and "address".
|
||||||
|
|
||||||
|
$ $THIS window "0xaaaaea92a7e0" "{title, workspace, address}"
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +34,18 @@ log() {
|
|||||||
logging log --source "$THIS_FILE" "$@"
|
logging log --source "$THIS_FILE" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
call_jq() {
|
||||||
|
hypr_path=$1
|
||||||
|
select_str=$2
|
||||||
|
optional_keys=$3
|
||||||
|
|
||||||
|
if [[ -n $optional_keys ]]; then
|
||||||
|
hyprctl $hypr_path -j | jq -C ".[] | $select_str | $optional_keys"
|
||||||
|
else
|
||||||
|
hyprctl $hypr_path -j | jq -C ".[] | $select_str"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# MAIN
|
# MAIN
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -36,23 +54,27 @@ log() {
|
|||||||
source "$SCRIPTS/hypr/logging"
|
source "$SCRIPTS/hypr/logging"
|
||||||
setup-logging "$THIS"
|
setup-logging "$THIS"
|
||||||
|
|
||||||
if [[ ! ${#@} -ge 2 ]]; then
|
# Early out check for help flag
|
||||||
log --error "Unexpected argument count: ${#@}, expected at least: 2"
|
if [[ $@ =~ -h ]] || [[ $@ =~ --help ]]; then
|
||||||
usage && exit 1
|
usage && exit 0
|
||||||
|
# Check for expected argument count or error.
|
||||||
|
elif [[ ! $# -ge 2 ]] || [[ $# -gt 3 ]]; then
|
||||||
|
log --error "Unexpected argument count, expected 2 or 3 but got '$#'"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mode="$1"
|
mode=$1
|
||||||
# Remove single quotes from the arg.
|
arg=$2
|
||||||
arg="${2//\'/}"
|
arg2=$3 # either optional keys or utils config.
|
||||||
|
|
||||||
if [[ $mode == "monitor" ]]; then
|
if [[ $mode == "monitor" ]]; then
|
||||||
hyprctl monitors -j | jq -C ".[] | select(.id == $arg)"
|
call_jq monitors "select(.id == $arg)" "$arg2"
|
||||||
elif [[ $mode == "window" ]]; then
|
elif [[ $mode == "window" ]]; then
|
||||||
hyprctl clients -j | jq -C ".[] | select(.address == \"$arg\")"
|
call_jq clients "select(.address == \"$arg\")" "$arg2"
|
||||||
elif [[ $mode == "workspace" ]]; then
|
elif [[ $mode == "workspace" ]]; then
|
||||||
hyprctl workspaces -j | jq -C ".[] | select(.id == $arg)"
|
call_jq workspaces "select(.id == $arg)" "$arg2"
|
||||||
elif [[ $mode == "utils" ]]; then
|
elif [[ $mode == "utils" ]]; then
|
||||||
config="${3//\'/}"
|
config="${arg2//\'/}"
|
||||||
if [[ ! -f $config ]]; then
|
if [[ ! -f $config ]]; then
|
||||||
log --error "No utility-launcher config found: $config"
|
log --error "No utility-launcher config found: $config"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
164
env/.local/scripts/hypr/utils/windows/window-action-picker
vendored
Executable file
164
env/.local/scripts/hypr/utils/windows/window-action-picker
vendored
Executable file
@@ -0,0 +1,164 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||||
|
THIS_FILE=${BASH_SOURCE[0]}
|
||||||
|
LOG_LABEL=$(basename "$THIS_FILE")
|
||||||
|
THIS=${THIS:-$LOG_LABEL}
|
||||||
|
|
||||||
|
address=""
|
||||||
|
move_silent_flag="0"
|
||||||
|
should_go_back="0"
|
||||||
|
|
||||||
|
if [[ $# == 1 ]]; then
|
||||||
|
address="$1"
|
||||||
|
else
|
||||||
|
# If an address not supplied then read from stdin, which allows us to pipe into
|
||||||
|
# this command.
|
||||||
|
read -r address
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Logging utility function, use in place of echo.
|
||||||
|
log() {
|
||||||
|
logging log --source "$THIS_FILE" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
action_footer() {
|
||||||
|
cat <<'EOF'
|
||||||
|
___ __ _
|
||||||
|
/ _ |____/ /_(_)__ ___
|
||||||
|
/ __ / __/ __/ / _ \/ _ \
|
||||||
|
/_/ |_\__/\__/_/\___/_//_/
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prevent hyprctl dispatch calls from printing to the console.
|
||||||
|
hypr_dispatch() {
|
||||||
|
hyprctl dispatch "$@" >/dev/null 2>&1
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
focus_window() {
|
||||||
|
log "Focusing window, selection: $address"
|
||||||
|
local name=$(hyprctl clients -j | jq -r ".[] | select(.address == \"$address\") | .workspace.name")
|
||||||
|
local active_workspace=$(hyprctl activewindow -j | jq -r ".workspace.name")
|
||||||
|
log "Window workspace: '$name', active workspace: '$active_workspace'"
|
||||||
|
if [[ $name =~ ^special ]] && [[ ! $active_workspace == $name ]]; then
|
||||||
|
log "Toggling special workspace prior to focusing window."
|
||||||
|
name="${name#special:*}"
|
||||||
|
hypr_dispatch togglespecialworkspace $name
|
||||||
|
fi
|
||||||
|
hypr_dispatch focuswindow "address:$address"
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_workspace_id() {
|
||||||
|
local workspace_name=""
|
||||||
|
read -r workspace_name
|
||||||
|
|
||||||
|
log "Parsing selected workspace name: $workspace_name"
|
||||||
|
|
||||||
|
if [[ -z $workspace_name ]]; then
|
||||||
|
log --error "No workspace set to move window to."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $workspace_name =~ ^special ]]; then
|
||||||
|
log "Special workspace, returning name."
|
||||||
|
echo $workspace_name
|
||||||
|
else
|
||||||
|
local id="$(hyprctl workspaces -j | jq -r ".[] | select(.name | contains(\"$workspace_name\")) | .id")"
|
||||||
|
log "Selected workspace id: $id"
|
||||||
|
echo "$id"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
move_to_workspace() {
|
||||||
|
|
||||||
|
log "Moving window: '$address'"
|
||||||
|
log "Prompting for workspace to move to..."
|
||||||
|
|
||||||
|
local action="movetoworkspace"
|
||||||
|
if [[ $move_silent_flag == "1" ]]; then
|
||||||
|
action="movetoworkspacesilent"
|
||||||
|
fi
|
||||||
|
|
||||||
|
$SCRIPTS/hypr/workspace-picker --return-name-if-special --header="Select a workspace to move window to:" |
|
||||||
|
parse_workspace_id |
|
||||||
|
xargs -I{} hyprctl dispatch "$action" "{},address:$address" >/dev/null 2>&1
|
||||||
|
|
||||||
|
return $?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# MAIN
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# Setup logging file and label.
|
||||||
|
source "$SCRIPTS/hypr/logging"
|
||||||
|
setup-logging "$LOG_LABEL"
|
||||||
|
|
||||||
|
if [[ -z $address ]]; then
|
||||||
|
log --error "Address not set."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
log "Prompting for window action..."
|
||||||
|
|
||||||
|
choices=(
|
||||||
|
"Focus the selected window.:Focus window"
|
||||||
|
"Close the selected window.:Close window"
|
||||||
|
"Close the selected window and go back to the window list.:Close window and back"
|
||||||
|
"Move the selected window to another workspace, focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace"
|
||||||
|
"Move the selected window to another workspace, without focusing the window.\n\nA workspace picker will be presented to choose which workspace to move to.:Move to workspace - silent"
|
||||||
|
"Copy the window address to the system clipboard:Copy to clipboard"
|
||||||
|
"Move back to window picker and reload windows.:Back"
|
||||||
|
"Quit:Quit"
|
||||||
|
)
|
||||||
|
preview_action="$SCRIPTS/hypr/preview-stats window $address \"{title, workspace, address}\""
|
||||||
|
choice=$(
|
||||||
|
printf "%s\n" "${choices[@]}" |
|
||||||
|
fzf --style=full --footer="$(action_footer)" \
|
||||||
|
--delimiter=':' --with-nth=2 \
|
||||||
|
--header="What should we do with the selected window?" \
|
||||||
|
--preview-label="[ Description ]" \
|
||||||
|
--preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $preview_action;"
|
||||||
|
)
|
||||||
|
if [[ $? -gt 0 ]]; then
|
||||||
|
log --error "Unexpected fzf status: $?"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set choice to just the action portion.
|
||||||
|
choice="${choice#*:}"
|
||||||
|
log "Action Choice: $choice"
|
||||||
|
|
||||||
|
# Set appropriate flags based on the choice and perform the action on the window address.
|
||||||
|
if [[ $choice == "Quit" ]]; then
|
||||||
|
exit 0
|
||||||
|
elif [[ $choice == "Close window" ]]; then
|
||||||
|
"$SCRIPTS/hypr/close-windows" "$address"
|
||||||
|
elif [[ $choice == "Close window and back" ]]; then
|
||||||
|
"$SCRIPTS/hypr/close-windows" "$address"
|
||||||
|
should_go_back="1"
|
||||||
|
elif [[ $choice == "Copy to clipboard" ]]; then
|
||||||
|
echo $address | wl-copy
|
||||||
|
elif [[ $choice == "Focus window" ]]; then
|
||||||
|
focus_window
|
||||||
|
elif [[ $choice == "Move to workspace" ]]; then
|
||||||
|
move_to_workspace
|
||||||
|
elif [[ $choice == "Move to workspace - silent" ]]; then
|
||||||
|
move_silent_flag="1"
|
||||||
|
move_to_workspace
|
||||||
|
elif [[ $choice == "Back" ]]; then
|
||||||
|
should_go_back="1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# TODO: Maybe we just echo out a 'back' message.
|
||||||
|
if [[ $should_go_back == "1" ]]; then
|
||||||
|
exit 69
|
||||||
|
fi
|
||||||
2
env/.local/scripts/hypr/windowctl
vendored
2
env/.local/scripts/hypr/windowctl
vendored
@@ -143,7 +143,7 @@ ask_what_to_do_with_selection() {
|
|||||||
--delimiter=':' --with-nth=2 \
|
--delimiter=':' --with-nth=2 \
|
||||||
--header="What should we do with the selected window?" \
|
--header="What should we do with the selected window?" \
|
||||||
--preview-label="[ Description ]" \
|
--preview-label="[ Description ]" \
|
||||||
--preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $SCRIPTS/hypr/preview-stats window $selected_value;"
|
--preview="echo -e {1}; echo -e '\n\n\e[35mSelected Window:\e[0m'; $SCRIPTS/hypr/preview-stats window $selected_value \"{title, workspace, address}\";"
|
||||||
)
|
)
|
||||||
# Set choice to just the action portion.
|
# Set choice to just the action portion.
|
||||||
choice="${choice#*:}"
|
choice="${choice#*:}"
|
||||||
|
|||||||
Reference in New Issue
Block a user