]> git.friedersdorff.com Git - max/dotfiles.git/commitdiff
Create ssh_in function for tmux shenanigans
authorMaximilian Friedersdorff <max@friedersdorff.com>
Thu, 13 Sep 2018 11:49:14 +0000 (12:49 +0100)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Thu, 13 Sep 2018 11:49:14 +0000 (12:49 +0100)
Copy the current tmux config to the remote server,
ssh in and start tmux

bash/.bash_aliases

index 952029c6af8df02214836da349205b8f7d54534f..40b2d03b516a3b067698e050795225667c81976d 100644 (file)
@@ -27,7 +27,26 @@ fi
  
 
 function ssh_in() {
+  control_file="$TMPDIR/${1}_ssh_in"
+  if [[ -e $control_file ]]; then
+    echo "Session is already open"
+    exit
+  fi
+
+  cat ~/.tmux.conf | ssh \
+    -M \
+    -S "$control_file" \
+    -o ControlPersist=yes \
+    "${1}" \
+    'cat - > ~/.tmux_ssh.conf'
+    
+
   i3-sensible-terminal -e \
-    ssh -o RemoteCommand="/bin/sh -c 'tmux has-session && exec tmux attach || exec tmux'" \
-    -t "$@"
+    sh -c \
+    "ssh \
+      -o RemoteCommand=\"/bin/sh -c 'exec tmux -f ~/.tmux_ssh.conf'\" \
+      -S \"$control_file\" \
+      -t \
+      \"$@\"
+    ssh -O exit -S \"$control_file\" \"$1\"" 
 }