dotfiles/zsh/preserve-cwd-ssh.zsh

37 lines
1005 B
Bash
Raw Normal View History

2024-06-21 17:28:36 +02:00
if [ "$PRESERVE_SSH_CWD" = "true" ]; then
2024-06-21 18:40:01 +02:00
if [ -z $DISPLAY ]; then
if [ -z $TERMINAL_UUID ]; then
2024-06-21 18:16:54 +02:00
export TERMINAL_UUID=$(uuidgen)
2024-06-21 18:40:01 +02:00
fi
else
WINDOW_ID=$(xdotool getactivewindow)
if [ $? -eq 0 ]; then
2024-06-21 18:16:54 +02:00
WM_NAME=$(xprop -id $WINDOW_ID WM_NAME | cut -d '"' -f 2)
export TERMINAL_UUID=$WM_NAME
2024-06-21 18:40:01 +02:00
else
export TERMINAL_UUID=$(uuidgen)
2024-06-21 18:16:54 +02:00
fi
fi
echo -en "\e]2;$TERMINAL_UUID\a"
2024-06-21 17:28:36 +02:00
mkdir -p $HOME/.config/terminalscwd/
cd() {
builtin cd $1
pwd > $HOME/.config/terminalscwd/$TERMINAL_UUID.pwd
}
2024-06-21 17:32:39 +02:00
if [ -f $HOME/.config/terminalscwd/$PARENT_TERMINAL.pwd ]; then
cd $(cat $HOME/.config/terminalscwd/$PARENT_TERMINAL.pwd)
2024-06-21 17:28:36 +02:00
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