Last active
February 23, 2022 23:54
-
-
Save koush/51ee5e4f72e42224b9a06bbbc3cd3796 to your computer and use it in GitHub Desktop.
Put this in your .bash_profile(s) to open VS Code on your local machine while SSH'd into a remote machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this needs to be on the *remote* machine. | |
if [ ! -z "$SSH_CLIENT" ] | |
then | |
function code() { | |
local ssh_client_host=$(echo $SSH_CLIENT | cut -d ' ' -f1) | |
if [ -z "$1" ] | |
then | |
local argpath="." | |
else | |
local argpath="$1" | |
fi | |
# ssh-remote requires a directory | |
local resolved=$(realpath -m $argpath) | |
if [ -f "$resolved" ]; then | |
local resolved=$(dirname $resolved) | |
fi | |
ssh $ssh_client_host code \ | |
--folder-uri=vscode-remote://ssh-remote+$(hostname)$resolved | |
} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
neat!
i'd prefer wrapping the
code()
definition itself in theif
statement checking forSSH_CLIENT
. that way the init file simply doesn't define thecode
function unless it's been started over ssh. this way there's no complication in local logins mode =Dalso using local variables removes the need to unset afterwards