From e2559a9f850b8b5b310fd6dad1f36135a9430675 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 21 Jun 2024 17:28:36 +0200 Subject: [PATCH] Preserve ssh --- alacritty.toml | 6 +++--- bin/clone-terminal | 9 +++++++++ zsh/config.zsh | 5 +++++ zsh/preserve-cwd-ssh.zsh | 20 ++++++++++++++++++++ zshrc | 1 + 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100755 bin/clone-terminal create mode 100644 zsh/preserve-cwd-ssh.zsh diff --git a/alacritty.toml b/alacritty.toml index 3a955c5..4578cc5 100644 --- a/alacritty.toml +++ b/alacritty.toml @@ -60,7 +60,7 @@ x = 0 y = 0 [[keyboard.bindings]] -action = "SpawnNewInstance" +command = "clone-terminal" key = "E" mods = "Control|Shift" @@ -636,8 +636,8 @@ semantic_escape_chars = ",│`|:\"' ()[]{}<>" [window] decorations = "none" -dynamic_title = false -opacity = 0.8 +dynamic_title = true +opacity = 0.85 [window.dimensions] columns = 0 diff --git a/bin/clone-terminal b/bin/clone-terminal new file mode 100755 index 0000000..c07e836 --- /dev/null +++ b/bin/clone-terminal @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +WINDOW_ID=$(xdotool getactivewindow) +WM_NAME=$(xprop -id $WINDOW_ID WM_NAME | cut -d '"' -f 2) + +if [ -f $HOME/.config/terminalscwd/$WM_NAME.ssh ]; then + echo $(cat $HOME/.config/terminalscwd/$WM_NAME.ssh) > ~/toto.txt + alacritty -e sh -c "TERMINAL_UUID=$WM_NAME ssh $(cat $HOME/.config/terminalscwd/$WM_NAME.ssh)" +fi diff --git a/zsh/config.zsh b/zsh/config.zsh index 6408e26..a5709bd 100644 --- a/zsh/config.zsh +++ b/zsh/config.zsh @@ -14,6 +14,11 @@ # Uncomment following line if you want to disable autosetting terminal title. DISABLE_AUTO_TITLE="true" +if [ -z $TERMINAL_UUID ]; then + export TERMINAL_UUID=$(uuidgen) +fi +echo -en "\e]2;$TERMINAL_UUID\a" + # Uncomment following line if you want red dots to be displayed while waiting for completion # COMPLETION_WAITING_DOTS="true" diff --git a/zsh/preserve-cwd-ssh.zsh b/zsh/preserve-cwd-ssh.zsh new file mode 100644 index 0000000..e3337ec --- /dev/null +++ b/zsh/preserve-cwd-ssh.zsh @@ -0,0 +1,20 @@ +if [ "$PRESERVE_SSH_CWD" = "true" ]; then + mkdir -p $HOME/.config/terminalscwd/ + cd() { + builtin cd $1 + pwd > $HOME/.config/terminalscwd/$TERMINAL_UUID.pwd + } + + if [ -f $HOME/.config/terminalscwd/$TERMINAL_UUID.pwd ]; then + cd $(cat $HOME/.config/terminalscwd/$TERMINAL_UUID.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 diff --git a/zshrc b/zshrc index 8172488..5eaabbb 100644 --- a/zshrc +++ b/zshrc @@ -31,6 +31,7 @@ source $DOTFILES/zsh/config.zsh source $DOTFILES/zsh/path.zsh source $DOTFILES/zsh/exports.zsh source $DOTFILES/zsh/aliases.zsh +source $DOTFILES/zsh/preserve-cwd-ssh.zsh if [ -f $DOTFILES/zsh/extraconfig.zsh ]; then source $DOTFILES/zsh/extraconfig.zsh