dotfiles/zsh/preserve-cwd-ssh.zsh

32 lines
914 B
Bash

if [ "$PRESERVE_SSH_CWD" = "true" ]; then
if [ -z $TERMINAL_UUID ]; then
if [ -z $DISPLAY ]; then
export TERMINAL_UUID=$(uuidgen)
else
WINDOW_ID=$(xdotool getactivewindow)
WM_NAME=$(xprop -id $WINDOW_ID WM_NAME | cut -d '"' -f 2)
export TERMINAL_UUID=$WM_NAME
fi
fi
echo -en "\e]2;$TERMINAL_UUID\a"
mkdir -p $HOME/.config/terminalscwd/
cd() {
builtin cd $1
pwd > $HOME/.config/terminalscwd/$TERMINAL_UUID.pwd
}
if [ -f $HOME/.config/terminalscwd/$PARENT_TERMINAL.pwd ]; then
cd $(cat $HOME/.config/terminalscwd/$PARENT_TERMINAL.pwd)
else
cd
fi
ssh() {
echo $1 > $HOME/.config/terminalscwd/$TERMINAL_UUID.ssh
/usr/bin/ssh $@
rm $HOME/.config/terminalscwd/$TERMINAL_UUID.ssh
pwd > $HOME/.config/terminalscwd/$TERMINAL_UUID.pwd
}
fi