From fdc791736c8de17e9b498e853a5f2e2670425eb1 Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Tue, 11 Oct 2022 23:05:00 +0300 Subject: [PATCH] bash: trap 'command not found' errors --- config/.bashrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/.bashrc b/config/.bashrc index 72d1dcd..2ba3fd7 100644 --- a/config/.bashrc +++ b/config/.bashrc @@ -51,3 +51,15 @@ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || pr # https://stackoverflow.com/a/65362210/13725946 export DOCKER_BUILDKIT=0 export COMPOSE_DOCKER_CLI_BUILD=0 + +__trap_not_cmd_found_error() { + code="$?" + if [[ "$code" == "127" ]]; then + prevCmd=$(history | tail -n 1 | awk '{ printf $2 }') + echo "$prevCmd" + + xdg-open "https://command-not-found.com/$prevCmd" + fi +} + +trap "__trap_not_cmd_found_error" ERR