Last active
May 18, 2022 02:36
-
-
Save ConnerWill/f3be936da86fc5bdd3e22631e6707a5e to your computer and use it in GitHub Desktop.
Bash script to parse and log only the configured *(uncommented)* lines/settings in a configuration file. *Used ‘kitty.conf’ as an example*.
This file contains 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
# ----------------------------------------------------- | |
# List of configured 'kitty.conf' options | |
# | |
# This File Only Shows The Set Options In 'kitty.conf' | |
# Which Makes It Easier To Know Which Options Are Configured | |
# | |
# This file is not a live/up-to-date list of set options, | |
# if an option was set and this file wasnt updated, | |
# the option will not show in this file until it is updated | |
# | |
# To View all set options ... run this command ... | |
# $ cat kitty.conf | grep --regexp='^[^#]' | |
# | |
# To update this file to show all set options .. | |
# Run this script :) | |
# | |
# Make sure to define and export the kitty config variable | |
# (Add to your .bashrc or .zshrc) | |
# export KITTY_CONFIG="$XDG_CONFIG_HOME/kitty/kitty.conf" | |
# | |
# If '$XDG_CONFIG_HOME' is not defined, either define it, | |
# or edit the variable value to point to your 'kitty.conf' | |
# | |
# ----------------------------------------------------- | |
function updatelistofkittykeybindings(){ | |
# Help Menu | |
showkittyoptionshelp='\e[1m\e[48;5;9m\e[37;5;15m ERROR \e[0m\e[1m\e[38;5;248m "KITTY_CONFIG" is not defined\e[0m | |
\e[38;5;57m---------------------------------------------------------\e[0m | |
List of configured \e[38;5;11m'kitty.conf'\e[0m options \e[0m | |
\e[38;5;57m---------------------------------------------------------\e[0m | |
\e[38;5;81mThis File Only Shows The Set Options In \e[38;5;11'kitty.conf'\e[0m | |
\e[38;5;81mWhich Makes It Easier To Know Which Options Are Configured\e[0m | |
\e[38;5;81mThis file is not a live/up-to-date list of set options,\e[0m | |
\e[38;5;81mif an option was set and this file wasnt updated,\e[0m | |
\e[38;5;81mthe option will not show in this file until\e[0m | |
\e[38;5;81mit is updated by running this script.\e[0m | |
\e[38;5;81mThe set options will be shown to the screen and\e[0m | |
\e[38;5;81msaved to the file: \e[38;5;11m"$KITTY_CONFIG_DIR/set-kitty-options.txt"\e[0m | |
\e[38;5;57m---------------------------------------------------------\e[0m | |
To View all set options without saving to file, run this command ... | |
\e[38;5;34m$\e[0m \e[38;5;12mcat\e[0m \e[38;5;15mkitty.conf\e[0m \e[38;5;10m|\e[0m \e[38;5;12mgrep\e[0m \e[38;5;7m--regexp\e[0m\e[38;5;2m=\e[0m\e[38;5;3m'\''^[^#]'\''\e[0m | |
Make sure to define and export the kitty config variable | |
\t\e[38;5;249m(Add to your .bashrc or .zshrc)\e[0m | |
\t\e[38;5;12mexport\e[0m \e[38;5;15mKITTY_CONFIG\e[0m\e[38;5;10m=\e[0m\e[38;5;11m\"$XDG_CONFIG_HOME/kitty/kitty.conf"\e[0m | |
If \e[38;5;11m"$KITTY_CONFIG"\e[0m is not defined, it will use the default path \e[38;5;11m"$XDG_CONFIG_HOME/kitty/kitty.conf"\e[0m | |
If \e[38;5;11m"$XDG_CONFIG_HOME"\e[0m is not defined, either define it, | |
or edit the variable value to point to your \e[38;5;11m"kitty.conf"\e[0m\n | |
' | |
# Main Script | |
clear | |
[[ -z "$KITTY_CONFIG" ]] && echo -n -e '\e[48;5;20m\e[38;5;11m\e[1m WARNING \e[0m \e[38;5;11m"$KITTY_CONFIG"\e[0m is not defined. ' && export KITTY_CONFIG="$XDG_CONFIG_HOME/kitty/kitty.conf" && echo -e "Using \e[38;5;3m'$KITTY_CONFIG'\e[0m ...\e[0m" | |
[[ -f "$KITTY_CONFIG" ]] || echo -e "$showkittyoptionshelp" || return | |
local ALLKITTYOPTIONS=$(cat "$KITTY_CONFIG" | grep --regexp='^[^#]' 2>/dev/null) | |
local GETKITTYMOD=$(echo "$ALLKITTYOPTIONS" | grep --regexp='^kitty_mod' | awk '{print $2}') | |
local GETKITTYKEYS=$(echo "$ALLKITTYOPTIONS" | grep --regexp='map') | |
local SETKITTYOPTIONS=$(echo "$ALLKITTYOPTIONS" | grep --regexp='^[^map|kitty_mod]') | |
local KITTY_CONFIG_DIR=$(dirname "$KITTY_CONFIG") | |
local SET_KITTY_OPTIONS_PATH="$KITTY_CONFIG_DIR/kitty-config-view.txt" | |
date +'%Y-%m-%d-%H%M%S' > "$SET_KITTY_OPTIONS_PATH" | |
echo -e '\e[48;5;9m\e[38;5;15m\e[1mDO OT MODIFY THIS FILE!\e[0m\n\n\e[48;5;9m\e[38;5;15m\e[1mIT IS NOT THE FILE WHICH CONFIGURES KITTY\e[0m\n\e[48;5;20m\e[38;5;11m\e[1mINSTEAD, MODIFY:\e[0m\t\e[38;5;11m$KITTY_CONFIG\e[0m' >> "$SET_KITTY_OPTIONS_PATH" | |
echo -e '#\e[38;5;21m------------------------------------------------------\e[0m' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '# Configured Settings In \e[38;5;11m'kitty.conf '\e[0m \e[0m' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '#\e[38;5;21m------------------------------------------------------\e[0m' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '#\e[38;5;21m-\e[38;5;105m[Config]\e[38;5;21m----------------------------------------------\e[0m' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '#\e[38;5;21m---\e[38;5;127m[Settings]\e[38;5;21m-----------------------------------------\e[0m\n' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo "$SETKITTYOPTIONS" | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '\n#\e[38;5;21m-\e[38;5;105m[Key Bindings]\e[38;5;21m---------------------------------------\e[0m' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '#\e[38;5;21m---\e[38;5;127m[Modifier]\e[38;5;21m-------------------------------------------\e[0m\n' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo "$GETKITTYMOD" | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '\n#\e[38;5;21m---\e[38;5;127m[Bindings]\e[38;5;21m-------------------------------------------\e[0m\n' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo "$GETKITTYKEYS" | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e '\n#\e[38;5;21m-----------------------------------------------------\e[0m' | tee --append "$SET_KITTY_OPTIONS_PATH" | |
echo -e "\e[38;5;81mSaved to the file: \e[38;5;11m$SET_KITTY_OPTIONS_PATH\e[0m" | |
} | |
updatelistofkittykeybindings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment