Created
November 25, 2023 02:52
-
-
Save kRHYME7/5741387c289df80f42a89b52c740aae3 to your computer and use it in GitHub Desktop.
Just Parsing the keybings from hyprland configuration then display to yad. ( )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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