我想这就是你想要的效果:
之前:
/Users/fred> cd ..
/Users> cd
/Users/fred> history
...
438 cd ..
439 cd
440 history
之后:
/Users/fred> source gash.sh # Magic happens here
/Users/fred> cd ..
/Users> cd
/Users/fred> history
...
501 source gash.sh
502 cd /Users
503 cd /Users/fred
504 history
bash
,此处定义为
伤口.sh:
# Must be 'sourced'
cd() {
if (( $# == 0 )); then
builtin cd # This calls the shell version of cd
else
builtin cd "$@" # This calls the shell version of cd
fi
msg="cd $(pwd)"
history -s "$msg" # This writes to the history 'file'
}
在
zsh
history -s
(哪个
没有)与
print -s
fc -p
和
fc -P
,但这似乎是一个相当大的开销来绕过这一点。