From 06fe7abd70a76820a13f751d3aadb393c11ba2c0 Mon Sep 17 00:00:00 2001 From: arkochan Date: Wed, 6 Nov 2024 05:15:05 +0600 Subject: [PATCH 1/2] fix 406: stores the content of keybindings variable in a file for reuse. prevents regenerating the keybinds variable each time. done through : - check if a generated help file already exists for the selected keybind .conf file. - if not: generate a file from the keybinds variable. - else: use already generated help file To ensure for each modification a single file is generated if can be checked either using the last modification using stat -c '%Y' $config_file or by generating a hash value for the file. --- .../.config/hypr/scripts/keybindings.sh | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/share/dotfiles/.config/hypr/scripts/keybindings.sh b/share/dotfiles/.config/hypr/scripts/keybindings.sh index d0b9150b..5bc7fd5c 100755 --- a/share/dotfiles/.config/hypr/scripts/keybindings.sh +++ b/share/dotfiles/.config/hypr/scripts/keybindings.sh @@ -1,47 +1,58 @@ #!/bin/bash -# _ _ _ _ _ -# | | _____ _ _| |__ (_)_ __ __| (_)_ __ __ _ ___ -# | |/ / _ \ | | | '_ \| | '_ \ / _` | | '_ \ / _` / __| -# | < __/ |_| | |_) | | | | | (_| | | | | | (_| \__ \ -# |_|\_\___|\__, |_.__/|_|_| |_|\__,_|_|_| |_|\__, |___/ -# |___/ |___/ +# _ _ _ _ _ +# | | _____ _ _| |__ (_)_ __ __| (_)_ __ __ _ ___ +# | |/ / _ \ | | | '_ \| | '_ \ / _` | | '_ \ / _` / __| +# | < __/ |_| | |_) | | | | | (_| | | | | | (_| \__ \ +# |_|\_\___|\__, |_.__/|_|_| |_|\__,_|_|_| |_|\__, |___/ +# |___/ |___/ # -# ----------------------------------------------------- +# ----------------------------------------------------- # Get keybindings location based on variation -# ----------------------------------------------------- +# ----------------------------------------------------- config_file=$(cat ~/.config/hypr/conf/keybinding.conf) config_file=${config_file/source = ~/} config_file=${config_file/source=~/} -# ----------------------------------------------------- +# ----------------------------------------------------- # Path to keybindings config file -# ----------------------------------------------------- +# ----------------------------------------------------- config_file="/home/$USER$config_file" echo "Reading from: $config_file" +genretaed_filename="${config_file}_$(stat -c '%Y' $config_file).help" + keybinds="" -# Detect Start String -while read -r line -do +## Check if the generated help file exists +if [ -f "$genretaed_filename" ]; then + echo "Help file for $config_file already exists" + keybinds=$(cat "$genretaed_filename") +else + echo "Generated help file not found. Removing $config_file*.help files" + echo "Generating help file for $config_file" + while read -r line; do if [[ "$line" == "bind"* ]]; then - line="$(echo "$line" | sed 's/$mainMod/SUPER/g')" - line="$(echo "$line" | sed 's/bind = //g')" - line="$(echo "$line" | sed 's/bindm = //g')" + line="$(echo "$line" | sed 's/$mainMod/SUPER/g')" + line="$(echo "$line" | sed 's/bind = //g')" + line="$(echo "$line" | sed 's/bindm = //g')" - IFS='#' - read -a strarr <<<"$line" - kb_str=${strarr[0]} - cm_str=${strarr[1]} + IFS='#' + read -a strarr <<<"$line" + kb_str=${strarr[0]} + cm_str=${strarr[1]} - IFS=',' - read -a kbarr <<<"$kb_str" + IFS=',' + read -a kbarr <<<"$kb_str" - item="${kbarr[0]} + ${kbarr[1]}"$'\r'"${cm_str:1}" - keybinds=$keybinds$item$'\n' - fi -done < "$config_file" + item="${kbarr[0]} + ${kbarr[1]}"$'\r'"${cm_str:1}" + keybinds=$keybinds$item$'\n' + fi + done <"$config_file" + echo "$keybinds" >"$genretaed_filename" + rm -f "$config_file"*.help +fi sleep 0.2 -rofi -dmenu -i -markup -eh 2 -replace -p "Keybinds" -config ~/.config/rofi/config-compact.rasi <<< "$keybinds" \ No newline at end of file +rofi -dmenu -i -markup -eh 2 -replace -p "Keybinds" -config ~/.config/rofi/config-compact.rasi <<<"$keybinds" + From 53889abaf1b47959d74b6ccfa0df9acda3cfb9a9 Mon Sep 17 00:00:00 2001 From: arkochan Date: Wed, 6 Nov 2024 05:15:05 +0600 Subject: [PATCH 2/2] fix 406: stores the content of keybindings variable in a file for reuse. prevents regenerating the keybinds variable each time. done through : - check if a generated help file already exists for the selected keybind .conf file. - if not: generate a file from the keybinds variable. - else: use already generated help file To ensure for each modification a single file is generated if can be checked either using the last modification using stat -c '%Y' $config_file or by generating a hash value for the file. --- share/dotfiles/.config/hypr/scripts/keybindings.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/share/dotfiles/.config/hypr/scripts/keybindings.sh b/share/dotfiles/.config/hypr/scripts/keybindings.sh index 5bc7fd5c..f9f0143b 100755 --- a/share/dotfiles/.config/hypr/scripts/keybindings.sh +++ b/share/dotfiles/.config/hypr/scripts/keybindings.sh @@ -28,8 +28,9 @@ if [ -f "$genretaed_filename" ]; then echo "Help file for $config_file already exists" keybinds=$(cat "$genretaed_filename") else - echo "Generated help file not found. Removing $config_file*.help files" - echo "Generating help file for $config_file" + echo "Generated help file with smilar modification time not found. Removing old $config_file*.help files" + rm -f "$config_file"*.help + echo "Generating new help file for $config_file" while read -r line; do if [[ "$line" == "bind"* ]]; then @@ -50,9 +51,7 @@ else fi done <"$config_file" echo "$keybinds" >"$genretaed_filename" - rm -f "$config_file"*.help fi sleep 0.2 rofi -dmenu -i -markup -eh 2 -replace -p "Keybinds" -config ~/.config/rofi/config-compact.rasi <<<"$keybinds" -