Skip to content

Instantly share code, notes, and snippets.

@mortehu
Last active December 16, 2015 17:19
Show Gist options
  • Save mortehu/5469769 to your computer and use it in GitHub Desktop.
Save mortehu/5469769 to your computer and use it in GitHub Desktop.
Fix spelling mistakes in bash command lines
# BEGIN: Put this in ~/.bashrc
function err_handle {
if [ "$?" != 0 ]
then
if echo "$previous_command" | grep -q '\<hlep\>'
then
NEW_COMMAND="$(echo "$previous_command" | sed 's/\<hlep\>/help/g')"
echo -ne "Command failed. Retry with '$NEW_COMMAND' (y/n)? "
read p
if [ "$p" = "y" ]
then
eval $NEW_COMMAND
fi
fi
fi
}
trap 'err_handle' ERR
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
# END: Put this in ~/.bashrc
# Example:
/bin/ls --hlep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment