-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completes 406: stores the content of keybindings variable in a file for reuse. #410
base: main
Are you sure you want to change the base?
Conversation
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.
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.
@arkochan hope you don't mind that I tested out your script and added a few modification to my own, as I also felt that the rofi is taking too long to show. Your idea has significantly improved the performance. As this is your PR, you decide if you want to include my suggestion in. Here are what I discovered.
mod_key=$(rg "^*mainMod =" <"$config_file" | awk '{print $3}')
In any case, I will just paste the modified script here for your to reference. config_file=~/.config/hypr/conf/keybinding.conf
config_file=${config_file/source = ~/}
config_file=${config_file/source=~/}
cache_dir=${XDG_CACHE_HOME:-$HOME/.cache}
cache_file_prefix=.hypr_keymaps_
echo "Reading from: $config_file"
mod_key=$(rg "^*mainMod =" <"$config_file" | awk '{print $3}')
generated_filename="$cache_dir/$cache_file_prefix$(stat -c '%Y' "$config_file")"
keybinds=""
if [ -f "$generated_filename" ]; then
echo "Help file for $config_file already exists in $generated_filename"
keybinds=$(cat "$generated_filename")
else
echo "Generated cache with similar modification time not found. Removing any other cache files"
rm -f "$cache_dir"/"$cache_file_prefix"
echo "Generating new cache for $config_file"
while read -r line; do
if [[ "$line" == "bind"* ]]; then
line=${line/\$mainMod/$mod_key}
line=${line/bind = /}
line=${line/bindm = /}
IFS='#'
read -a strarr <<<"$line"
kb_str=${strarr[0]}
cm_str=${strarr[1]}
IFS=','
read -a kbarr <<<"$kb_str"
item="${kbarr[0]} + ${kbarr[1]}"$'\r'"${cm_str:1}"
keybinds=$keybinds$item$'\n'
fi
done <"$config_file"
echo "$keybinds" >"$generated_filename"
fi
rofi -dmenu -i -markup -eh 2 -replace -p "Keybinds" -config ~/.config/rofi/config-compact.rasi <<<"$keybinds"
|
hmm..... you know what? I just discovered that we don't need that help file to be fast. it is just the inefficient code that is making it slow. instead of using line="$(echo "$line" | sed 's/$mainMod/ALT/g')"
line="$(echo "$line" | sed 's/bind = //g')"
line="$(echo "$line" | sed 's/binde = //g')"
line="$(echo "$line" | sed 's/bindm = //g')"
do this, and keep everything else as usual. line=${line/\$mainMod/ALT}
line=${line/bind = /}
line=${line/bindm = /}
line=${line/binde = /} 🤯 🤯 |
I have definitely gone too far. 😶 😅 Rewrote the entire script with another >100% speed improvement. Here is my entire script #!/bin/bash
config_file=~/.config/hypr/conf/keybinding.conf
echo "Reading from: $config_file"
mod_key=$(rg "^*mainMod =" <"$config_file" | awk '{print $3}')
binds=$(rg "^bind* =" <"$config_file" |
awk -F, '{print $1,"+", $2, "\r#",$3,$4}' | # added # after \r to easily capture unwanted strings
sed 's/bind* = //g' | # remove "bind = "
sed "s/\$mainMod/$mod_key/g" | # replace $mainMod
sed 's/#.*#//g') # remove execution commands containing withing #<unwanted>#
rofi -dmenu -i -markup -eh 2 -replace -p "Keybinds" -config ~/.config/rofi/config-compact.rasi <<<"$binds"
|
This pull requests holds upgrade to
hypr/scripts/keybindings.sh
as i mentioned before on #406.Rather than generating the keybinds variable from the keybind .conf (eg. hypr/keybindings/default.conf) file each time hypr/scripts/keybindings.sh script is ran, it is be generated once after each modification to keybind .conf file selected by user.
This variable is saved as
[configfile.conf]_[unix_time_stamp].help
file. the unix time stamp indicates the last time the config file is modified. if it dosent match the help file is regenerated according to thekeybinds
variable and older .help file is removed. The .help extension might not be the best choice. and i am a bit confused with the extension name. Also the help file is stored in the same directory as the conf direcotry. (eg.config/hypr/conf/keybindings
by default)This is my first PR in an open source project. Please do guide me if mistakes are made.