aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorDon Williams <don.e.williams@gmail.com>2025-11-26 09:37:58 -0500
committerDon Williams <don.e.williams@gmail.com>2025-11-26 09:37:58 -0500
commitd13effd33c992b594ab4967e83fe4355732f49cb (patch)
treeff5cdfe4243dd4139d0d8f7ae5e64744add41fa3 /config
parentf01c8c736d0be75aa6dcb6068b045cfb12724054 (diff)
KeyBinds.sh checks sys and user keybinds and flags dups
Diffstat (limited to 'config')
-rwxr-xr-xconfig/hypr/scripts/KeyBinds.sh84
1 files changed, 81 insertions, 3 deletions
diff --git a/config/hypr/scripts/KeyBinds.sh b/config/hypr/scripts/KeyBinds.sh
index 46953cc5..c2aa56b7 100755
--- a/config/hypr/scripts/KeyBinds.sh
+++ b/config/hypr/scripts/KeyBinds.sh
@@ -21,9 +21,87 @@ msg='☣️ NOTE ☣️: Clicking with Mouse or Pressing ENTER will have NO func
files=("$keybinds_conf" "$user_keybinds_conf")
[[ -f "$laptop_conf" ]] && files+=("$laptop_conf")
-raw_keybinds=$(cat "${files[@]}" 2>/dev/null \
- | grep -E '^[[:space:]]*bind' \
- | sed -E 's/[[:space:]]+#.*$//')
+# Parse binds/unbinds from files, detect overrides, and keep unique effective binds
+declare -A binding_map # combo -> bind line (effective)
+declare -A source_map # combo -> source file
+declare -A user_bind_map # combo -> user bind line
+declare -A unbound_user # combo -> 1 if explicitly unbound in user file
+declare -A seen_any_bind # combo -> 1 if any bind seen (for iteration)
+declare -A default_seen # combo -> 1 if default bind exists
+declare -a missing_unbind_suggestions_arr
+
+normalize_combo() { echo "$1" | sed -E 's/[[:space:]]//g'; }
+
+extract_combo() {
+ # arg: a bind/unbind line; returns "mods,key" via echo
+ local s="$1"
+ s="$(echo "$s" | sed -E 's/[[:space:]]+#.*$//')"
+ if [[ "$s" =~ = ]]; then
+ local rhs="${s#*=}"
+ local mods="$(echo "$rhs" | awk -F',' '{gsub(/^[ \t]+|[ \t]+$/,"",$1); print $1}')"
+ local key="$(echo "$rhs" | awk -F',' '{gsub(/^[ \t]+|[ \t]+$/,"",$2); print $2}')"
+ echo "${mods},${key}"
+ fi
+}
+
+for file in "${files[@]}"; do
+ [[ ! -f "$file" ]] && continue
+ while IFS= read -r line; do
+ [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
+
+ if [[ "$line" =~ ^[[:space:]]*bind[a-z]*[[:space:]]*= ]]; then
+ combo_raw="$(extract_combo "$line")"
+ [[ -z "$combo_raw" ]] && continue
+ combo="$(normalize_combo "$combo_raw")"
+ seen_any_bind["$combo"]=1
+
+ if [[ "$file" != "$user_keybinds_conf" ]]; then
+ default_seen["$combo"]=1
+ fi
+
+ # prefer user bind, else first seen
+ if [[ -z "${source_map[$combo]}" ]]; then
+ binding_map["$combo"]="$line"
+ source_map["$combo"]="$file"
+ fi
+ if [[ "$file" == "$user_keybinds_conf" ]]; then
+ user_bind_map["$combo"]="$line"
+ binding_map["$combo"]="$line"
+ source_map["$combo"]="$file"
+ fi
+
+ elif [[ "$line" =~ ^[[:space:]]*unbind[[:space:]]*= ]]; then
+ combo_raw="$(extract_combo "$line")"
+ [[ -z "$combo_raw" ]] && continue
+ combo="$(normalize_combo "$combo_raw")"
+ if [[ "$file" == "$user_keybinds_conf" ]]; then
+ unbound_user["$combo"]=1
+ fi
+ fi
+ done < "$file"
+done
+
+# Build raw_keybinds for display and collect missing unbind suggestions
+raw_keybinds=""
+for combo in "${!seen_any_bind[@]}"; do
+ eff_line="${binding_map[$combo]}"
+ src="${source_map[$combo]}"
+ [[ -z "$eff_line" ]] && continue
+ raw_keybinds+="$eff_line"$'\n'
+
+ # If user overrides a default but didn't unbind in user file, suggest unbind
+ if [[ "$src" == "$user_keybinds_conf" && -n "${default_seen[$combo]}" && -z "${unbound_user[$combo]}" ]]; then
+ suggest="$(echo "$eff_line" | sed -E 's/^[[:space:]]*bind[a-z]*/unbind/')"
+ missing_unbind_suggestions_arr+=("$suggest")
+ fi
+done
+
+# If there are missing unbinds, write suggestions to a temp file and note in message
+if (( ${#missing_unbind_suggestions_arr[@]} > 0 )); then
+ suggestions_file="$(mktemp -t hypr-unbind-suggestions.XXXX.conf)"
+ printf '%s\n' "${missing_unbind_suggestions_arr[@]}" > "$suggestions_file"
+ msg="$msg | Overrides missing unbind: ${#missing_unbind_suggestions_arr[@]} (suggestions: $suggestions_file)"
+fi
# check for any keybinds to display
if [[ -z "$raw_keybinds" ]]; then
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage