Skip to content

Instantly share code, notes, and snippets.

@kRHYME7
Created November 25, 2023 02:52
Show Gist options
  • Save kRHYME7/5741387c289df80f42a89b52c740aae3 to your computer and use it in GitHub Desktop.
Save kRHYME7/5741387c289df80f42a89b52c740aae3 to your computer and use it in GitHub Desktop.
Just Parsing the keybings from hyprland configuration then display to yad. ( )
#!/usr/bin/env sh
#!Declare Some Symbols or Replacements here just to look good
declare -A replacements=(
["XF86Audio"]="🕪 "
["XF86MonBrightnessUp"]="☼ ↑"
["XF86MonBrightnessDown"]="☼ ↓"
['$mainMod']="[]"
["UP"]=""
["DOWN"]=""
["LEFT"]=""
["RIGHT"]=""
["MOUSE:272"]="🖰 ←"
["MOUSE:273"]="🖰 →"
["MOUSE_"]="🖰 "
['switch:on:Lid']="💻 "
)
# Read the configuration file line by line
while IFS= read -r line
do
pre=$(echo $line | cut -d '=' -f 1)
if [[ $pre == *bind* ]]; then
# Parse the line to extract the mod, key, and description
mod=$(echo "$line" | cut -d'=' -f2 | cut -d',' -f1 )
key=$(echo "$line" | cut -d',' -f2)
description=$(echo "$line" | grep -o '#.*' | cut -c 2- | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')
keybind=$(echo "$mod$key" | sed 's/ / * /g' | sed 's/^[ *]*//')
# Loop over the replacements array
for word in "${!replacements[@]}"; do if [[ $keybind == *"$word"* ]]; then symbol=${replacements[$word]}
keybind=$(echo "$keybind" | sed "s/$word/$symbol/g")
fi ; done
hotkeys+=("$keybind" "$description")
elif [[ $pre == "##"* ]]; then
pgebrk="
$(echo "$line" | tr '[:lower:]' '[:upper:]' | cut -d'#' -f3)
"
hotkeys+=("" "$pgebrk")
fi
done < ~/.config/hypr/keybindings.conf
# Pass the list of items to yad
selected=$(yad --width=1200 --height=800 \
--center \
--title="Keybindings" \
--no-buttons \
--list \
--column=Key:BTN \
--column=Description: \
"${hotkeys[@]}";)
if [[ -n $selected ]]; then
echo $selected
# Perform your action here
# For example, open an editor to edit the keybindings.conf file
# code ~/.config/hypr/keybindings.conf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment