Search code examples
bashcygwincd

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


On cygwin start I'd like to be back in the same dir I was when left cygwin (by exit) last time.

So I think i need to store the current dir on exit in a file and use this to come back on next login in .bashrc. Is there a default script called on exit or logout?


Solution

  • Put this in your .bashrc:

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