Skip to content

Instantly share code, notes, and snippets.

@isaiahtaylor
Last active November 2, 2023 20:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaiahtaylor/201929504151cc389b0b2454e5c29e36 to your computer and use it in GitHub Desktop.
Save isaiahtaylor/201929504151cc389b0b2454e5c29e36 to your computer and use it in GitHub Desktop.
VS Code's "code" command for code-server
#!/bin/bash
set -e
function cleanup {
echo ""
echo "Cleaning up processes"
kill -SIGINT -$GID
}
trap cleanup EXIT
if [ "$1" ]; then
cd $1
fi
module load singularity/3.0.3/go/1.11.5
ipnport="$(shuf -i8000-9999 -n1)"
ipnip="$(hostname -i)"
ipnlogname="/tmp/code-server-$ipnport-$(date +%H.%M.%S).log"
touch $ipnlogname
SINGULARITYENV_PATH=$PATH nohup singularity run <redacted>/code-server_xenial-2.sif -p $ipnport > $ipnlogname 2>&1 &
GID=$$
echo "----------------------CODE SERVER---------------------"
echo "Starting server so you can run VS Code in the browser."
echo ""
echo "To access VS Code on Aeolus in the browser, please run"
echo "this command in a shell on your local machine:"
echo ""
echo "ssh -NL 8443:${ipnip}:${ipnport} $USER@[redacted]"
echo ""
echo "Then, you can access VS Code from your browser:"
echo "https://localhost:8443"
echo ""
echo -n "Getting your one time password..."
ipnpass=
while [[ -z "$ipnpass" ]]; do
sleep 1
echo -n .
set +e
ipnpass="$(grep -oE 'Password:.+\w+' $ipnlogname)"
done
set -e
echo ""
echo "Here is your one-time password to access the session:"
echo -e "${ipnpass}\e[0m"
echo "Please enter it when prompted."
echo ""
echo "When you are finished using VS Code in your browser,"
echo "please kill this script using Ctrl-C."
echo "----------------------CODE SERVER---------------------"
read -r -d '' _ </dev/tty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment