ssh scwrypts extension + moved dotwryn scwrypts extension deeper
This commit is contained in:
parent
8ec32af38e
commit
8ab8647402
@ -1,7 +1,6 @@
|
||||
SCWRYPTS_GROUPS+=(dotwryn)
|
||||
[ $DOTWRYN ] || source "$HOME/.config/wryn/env.zsh"
|
||||
|
||||
export SCWRYPTS_TYPE__dotwryn=zsh
|
||||
export SCWRYPTS_ROOT__dotwryn="$DOTWRYN/scwrypts"
|
||||
export SCWRYPTS_ROOT__dotwryn="$DOTWRYN/scwrypts/dotwryn"
|
||||
export SCWRYPTS_COLOR__dotwryn='\033[0;31m'
|
||||
|
||||
[ $DOTWRYN ] || source "$HOME/.config/wryn/env.zsh"
|
1
scwrypts/ssh/.config/env.template
Normal file
1
scwrypts/ssh/.config/env.template
Normal file
@ -0,0 +1 @@
|
||||
#!/bin/zsh
|
0
scwrypts/ssh/.config/env.template.descriptions
Normal file
0
scwrypts/ssh/.config/env.template.descriptions
Normal file
13
scwrypts/ssh/connect/ssh
Executable file
13
scwrypts/ssh/connect/ssh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/zsh
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use ssh --group remote
|
||||
|
||||
CHECK_ENVIRONMENT
|
||||
|
||||
#####################################################################
|
||||
|
||||
REMOTE__LOGIN $@
|
13
scwrypts/ssh/connect/ssh-xserver
Executable file
13
scwrypts/ssh/connect/ssh-xserver
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/zsh
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use ssh --group remote
|
||||
|
||||
CHECK_ENVIRONMENT
|
||||
|
||||
#####################################################################
|
||||
|
||||
REMOTE_ARGS=(-Y) REMOTE__LOGIN $@
|
13
scwrypts/ssh/connect/tmux
Executable file
13
scwrypts/ssh/connect/tmux
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/zsh
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use tmux --group remote
|
||||
|
||||
CHECK_ENVIRONMENT
|
||||
|
||||
#####################################################################
|
||||
|
||||
REMOTE_CONNECT_TMUX $@
|
46
scwrypts/ssh/lib/connection/parse.module.zsh
Normal file
46
scwrypts/ssh/lib/connection/parse.module.zsh
Normal file
@ -0,0 +1,46 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=()
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
#####################################################################
|
||||
|
||||
PARSE_CONNECTION() {
|
||||
[ ! $CONNECTION ] && [ ! $REMOTE_NAME ] && {
|
||||
ERROR 'cannot parse connection without specifying CONNECTION or REMOTE_NAME'
|
||||
return 1
|
||||
}
|
||||
|
||||
[ $REMOTE_NAME ] && CONNECTION=$(GET_CONNECTION $REMOTE_NAME)
|
||||
|
||||
[ ! $CONNECTION ] && {
|
||||
ERROR "no such connection with name '$REMOTE_NAME'"
|
||||
}
|
||||
|
||||
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'))
|
||||
}
|
||||
|
||||
GET_CONNECTIONS() {
|
||||
(
|
||||
echo 'localhost | localhost'
|
||||
echo "$(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_CONNECTION_NAMES() {
|
||||
echo ($(GET_CONNECTIONS | awk '{print $1;}'))
|
||||
}
|
||||
|
||||
IS_VALID_CONNECTION_NAME() {
|
||||
GET_CONNECTION $1 | grep -q '|'
|
||||
}
|
49
scwrypts/ssh/lib/ssh.module.zsh
Normal file
49
scwrypts/ssh/lib/ssh.module.zsh
Normal file
@ -0,0 +1,49 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(
|
||||
ssh
|
||||
)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use connection/parse --group remote
|
||||
|
||||
#####################################################################
|
||||
|
||||
[ ! $REMOTE_DEFAULT_SHELL ] && REMOTE_DEFAULT_SHELL=(zsh -l)
|
||||
|
||||
REMOTE__LOGIN() {
|
||||
local READ_COMMAND=0
|
||||
|
||||
[ ! $REMOTE_NAME ] && REMOTE_NAME=$1
|
||||
|
||||
[ $REMOTE_NAME ] && {
|
||||
STATUS "connecting to $REMOTE_NAME"
|
||||
}
|
||||
|
||||
PARSE_CONNECTION
|
||||
|
||||
[ ! $REMOTE_HOST ] && {
|
||||
ERROR "could not parse REMOTE_HOST from REMOTE_NAME;
|
||||
check the configuration file for errors"
|
||||
return 1
|
||||
}
|
||||
|
||||
[[ $REMOTE_HOST =~ ^localhost$ ]] && {
|
||||
WARNING 'performing login to localhost'
|
||||
eval "cd; "${REMOTE_DEFAULT_SHELL[@]} ${REMOTE_SHELL_ARGS[@]}
|
||||
return $?
|
||||
}
|
||||
|
||||
ssh -t ${REMOTE_ARGS[@]} $REMOTE_HOST "$REMOTE_DEFAULT_SHELL ${REMOTE_SHELL_ARGS[@]}"
|
||||
}
|
||||
|
||||
REMOTE__EXECUTE() {
|
||||
[ ! $REMOTE_COMMAND ] && REMOTE_COMMAND="$@"
|
||||
|
||||
[ ! $REMOTE_COMMAND ] && {
|
||||
ERROR 'no REMOTE_COMMAND provided!'
|
||||
return 1
|
||||
}
|
||||
|
||||
REMOTE_SHELL_ARGS=(-c "'$REMOTE_COMMAND'") REMOTE__LOGIN
|
||||
}
|
36
scwrypts/ssh/lib/tmux.module.zsh
Normal file
36
scwrypts/ssh/lib/tmux.module.zsh
Normal file
@ -0,0 +1,36 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(
|
||||
tmux
|
||||
)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
use ssh --group remote
|
||||
|
||||
#####################################################################
|
||||
|
||||
REMOTE_CONNECT_TMUX() {
|
||||
local REMOTE_NAME="$1"
|
||||
local USAGE="
|
||||
usage: REMOTE_NAME
|
||||
Connect to remote tmux session on '$REMOTE_NAME'
|
||||
"
|
||||
|
||||
local REMOTE_HOST
|
||||
local REMOTE_ARGS=()
|
||||
|
||||
IS_VALID_CONNECTION_NAME $REMOTE_NAME || ERROR "invalid REMOTE_NAME '$REMOTE_NAME'"
|
||||
|
||||
CHECK_ERRORS
|
||||
|
||||
local TMUX_ARGS=()
|
||||
|
||||
# enforce UTF-8 if supported by host locale
|
||||
TMUX_ARGS+=($(locale charmap | grep -q 'UTF-8' && echo '-u'))
|
||||
|
||||
# create or connect to session
|
||||
TMUX_ARGS+=(new-session -As wryn)
|
||||
|
||||
REMOTE__EXECUTE "tmux ${TMUX_ARGS[@]}"
|
||||
}
|
||||
|
34
scwrypts/ssh/omni
Executable file
34
scwrypts/ssh/omni
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/zsh
|
||||
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(
|
||||
tmux
|
||||
hostnamectl
|
||||
scwrypts # must be on path
|
||||
)
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
CHECK_ENVIRONMENT
|
||||
|
||||
#####################################################################
|
||||
|
||||
[[ $TERM =~ tmux ]] && FAIL 69 "\n Cannot run tmux-omni within a tmux session!\n "
|
||||
|
||||
OMNI_SOCKET="omni.socket"
|
||||
OMNI_TMUX() { tmux -L $OMNI_SOCKET $@; }
|
||||
|
||||
OMNI_TMUX list-sessions 2>/dev/null | grep -v omni-manager | grep -qi omni || {
|
||||
STATUS "initializing omni server"
|
||||
OMNI_TMUX kill-session -t=omni-manager >/dev/null 2>&1
|
||||
|
||||
OMNI_TMUX -f "$SCWRYPTS_ROOT__remote/omni.tmux.conf" new -d -s omni \
|
||||
"echo searching for first connection...; sleep 30" \; \
|
||||
split-window "sleep 3; TMUX= tmux -L $OMNI_SOCKET a -t=omni-manager" \; \
|
||||
move-window -t 99 \;
|
||||
|
||||
OMNI_TMUX new -d -s omni-manager "$SCWRYPTS_ROOT__remote/omni-manager"
|
||||
}
|
||||
|
||||
STATUS 'connecting to omni server'
|
||||
OMNI_TMUX a -t=omni
|
60
scwrypts/ssh/omni-manager
Executable file
60
scwrypts/ssh/omni-manager
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/zsh
|
||||
#
|
||||
# works as a standalone zsh script
|
||||
#
|
||||
CONNECTIONS_FILE="$HOME/.config/wryn/remote-connections"
|
||||
OMNI_SOCKET="omni.socket"
|
||||
OMNI_TMUX() { tmux -L $OMNI_SOCKET $@; }
|
||||
|
||||
sleep 1
|
||||
OMNI_TMUX new-window -t=omni-manager -dn 'harakiri' "
|
||||
while true
|
||||
do
|
||||
tmux -L $OMNI_SOCKET list-sessions | grep -v omni-manager | grep -qi omni || {
|
||||
tmux -L $OMNI_SOCKET kill-session -t omni-manager
|
||||
}
|
||||
sleep 5
|
||||
done
|
||||
"
|
||||
|
||||
CONNECTED() { echo "\\033[1;32mconnected\\033[0m"; }
|
||||
DISCONNECTED() { echo "\\033[1;31mdisconnected\\033[0m"; }
|
||||
|
||||
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"))
|
||||
do
|
||||
CONNECTION=$(echo $CONNECTION | sed 's/[\^]/ /g')
|
||||
|
||||
REMOTE_NAME=$(echo $CONNECTION | awk '{print $1;}')
|
||||
REMOTE_HOST=$(echo $CONNECTION | awk '{print $2;}')
|
||||
REMOTE_ARGS=($(echo $CONNECTION | awk '{$1=$2="";}1'))
|
||||
|
||||
printf "$REMOTE_NAME : "
|
||||
|
||||
OMNI_TMUX list-windows -t=omni | awk '{print $2;}' | grep -q $REMOTE_NAME \
|
||||
&& CONNECTED && continue
|
||||
|
||||
SUCCESS=0
|
||||
[[ $REMOTE_HOST =~ ^localhost$ ]] && SUCCESS=1
|
||||
|
||||
[[ $SUCCESS -eq 1 ]] || {
|
||||
timeout 3 ssh ${REMOTE_ARGS} -o BatchMode=yes $REMOTE_HOST 'command -v tmux 2>/dev/null' 2>/dev/null | grep -q tmux \
|
||||
&& SUCCESS=1
|
||||
}
|
||||
|
||||
[[ $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 list-window -t=omni | awk '{print $1;}' | grep -q '99:' \
|
||||
&& OMNI_TMUX kill-window -t omni:99
|
||||
}
|
||||
|
||||
OMNI_TMUX list-windows -t=omni | awk '{print $2;}' | grep -q $REMOTE_NAME \
|
||||
&& CONNECTED || DISCONNECTED
|
||||
done
|
||||
|
||||
echo "\nPress ENTER to search again now (checks every 60 seconds)"
|
||||
read -t 60
|
||||
done
|
44
scwrypts/ssh/omni.tmux.conf
Normal file
44
scwrypts/ssh/omni.tmux.conf
Normal file
@ -0,0 +1,44 @@
|
||||
source ~/.config/tmux/tmux.conf
|
||||
# window / tile navigation settings from $DOTWRYN/config/tmux.conf
|
||||
# but default to nested session rather than host
|
||||
bind -n M-h send-keys C-b Left
|
||||
bind -n M-H select-pane -L
|
||||
bind -n M-j send-keys C-b Down
|
||||
bind -n M-J select-pane -D
|
||||
bind -n M-k send-keys C-b Up
|
||||
bind -n M-K select-pane -U
|
||||
bind -n M-l send-keys C-b Right
|
||||
bind -n M-L select-pane -R
|
||||
|
||||
bind -n M-Left send-keys C-b C-Left
|
||||
bind -n M-S-Left resize-pane -L 2
|
||||
bind -n M-Down send-keys C-b C-Down
|
||||
bind -n M-S-Down resize-pane -D 2
|
||||
bind -n M-Up send-keys C-b C-Up
|
||||
bind -n M-S-Up resize-pane -U 2
|
||||
bind -n M-Right send-keys C-b C-Right
|
||||
bind -n M-S-Right resize-pane -R 2
|
||||
|
||||
bind-key -n M-Tab send-keys C-b n
|
||||
bind-key -n M-n next-window
|
||||
bind-key -n M-BTab send-keys C-b p
|
||||
bind-key -n M-p previous-window
|
||||
|
||||
bind-key -n M-c new-window
|
||||
bind-key -n M-Enter send-keys C-b c
|
||||
|
||||
bind-key -n M-v send-keys M-v
|
||||
bind-key -n M-V split-window -v
|
||||
bind-key -n M-b send-keys M-b
|
||||
bind-key -n M-B split-window -h
|
||||
bind-key -n M-q send-keys M-q
|
||||
bind-key -n M-Q kill-session
|
||||
bind-key -n M-z send-keys M-z
|
||||
bind-key -n M-Z resize-pane -Z
|
||||
|
||||
bind-key -n M-w send-keys C-M-w
|
||||
|
||||
# force reload now
|
||||
bind-key -n M-R send-keys -t omni-manager ENTER
|
||||
|
||||
set -g status-right "omni host : #(hostnamectl --static) | #(cat /sys/class/power_supply/BAT0/capacity)% "
|
46
scwrypts/ssh/ssh.scwrypts.zsh
Normal file
46
scwrypts/ssh/ssh.scwrypts.zsh
Normal file
@ -0,0 +1,46 @@
|
||||
SCWRYPTS_GROUPS+=(remote)
|
||||
[ $DOTWRYN ] || source "$HOME/.config/wryn/env.zsh"
|
||||
|
||||
export SCWRYPTS_TYPE__remote=zsh
|
||||
export SCWRYPTS_ROOT__remote="$DOTWRYN/scwrypts/ssh"
|
||||
export SCWRYPTS_COLOR__remote='\033[0;34m'
|
||||
|
||||
REMOTE_CONNECTIONS_FILE="$HOME/.config/wryn/remote-connections"
|
||||
|
||||
SCWRYPTS__LIST_AVAILABLE_SCWRYPTS__remote() {
|
||||
[ ! -f "$REMOTE_CONNECTIONS_FILE" ] && {
|
||||
[ -f "$HOME/.config/wryn/ssh-connections" ] \
|
||||
&& cp "$HOME/.config/wryn/ssh-connections" "$REMOTE_CONNECTIONS_FILE" \
|
||||
|| touch "$REMOTE_CONNECTIONS_FILE"
|
||||
}
|
||||
|
||||
for CONNECTION_TYPE in $(cd $SCWRYPTS_ROOT__remote/connect; find . -mindepth 1 -type f -executable)
|
||||
do
|
||||
CONNECTION_TYPE="$(echo $CONNECTION_TYPE | sed 's/\.\///;')"
|
||||
(
|
||||
echo "$(hostnamectl --static) | localhost"
|
||||
echo 'localhost | localhost'
|
||||
cat "$REMOTE_CONNECTIONS_FILE"
|
||||
) | sed -n 's/#.*//; /./p' | awk '{print $1;}' | sort -u | sed "s|^|$SCWRYPTS_TYPE__remote/connect/$CONNECTION_TYPE/|"
|
||||
done
|
||||
|
||||
echo "$SCWRYPTS_TYPE__remote/tmux/omni"
|
||||
echo "$SCWRYPTS_TYPE__remote/remote/configure"
|
||||
}
|
||||
|
||||
SCWRYPTS__GET_RUNSTRING__remote__$SCWRYPTS_TYPE__remote() {
|
||||
[[ $SCWRYPT_NAME =~ tmux/omni ]] \
|
||||
&& echo "source $SCWRYPTS_ROOT__remote/omni" \
|
||||
&& return 0
|
||||
|
||||
[[ $SCWRYPT_NAME =~ remote/configure ]] \
|
||||
&& echo "EDIT $REMOTE_CONNECTIONS_FILE" \
|
||||
&& return 0
|
||||
|
||||
local DETAILS=$(echo $SCWRYPT_NAME | sed 's|connect||; s|/| |g;')
|
||||
|
||||
local CONNECTION_TYPE=$(echo $DETAILS | awk '{print $1;}')
|
||||
local TARGET=$(echo $DETAILS | awk '{print $2;}')
|
||||
|
||||
echo "source $SCWRYPTS_ROOT__remote/connect/$CONNECTION_TYPE $TARGET"
|
||||
}
|
Loading…
Reference in New Issue
Block a user