add custom error handling for command not found

Enhance user experience by displaying errors in red when a command
is not found in the shell environment.
This commit is contained in:
Ray Elliott 2025-09-30 21:22:19 +01:00
parent c93727503e
commit ac7683930b
1 changed files with 6 additions and 0 deletions

6
bashrc
View File

@ -167,6 +167,12 @@ function calculate_git_alignment() {
# Set up prompt command to draw divider, update git status, and calculate alignment
PROMPT_COMMAND="draw_prompt_divider; my_gitstatus_prompt_update; calculate_git_alignment"
# Custom command_not_found_handle function to show errors in red
command_not_found_handle() {
echo -e "\033[01;31mbash: $1: command not found\033[00m" >&2
return 127
}
# Set PS1 with user@host, directory on first line, dynamically aligned git status, prompt on third line
PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[1;34m\]\w\[\033[00m\]\n${GITSTATUS_PROMPT:+$GIT_ALIGNMENT_PADDING$GITSTATUS_PROMPT\n}└── \[\033[01;$((31+!$?))m\]\$\[\033[00m\] \[\e]0;\u@\h: \w\a\]'