diff options
| author | Martin Guzman <55927935+brockar@users.noreply.github.com> | 2025-11-22 13:42:39 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-22 13:42:39 -0300 |
| commit | bcfd5e7c2b67f0a62b1ceeb62d20b0a80ca55a70 (patch) | |
| tree | e87f649fe0c9d8f382b8f465d1468b6495fb5886 /config/hypr/scripts/KeyBinds.sh | |
| parent | c862835221decf03b6640bb43e4044861cceaa04 (diff) | |
| parent | 1351220a092414ae593bc006e3a3ebc09523198d (diff) | |
Merge pull request #871 from JaKooLit/development
[Bug] Change to waybar sleep timers was too long, slowed down waybar start/refressh
Diffstat (limited to 'config/hypr/scripts/KeyBinds.sh')
| -rwxr-xr-x | config/hypr/scripts/KeyBinds.sh | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/config/hypr/scripts/KeyBinds.sh b/config/hypr/scripts/KeyBinds.sh index 9c6b5ab7..46953cc5 100755 --- a/config/hypr/scripts/KeyBinds.sh +++ b/config/hypr/scripts/KeyBinds.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash # /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ## -# searchable enabled keybinds using rofi +# searchable enabled keybinds using rofi (supports bindd descriptions) # kill yad to not interfere with this binds pkill yad || true @@ -17,23 +17,66 @@ laptop_conf="$HOME/.config/hypr/UserConfigs/Laptops.conf" rofi_theme="$HOME/.config/rofi/config-keybinds.rasi" msg='☣️ NOTE ☣️: Clicking with Mouse or Pressing ENTER will have NO function' -# combine the contents of the keybinds files and filter for keybinds -keybinds=$(cat "$keybinds_conf" "$user_keybinds_conf" | grep -E '^bind') +# collect raw bind lines (strip end-of-line comments) from available files +files=("$keybinds_conf" "$user_keybinds_conf") +[[ -f "$laptop_conf" ]] && files+=("$laptop_conf") -# check if laptop.conf exists and add its keybinds if present -if [[ -f "$laptop_conf" ]]; then - laptop_binds=$(grep -E '^bind' "$laptop_conf") - keybinds+=$'\n'"$laptop_binds" -fi +raw_keybinds=$(cat "${files[@]}" 2>/dev/null \ + | grep -E '^[[:space:]]*bind' \ + | sed -E 's/[[:space:]]+#.*$//') # check for any keybinds to display -if [[ -z "$keybinds" ]]; then +if [[ -z "$raw_keybinds" ]]; then echo "no keybinds found." exit 1 fi -# replace $mainmod with super in the displayed keybinds for rofi -display_keybinds=$(echo "$keybinds" | sed 's/\$mainMod/SUPER/g') +# transform into a readable list: MODS+KEY — DESCRIPTION — DISPATCHER [PARAMS] +display_keybinds=$(echo "$raw_keybinds" | awk -F'=' ' + function trim(s){ gsub(/^[ \t]+|[ \t]+$/,"",s); return s } + /^[[:space:]]*bind/ { + binder=$1; gsub(/[ \t]/, "", binder); + hasdesc = (index(binder, "d")>0); + + rhs=$2; rhs=trim(rhs); + n=split(rhs, a, /[ \t]*,[ \t]*/); + + mods=trim(a[1]); key=(n>=2?trim(a[2]):""); + desc=""; dispatcher=""; params=""; + + if (hasdesc) { + desc=(n>=3?trim(a[3]):""); + dispatcher=(n>=4?trim(a[4]):""); + start=5; + } else { + dispatcher=(n>=3?trim(a[3]):""); + start=4; + } + + for(i=start;i<=n;i++){ if(length(a[i])){ p=trim(a[i]); if(p!="") params = (params?params", ":"") p } } + + gsub(/\$mainMod/,"SUPER",mods); + gsub(/[ \t]+/,"+",mods); + + combo = (mods && key) ? mods "+" key : (key?key:mods); + + if (desc != "") { + if (dispatcher != "" && params != "") + print combo, " — ", desc, " — ", dispatcher, " ", params; + else if (dispatcher != "") + print combo, " — ", desc, " — ", dispatcher; + else + print combo, " — ", desc; + } else { + if (dispatcher != "" && params != "") + print combo, " — ", dispatcher, " ", params; + else if (dispatcher != "") + print combo, " — ", dispatcher; + else + print combo; + } + } +') -# use rofi to display the keybinds with the modified content -echo "$display_keybinds" | rofi -dmenu -i -config "$rofi_theme" -mesg "$msg"
\ No newline at end of file +# use rofi to display the keybinds +printf '%s\n' "$display_keybinds" | rofi -dmenu -i -config "$rofi_theme" -mesg "$msg" |
