diff --git a/scwrypts/.config/env.template b/scwrypts/dotwryn/.config/env.template similarity index 100% rename from scwrypts/.config/env.template rename to scwrypts/dotwryn/.config/env.template diff --git a/scwrypts/.config/env.template.descriptions b/scwrypts/dotwryn/.config/env.template.descriptions similarity index 100% rename from scwrypts/.config/env.template.descriptions rename to scwrypts/dotwryn/.config/env.template.descriptions diff --git a/scwrypts/desktop/backlight b/scwrypts/dotwryn/desktop/backlight similarity index 100% rename from scwrypts/desktop/backlight rename to scwrypts/dotwryn/desktop/backlight diff --git a/scwrypts/desktop/get-colorscheme-hex b/scwrypts/dotwryn/desktop/get-colorscheme-hex similarity index 100% rename from scwrypts/desktop/get-colorscheme-hex rename to scwrypts/dotwryn/desktop/get-colorscheme-hex diff --git a/scwrypts/desktop/i3/lock b/scwrypts/dotwryn/desktop/i3/lock similarity index 100% rename from scwrypts/desktop/i3/lock rename to scwrypts/dotwryn/desktop/i3/lock diff --git a/scwrypts/desktop/i3/logout b/scwrypts/dotwryn/desktop/i3/logout similarity index 100% rename from scwrypts/desktop/i3/logout rename to scwrypts/dotwryn/desktop/i3/logout diff --git a/scwrypts/desktop/i3/set-background b/scwrypts/dotwryn/desktop/i3/set-background similarity index 100% rename from scwrypts/desktop/i3/set-background rename to scwrypts/dotwryn/desktop/i3/set-background diff --git a/scwrypts/desktop/kitty-alternate-theme b/scwrypts/dotwryn/desktop/kitty-alternate-theme similarity index 100% rename from scwrypts/desktop/kitty-alternate-theme rename to scwrypts/dotwryn/desktop/kitty-alternate-theme diff --git a/scwrypts/desktop/play-sound b/scwrypts/dotwryn/desktop/play-sound similarity index 100% rename from scwrypts/desktop/play-sound rename to scwrypts/dotwryn/desktop/play-sound diff --git a/scwrypts/desktop/pulseaudio b/scwrypts/dotwryn/desktop/pulseaudio similarity index 100% rename from scwrypts/desktop/pulseaudio rename to scwrypts/dotwryn/desktop/pulseaudio diff --git a/scwrypts/desktop/screen-blank b/scwrypts/dotwryn/desktop/screen-blank similarity index 100% rename from scwrypts/desktop/screen-blank rename to scwrypts/dotwryn/desktop/screen-blank diff --git a/scwrypts/dotwryn.scwrypts.zsh b/scwrypts/dotwryn/dotwryn.scwrypts.zsh similarity index 73% rename from scwrypts/dotwryn.scwrypts.zsh rename to scwrypts/dotwryn/dotwryn.scwrypts.zsh index ba899d8..2c12849 100644 --- a/scwrypts/dotwryn.scwrypts.zsh +++ b/scwrypts/dotwryn/dotwryn.scwrypts.zsh @@ -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" diff --git a/scwrypts/home/update-all-servers b/scwrypts/dotwryn/home/update-all-servers similarity index 100% rename from scwrypts/home/update-all-servers rename to scwrypts/dotwryn/home/update-all-servers diff --git a/scwrypts/lib/desktop/colorscheme.module.zsh b/scwrypts/dotwryn/lib/desktop/colorscheme.module.zsh similarity index 100% rename from scwrypts/lib/desktop/colorscheme.module.zsh rename to scwrypts/dotwryn/lib/desktop/colorscheme.module.zsh diff --git a/scwrypts/lib/desktop/notify.module.zsh b/scwrypts/dotwryn/lib/desktop/notify.module.zsh similarity index 100% rename from scwrypts/lib/desktop/notify.module.zsh rename to scwrypts/dotwryn/lib/desktop/notify.module.zsh diff --git a/scwrypts/lib/media/audio.module.zsh b/scwrypts/dotwryn/lib/media/audio.module.zsh similarity index 100% rename from scwrypts/lib/media/audio.module.zsh rename to scwrypts/dotwryn/lib/media/audio.module.zsh diff --git a/scwrypts/ssh/.config/env.template b/scwrypts/ssh/.config/env.template new file mode 100644 index 0000000..f7df9c2 --- /dev/null +++ b/scwrypts/ssh/.config/env.template @@ -0,0 +1 @@ +#!/bin/zsh diff --git a/scwrypts/ssh/.config/env.template.descriptions b/scwrypts/ssh/.config/env.template.descriptions new file mode 100644 index 0000000..e69de29 diff --git a/scwrypts/ssh/connect/ssh b/scwrypts/ssh/connect/ssh new file mode 100755 index 0000000..c48c9ec --- /dev/null +++ b/scwrypts/ssh/connect/ssh @@ -0,0 +1,13 @@ +#!/bin/zsh +##################################################################### + +DEPENDENCIES+=() +REQUIRED_ENV+=() + +use ssh --group remote + +CHECK_ENVIRONMENT + +##################################################################### + +REMOTE__LOGIN $@ diff --git a/scwrypts/ssh/connect/ssh-xserver b/scwrypts/ssh/connect/ssh-xserver new file mode 100755 index 0000000..0e3b7d1 --- /dev/null +++ b/scwrypts/ssh/connect/ssh-xserver @@ -0,0 +1,13 @@ +#!/bin/zsh +##################################################################### + +DEPENDENCIES+=() +REQUIRED_ENV+=() + +use ssh --group remote + +CHECK_ENVIRONMENT + +##################################################################### + +REMOTE_ARGS=(-Y) REMOTE__LOGIN $@ diff --git a/scwrypts/ssh/connect/tmux b/scwrypts/ssh/connect/tmux new file mode 100755 index 0000000..43a2538 --- /dev/null +++ b/scwrypts/ssh/connect/tmux @@ -0,0 +1,13 @@ +#!/bin/zsh +##################################################################### + +DEPENDENCIES+=() +REQUIRED_ENV+=() + +use tmux --group remote + +CHECK_ENVIRONMENT + +##################################################################### + +REMOTE_CONNECT_TMUX $@ diff --git a/scwrypts/ssh/lib/connection/parse.module.zsh b/scwrypts/ssh/lib/connection/parse.module.zsh new file mode 100644 index 0000000..93f0e40 --- /dev/null +++ b/scwrypts/ssh/lib/connection/parse.module.zsh @@ -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 '|' +} diff --git a/scwrypts/ssh/lib/ssh.module.zsh b/scwrypts/ssh/lib/ssh.module.zsh new file mode 100644 index 0000000..2548007 --- /dev/null +++ b/scwrypts/ssh/lib/ssh.module.zsh @@ -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 +} diff --git a/scwrypts/ssh/lib/tmux.module.zsh b/scwrypts/ssh/lib/tmux.module.zsh new file mode 100644 index 0000000..ef43b0e --- /dev/null +++ b/scwrypts/ssh/lib/tmux.module.zsh @@ -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[@]}" +} + diff --git a/scwrypts/ssh/omni b/scwrypts/ssh/omni new file mode 100755 index 0000000..6023693 --- /dev/null +++ b/scwrypts/ssh/omni @@ -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 diff --git a/scwrypts/ssh/omni-manager b/scwrypts/ssh/omni-manager new file mode 100755 index 0000000..c0fb69b --- /dev/null +++ b/scwrypts/ssh/omni-manager @@ -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 diff --git a/scwrypts/ssh/omni.tmux.conf b/scwrypts/ssh/omni.tmux.conf new file mode 100644 index 0000000..59c88d7 --- /dev/null +++ b/scwrypts/ssh/omni.tmux.conf @@ -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)% " diff --git a/scwrypts/ssh/ssh.scwrypts.zsh b/scwrypts/ssh/ssh.scwrypts.zsh new file mode 100644 index 0000000..bc2f643 --- /dev/null +++ b/scwrypts/ssh/ssh.scwrypts.zsh @@ -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" +}