diff --git a/scwrypts/ssh/connect/ssh-xserver b/scwrypts/ssh/connect/xserver similarity index 100% rename from scwrypts/ssh/connect/ssh-xserver rename to scwrypts/ssh/connect/xserver diff --git a/scwrypts/ssh/lib/connection/parse.module.zsh b/scwrypts/ssh/lib/connection/parse.module.zsh index 93f0e40..351ebe2 100644 --- a/scwrypts/ssh/lib/connection/parse.module.zsh +++ b/scwrypts/ssh/lib/connection/parse.module.zsh @@ -19,22 +19,23 @@ PARSE_CONNECTION() { local CONNECTION_DETAILS=$(echo $CONNECTION | sed 's/|/ /g;') - REMOTE_NAME=$(echo $CONNECTION_DETAILS | awk '{print $1;}') - REMOTE_HOST=$(echo $CONNECTION_DETAILS | awk '{print $2;}') - REMOTE_ARGS+=($(echo $CONNECTION_DETAILS | awk '{$1=$2="";}1')) + REMOTE_ID=$(echo $CONNECTION_DETAILS | awk '{print $1;}') + REMOTE_NAME=$(echo $CONNECTION_DETAILS | awk '{print $2;}') + REMOTE_HOST=$(echo $CONNECTION_DETAILS | awk '{print $3;}') + REMOTE_ARGS+=($(echo $CONNECTION_DETAILS | awk '{$1=$2=$3="";}1')) } GET_CONNECTIONS() { ( - echo 'localhost | localhost' - echo "$(hostnamectl --static) | localhost" + echo '0 | localhost | localhost' + echo "0 | $(hostnamectl --static) | localhost" sed -n 's/#.*//;s/ \+$//;/./p' "$REMOTE_CONNECTIONS_FILE" ) | sort -u } GET_CONNECTION() { [ ! $1 ] && return 1 - GET_CONNECTIONS | grep "^$1 *|" | head -n1 + GET_CONNECTIONS | grep "^[0-9]\+ *| *$1 *|" | head -n1 } GET_CONNECTION_NAMES() { diff --git a/scwrypts/ssh/omni/manager b/scwrypts/ssh/omni/manager index c0fb69b..d884e0c 100755 --- a/scwrypts/ssh/omni/manager +++ b/scwrypts/ssh/omni/manager @@ -20,17 +20,46 @@ done CONNECTED() { echo "\\033[1;32mconnected\\033[0m"; } DISCONNECTED() { echo "\\033[1;31mdisconnected\\033[0m"; } +SET_UNIQUE_ID() { + i=0 + while : \ + && [[ $(OMNI_TMUX list-windows -t=omni | grep "^$REMOTE_ID:" | wc -l) -gt 0 ]] \ + && [[ ! $(OMNI_TMUX list-windows -t=omni | grep "^$REMOTE_ID:" | awk '{print $2;}') =~ ^$REMOTE_NAME ]] \ + ; + do + echo "$REMOTE_NAME wants id $REMOTE_ID, but it's in use" + sleep 1 + REMOTE_ID=$((69-$i)) + ((i+=1)) + [[ $i -gt 10 ]] && break + done +} + while true do clear REMOTE_HOSTS=() - for CONNECTION in $(sed -n 's/#.*//;s/ \+$//;s/|//g;s/ \+/^/g;/./p;' <(echo "$(hostnamectl --static) | localhost"; cat "$CONNECTIONS_FILE")) + CONNECTION_LIST=$(cat "$CONNECTIONS_FILE") + cat "$CONNECTIONS_FILE" | grep -q localhost || { + CONNECTION_LIST=$(echo "1 | $(hostnamectl --static) | localhost\n$CONNECTION_LIST") + } + + CONNECTION_LIST=$( + echo "$CONNECTION_LIST" | grep localhost + echo "$CONNECTION_LIST" | grep -v localhost + ) + + for CONNECTION in $(sed -n 's/#.*//;s/ \+$//;s/|//g;s/ \+/^/g;/./p;' <<< $CONNECTION_LIST) do CONNECTION=$(echo $CONNECTION | sed 's/[\^]/ /g') + echo "'$CONNECTION'" - REMOTE_NAME=$(echo $CONNECTION | awk '{print $1;}') - REMOTE_HOST=$(echo $CONNECTION | awk '{print $2;}') - REMOTE_ARGS=($(echo $CONNECTION | awk '{$1=$2="";}1')) + REMOTE_ID=$(echo $CONNECTION | awk '{print $1;}') + REMOTE_NAME=$(echo $CONNECTION | awk '{print $2;}') + REMOTE_HOST=$(echo $CONNECTION | awk '{print $3;}') + REMOTE_ARGS=($(echo $CONNECTION | awk '{$1=$2=$3="";}1')) + + SET_UNIQUE_ID printf "$REMOTE_NAME : " @@ -46,7 +75,7 @@ do } [[ $SUCCESS -eq 1 ]] && { - OMNI_TMUX new-window -t=omni -dn $REMOTE_NAME "source ~/.zshrc >/dev/null 2>&1; TMUX= scwrypts -n connect tmux $REMOTE_NAME; echo 'connection closed'; sleep 2" + OMNI_TMUX new-window -t=omni:$REMOTE_ID -dn $REMOTE_NAME "source ~/.zshrc >/dev/null 2>&1; TMUX= scwrypts -n connect tmux $REMOTE_NAME; echo 'connection closed'; sleep 2" OMNI_TMUX list-window -t=omni | awk '{print $1;}' | grep -q '99:' \ && OMNI_TMUX kill-window -t omni:99 } diff --git a/scwrypts/ssh/ssh.scwrypts.zsh b/scwrypts/ssh/ssh.scwrypts.zsh index 5d25c73..56c238a 100644 --- a/scwrypts/ssh/ssh.scwrypts.zsh +++ b/scwrypts/ssh/ssh.scwrypts.zsh @@ -18,10 +18,10 @@ SCWRYPTS__LIST_AVAILABLE_SCWRYPTS__remote() { do CONNECTION_TYPE="$(echo $CONNECTION_TYPE | sed 's/\.\///;')" ( - echo "$(hostnamectl --static) | localhost" - echo 'localhost | localhost' + echo "0 | $(hostnamectl --static) | localhost" + echo '0 | localhost | localhost' cat "$REMOTE_CONNECTIONS_FILE" - ) | sed -n 's/#.*//; /./p' | awk '{print $1;}' | sort -u | sed "s|^|$SCWRYPTS_TYPE__remote/connect/$CONNECTION_TYPE/|" + ) | sed -n 's/#.*//; /./p' | awk '{print $3;}' | sort -u | sed "s|^|$SCWRYPTS_TYPE__remote/connect/$CONNECTION_TYPE/|" done echo "$SCWRYPTS_TYPE__remote/tmux/omni"