Last active
October 30, 2017 09:40
-
-
Save ytomino/ce42b459645ef7585d4e84e29e95dc38 to your computer and use it in GitHub Desktop.
command not foundと相対パスcdを弾くzshaddhistory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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