Skip to content

Instantly share code, notes, and snippets.

@ytomino
Last active October 30, 2017 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytomino/ce42b459645ef7585d4e84e29e95dc38 to your computer and use it in GitHub Desktop.
Save ytomino/ce42b459645ef7585d4e84e29e95dc38 to your computer and use it in GitHub Desktop.
command not foundと相対パスcdを弾くzshaddhistory
function zshaddhistory {
local cmdline cmd dir
cmdline=( ${=1} )
if [[ ${cmdline[1]} =~ '[`(]' ]]; then
return 0 # do not want to exec something on expansion
else
cmd=${(e)~cmdline[1]}
if [[ ${cmd} == cd ]]; then
if [[ ${cmdline[2]} =~ '[`(]' ]]; then
return 0 # do not want to exec something on expansion
else
dir=${(e)~cmdline[2]}
[[ ${dir[1]} == - || ( ${dir[1]} == / && -d ${dir} ) ]]
fi
else
[[ ${cmd} =~ = ]] || which ${cmd} >& /dev/null || [[ ${cmd[1]} == / && -d ${cmd} ]]
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment