Skip to content

saves PWD to disk and sets it when starting a shell

Notifications You must be signed in to change notification settings

BashSTuff/rememberPWD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

rememberPWD

saves PWD to disk and sets previous PWD when starting a new BASH shell

The intended use is for systems that have users su - / sudo su - to use the root account (mainly Debian distros).

This script will cd the root/other user into their previous PWD. For example,

Terminal 1

  1. user1@Linux:~$
  2. user1@Linux:~$ sudo su - otherUser2
  3. otherUser2@Linux:~$
  4. otherUser2@Linux:~$ cd /var/log/
  5. otherUser2@Linux:/var/log$

Terminal 2 (or TAB)

  1. user1@Linux:~$
  2. user1@Linux:~$ sudo su - otherUser2
  3. otherUser2@Linux:/var/log$ <--- user is in same directory as before

My script adds this to the end of your .bashrc:

# save PWD to disk
function cd {
 builtin cd "$@"
 echo $PWD > ~/.previousPWD
}
cd "`cat ~/.previousPWD`"

About

saves PWD to disk and sets it when starting a shell

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages