bash/cygwin:登录 cd 到我上次所在的目录 "exit"

bash/cygwin: on login cd to directory i was on last "exit"

在 cygwin 启动时,我想回到上次离开 cygwin(exit)时所在的目录。

所以我想我需要将 exit 上的当前目录存储在一个文件中,并在下次登录 .bashrc 时使用它返回。是否有在 exit 或注销时调用的默认脚本?

将此放入您的 .bashrc:

trap 'pwd > ~/.lastdir' EXIT
if [[ -f ~/.lastdir ]]; then
    cd "$(< ~/.lastdir)"
fi