Skip to content

Instantly share code, notes, and snippets.

@mxmilkiib
Last active April 20, 2025 20:41
Show Gist options
  • Save mxmilkiib/2dda9d8b62c542cf8ab32ad637930bd0 to your computer and use it in GitHub Desktop.
Save mxmilkiib/2dda9d8b62c542cf8ab32ad637930bd0 to your computer and use it in GitHub Desktop.
readline etc hotkey reminder, two versions for smaller n larger terms
# readline etc hotkey reminder, two versions depending on tty/vty width
# https://gist.github.com/mxmilkiib/2dda9d8b62c542cf8ab32ad637930bd0
echo_color() {
local cyan="\033[0;96m"
local red="\033[0;91m"
local key_color=$cyan # Cyan for hotkeys
local desc_color=$red # Red for descriptions
local reset="\033[0m"
local output=""
# Loop through arguments in pairs (key, description)
while [[ $# -gt 0 ]]; do
output+="${key_color}${1}${reset} ${desc_color}${2}${reset} "
shift 2
done
printf "${output}\n"
}
# Function to display hotkeys based on terminal width
display_initial_hotkeys() {
# Check terminal width and display appropriate hotkeys
if [[ $COLUMNS -gt 120 ]]; then
# Wider terminal layout
echo_color "C-B " "Move back one character " "C-F " "Forward a character " "C-H " "Delete back a character " "C-D " "Delete a character "
echo_color "A-B " "Back to word start " "A-F " "Forward to word end " "C-W " "Delete back a word " "A-D " "Delete forward a word "
echo_color "C-A " "Go to line start " "C-E " "Jump to line end " "C-K " "Delete to end of line " "C-U " "Delete entire line "
echo_color "C-T " "fzf recursive file search " "A-T " "fzf dirs " "C-R " "fzf history " "C-Space" "fzf multi select "
echo_color "gencomp cmd" "add new comp " "** " "extra fuzzy "
else
# Narrower Terminal Layout
echo_color "C-B " "Back char " "C-F " "Fwd char " "C-H " "Del back chr" "C-D " "Del fwd chr "
echo_color "A-B " "Back word " "A-F " "Fwd word " "C-W " "Del back wrd" "A-D " "Del fwd wrd "
echo_color "C-A " "Line start " "C-E " "Line end " "C-K " "Del to end "
echo_color "C-P " "Prev line " "C-N " "Next line " "C-Y " "Undo line "
fi
}
# Function to be added to precmd_functions array. Runs only once.
_cascade_display_hotkeys_once() {
# Check if the function exists before calling and unsetting
if typeset -f display_initial_hotkeys > /dev/null; then
display_initial_hotkeys
unset -f display_initial_hotkeys
# Remove this function itself after it runs
unset -f _cascade_display_hotkeys_once
fi
}
# Add our one-time function to the precmd execution hooks
precmd_functions+=(_cascade_display_hotkeys_once)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment