40 lines
1.3 KiB
Bash
Executable File
40 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
RUNNING_SSH=false
|
|
RUNNING_WAYPIPE=false
|
|
SSH_CLIENT=""
|
|
CHILD_PID=$(pgrep -P "$1")
|
|
|
|
GRAND_CHILD_PID=$(pgrep -P "$CHILD_PID")
|
|
if [ "$GRAND_CHILD_PID" != 0 ]; then
|
|
GRAND_CHILD_NAME=$(ps -p "$GRAND_CHILD_PID" -o comm=)
|
|
if [ "$GRAND_CHILD_NAME" == "ssh" ]; then
|
|
RUNNING_SSH=true
|
|
CHILD_PID=$GRAND_CHILD_PID
|
|
SSH_CLIENT=$(ps -p "$CHILD_PID" -o args --no-headers | awk '{ print $2 }')
|
|
fi
|
|
if [ "$GRAND_CHILD_NAME" == "waypipe" ]; then
|
|
RUNNING_WAYPIPE=true
|
|
CHILD_PID=$(pgrep -P "$GRAND_CHILD_PID")
|
|
SSH_CLIENT=$(ps -p "$GRAND_CHILD_PID" -o args --no-headers | awk '{ print $4 }')
|
|
fi
|
|
fi
|
|
|
|
|
|
if [ $RUNNING_WAYPIPE == true ]; then
|
|
PREVIOUS_SESSION_ID=$(grep -z "SSH_SESSION_ID" "/proc/$CHILD_PID/environ" | xargs -0 -n 1 | grep -oP "[0-9]*")
|
|
SSH_SESSION_ID=$RANDOM
|
|
alacritty -e zsh -c "SSH_SESSION_ID=$SSH_SESSION_ID waypipe ssh -t \"$SSH_CLIENT\" env SSH_SESSION_ID=\"$SSH_SESSION_ID\" PREVIOUS_SESSION_ID=\"$PREVIOUS_SESSION_ID\" \"zsh --login\""
|
|
else
|
|
if [ "$(ps -p "$1" -o comm=)" == "alacritty" ]; then
|
|
CWD=$(readlink -e /proc/"$CHILD_PID"/cwd)
|
|
if [ "$CWD" != "" ]; then
|
|
alacritty --working-directory "$CWD"
|
|
else
|
|
alacritty
|
|
fi
|
|
else
|
|
alacritty
|
|
fi
|
|
fi
|