Created
March 24, 2014 11:29
-
-
Save Rob--W/9738549 to your computer and use it in GitHub Desktop.
Go to current directory when you open screen or a new tab in screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# The file where the PWD is going to be shared with other (new) tabs. | |
STY_SHARED_PWD="/tmp/.screenpwd-$STY" | |
if [ -e "$STY_SHARED_PWD" ] ; then | |
# If the file exists, then another session had already set the | |
# environment, so read the most recent PWD and go to the directory. | |
STY_PWD="$(</tmp/.screenpwd-$STY)" | |
# Provided that it's not empty. | |
[ -n "$STY_PWD" ] && cd "$STY_PWD" | |
fi | |
# Always write the latest location to the shared file. | |
export PROMPT_COMMAND="echo -n \"\$PWD\" > \"$STY_SHARED_PWD\"" | |
# Start the real shell | |
export SHELL=bash | |
bash "$@" | |
# When the screen exits, remove the temporary file. | |
[[ -e "$STY_SHARED_PWD" ]] && rm "$STY_SHARED_PWD" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrapped shell to ensure that PWD is always the latest PWD | |
shell $HOME/.screen.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment