Skip to content

Instantly share code, notes, and snippets.

@mcornella
Forked from koush/.bash_profile
Created January 14, 2022 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcornella/51496b8892028a382f1d5ecd67a4a479 to your computer and use it in GitHub Desktop.
Save mcornella/51496b8892028a382f1d5ecd67a4a479 to your computer and use it in GitHub Desktop.
Put this in your .bash_profile(s) to open VS Code on your local machine when SSH into a remote machine.
# this needs to be on the *remote* machine.
function code() {
if [ -z "$SSH_CLIENT" ]
then
unset -f code
code $@
return
fi
ssh_client_host=$(echo $SSH_CLIENT | cut -d ' ' -f1)
if [ -z "$1" ]
then
argpath="."
else
argpath="$1"
fi
# ssh-remote requires a directory
resolved=$(realpath -m $argpath)
if [ -f "$resolved" ]; then
resolved=$(dirname $resolved)
fi
ssh $ssh_client_host code \
--folder-uri=vscode-remote://ssh-remote+$(hostname)$resolved
unset resolved
unset argpath
unset ssh_client_host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment