command_not_found_handle() {
	export TEXTDOMAIN=command-not-found
	local cmd state rest args
	local -i pid ppid pgrp session tty_nr tpgid

	# do not run when inside Midnight Commander or within a Pipe
	if test -n "$MC_SID" -o ! -t 1 ; then
		echo $"$1: command not found"
		return 127
	fi

	# do not run when within a subshell
	read pid cmd state ppid pgrp session tty_nr tpgid rest  < /proc/self/stat
	if test $$ -eq $tpgid ; then
		echo "$1: command not found"
		return 127
	fi

	# math
	if [[ "$1" =~ ^[-\[0-9\(+] ]]; then
		which pcalc >& /dev/null || { echo "Can't find pcalc; see http://pcalc.sourceforge.net/"; return 1; };
		args=${@//[/(}
		args=${args//]/)}
		args=${args//0x/HZ}
		args=${args//x/\*}
		args=${args//HZ/0x}
		args=${args##+}
		pcalc "${args}"
		return $?
	fi

	echo "$1: command not found"

	return 127
}

