From 3b8514d9aa31d3f758eafbfa0791d1e20131c138 Mon Sep 17 00:00:00 2001 From: Wryn Wagner Date: Fri, 9 Apr 2021 15:14:18 -0600 Subject: [PATCH] updated ssh; fixed bugs, allowed empty 'cmux' to connect to default local conenction --- zsh/ssh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/zsh/ssh b/zsh/ssh index 2d9073b..f09e1b5 100644 --- a/zsh/ssh +++ b/zsh/ssh @@ -29,9 +29,11 @@ function WRYN_REMOTE_CONNECTOR() { local SSH_ID="^$CONNECTION$WRYN_SSH_DELIMITER" - [ $2 ] \ - || { echo 'Must specify a connection'; return 1 }; + [[ $COMMAND != 'tmux' ]] && [ ! $CONNECTION ] \ + && { echo 'Must specify a connection'; return 1 }; + grep -q "$SSH_ID" "$WRYN_SSH_CONNECTION_LIST" >/dev/null 2>&1 \ + || [ ! $CONNECTION ] \ || { echo 'No such connection'; return 2 }; case $COMMAND in; @@ -67,6 +69,7 @@ _WRYN_REMOTE_CONNECTOR() { sshfs ) _sshfs;; cpto | cpfrom ) _scp;; tmux ) _tmux;; + ssh-copy-id ) compadd $(ls);; * ) ;; esac ;; @@ -90,11 +93,15 @@ WRYN_REMOTE_TMUX() { local SSH_ID="$1" local UTF8_FLAG=$(locale charmap | grep -q 'UTF-8' && echo '-u') - [ ! $2 ] \ - && ssh $(WRYN_SSH_PARSE_ARGS $SSH_ID) -t tmux $UTF8_FLAG new-session -As $TMUX_DEFAULT_SESSION_NAME \ - || { - [ $3 ] \ - && ssh $(WRYN_SSH_PARSE_ARGS $SSH_ID) -t tmux $UTF8_FLAG ${@:2} \ - || ssh $(WRYN_SSH_PARSE_ARGS $SSH_ID) -t tmux $UTF8_FLAG a -t $2; - } + [[ "$SSH_ID" == "^$WRYN_SSH_DELIMITER" ]] \ + && { tmux new-session -As $TMUX_DEFAULT_SESSION_NAME } \ + || { + [ ! $2 ] \ + && ssh $(WRYN_SSH_PARSE_ARGS $SSH_ID) -t tmux $UTF8_FLAG new-session -As $TMUX_DEFAULT_SESSION_NAME \ + || { + [ $3 ] \ + && { ssh $(WRYN_SSH_PARSE_ARGS $SSH_ID) -t tmux $UTF8_FLAG ${@:2}; return 0 } \ + || { ssh $(WRYN_SSH_PARSE_ARGS $SSH_ID) -t tmux $UTF8_FLAG new-session -As $2; }; + } + } }