Support nested launching on ssh
This commit is contained in:
parent
741d0f4d1e
commit
910ca81166
|
@ -1,23 +1,17 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
RUNNING_SSH=false
|
||||||
CHILD_PID=$(pgrep -P $1)
|
CHILD_PID=$(pgrep -P $1)
|
||||||
|
|
||||||
|
[[ $(ps -p $CHILD_PID -o comm=) == "ssh" ]] && RUNNING_SSH=true
|
||||||
|
|
||||||
GRAND_CHILD_PID=$(pgrep -P $CHILD_PID)
|
GRAND_CHILD_PID=$(pgrep -P $CHILD_PID)
|
||||||
|
[[ $? == 0 ]] && [[ $(ps -p $GRAND_CHILD_PID -o comm=) == "ssh" ]] && RUNNING_SSH=true && CHILD_PID=$GRAND_CHILD_PID
|
||||||
|
|
||||||
if [ $? == 0 ]
|
if [ $RUNNING_SSH == true ]; then
|
||||||
then
|
CLIENT=$(ps -p $CHILD_PID -o args --no-headers | awk '{ print $2 }')
|
||||||
PROCESS=$(ps -p $GRAND_CHILD_PID -o comm=)
|
PORT=$(ss -tnpa | grep ssh | grep "pid=$CHILD_PID" | awk '{ print $4 }' | grep -o '[0-9]*$')
|
||||||
COMMAND=$(ps -p $GRAND_CHILD_PID -o args --no-headers)
|
alacritty -e ssh $CLIENT -t "cd \"\$(readlink -e /proc/\$(cat /tmp/ssh_session_$PORT)/cwd)\"; zsh --login"
|
||||||
if [ $PROCESS == "ssh" ]
|
else
|
||||||
then
|
alacritty --working-directory "$(readlink -e /proc/$CHILD_PID/cwd)"
|
||||||
PORT=$(ss -tnpa | grep ssh | grep "pid=$GRAND_CHILD_PID" | awk '{ print $4 }' | grep -o '[0-9]*$')
|
|
||||||
alacritty -e $COMMAND -t "cd \"\$(readlink -e /proc/\$(cat /tmp/ssh_session_$PORT)/cwd)\"; zsh --login"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pushd "/proc/$CHILD_PID/cwd"
|
|
||||||
SHELL_CWD=$(pwd -P)
|
|
||||||
popd
|
|
||||||
|
|
||||||
# Start alacritty with the working directory
|
|
||||||
alacritty --working-directory "$SHELL_CWD"
|
|
||||||
|
|
Loading…
Reference in New Issue