SchoofsKelvin / vscode-sshfs

Extension for Visual Studio Code: File system provider using SSH
GNU General Public License v3.0
543 stars 36 forks source link

Opening files via commandline in 2022 #335

Closed luckman212 closed 2 years ago

luckman212 commented 2 years ago

Originally posted by @SchoofsKelvin in https://github.com/SchoofsKelvin/vscode-sshfs/issues/160#issuecomment-655045830

While directly using code ssh://... still isn't supported, code --file-uri ssh://a/file and code --folder-uri ssh://a/folder are now.

luckman212 commented 2 years ago

I want to first thank you for this very useful extension! It's really coming in handy.

I am wanting to use the commandline / URI scheme to open some remote files, but am not having any luck. I tried e.g.

code --file-uri ssh://r1/usr/local/

where r1 is the name of one of my configs. But it did nothing. Code opens, but the workspace was empty. The --folder-uri parameter seems to work...

code --folder-uri ssh://r1/

but if I want to automate opening up a session to a particular host with a few files & folders visible, I am not sure how to do it, or if it's even possible... I'm using VSCode 1.67.1 on macOS... 🙏

luckman212 commented 2 years ago

I figured out a very clunky workaround... I am sure there must be a better way!

save this as e.g. sshfs-opener.sh and chmod +x it:

#!/usr/bin/env bash

case $1 in
  ''|-h|--help) echo "usage: ${0##*/} <host> [file1,file2...]"; exit;;
esac

host=$1

if code --reuse-window --folder-uri ssh://${host}/ ; then
  shift
  while (( $# > 0 )) ; do
    code --reuse-window --file-uri ssh://${host}$1
    shift
  done
fi

Then, run e.g. sshfs-opener.sh myhost1.foo /usr/local/www/js/script.js /etc/resolv.conf /home/fileA.txt

SchoofsKelvin commented 2 years ago

My extension just makes it that inside VS Code ssh://<host>/<path> URIs are handled properly, i.e. looking for an existing config for <host> or making one on the fly if it looks like username@host (this last bit might not be released yet and just be something I have on a feature branch, not sure).

It doesn't look like VS Code improved their CLI to accept any URI, e.g. code ssh://<host>/<path>/. Sadly enough not something I can fix but an improvement that VS Code has to add.