开发者

How can i make my Bash start where i worked last?

开发者 https://www.devze.com 2023-04-05 09:26 出处:网络
Can I somehow config my bash to be auto located in the last path I worked when I open it again ? E.g. yesterday I worked in my git repository (local machine) so I had to cd myself to \"/Appli开发者_如

Can I somehow config my bash to be auto located in the last path I worked when I open it again ? E.g. yesterday I worked in my git repository (local machine) so I had to cd myself to "/Appli开发者_如何学编程cations/.../git/" which is quite long.

After work I quit my bash.

Today I want to start right there when I open the bash without having to cd again. Is this somehow possible?

regards.


The only way I can come up with for now is kinda hacky... When a login shell terminates, it runs ~/.bash_logout. Adding pwd > ~/.lastdir to that file, you could then do cd $(cat ~/.lastdir) in your .bashrc. The hackyness is that you'd have to run all your terminals as login shells.


Add the following to your ~/.bashrc file

trap 'pwd > $HOME/.lastdir; exit' 0
if [ -f "$HOME/.lastdir" ]; then
    cd `cat $HOME/.lastdir`
fi


You can also use screen. This is a very useful tool for remote management, because it includes features of a bash screen, such as multiple tabs. The most notable feature is the session management: It's possible to return to one of your previous session, which also includes the screen's output and the last entered commands (of all virtual tabs).


All you have to do is to add the command cd path_to_folder in the .bashrc file in users' home directory.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号