gitpod icon indicating copy to clipboard operation
gitpod copied to clipboard

Add subcommand to `gp` CLI for detecting if the command was run from Web-VSCode or Desktop-VSCode or other

Open axonasif opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe

Such a shorthand subcommand would be useful for a use case such as:

  • On web, your webserver root address is something
  • But on desktop it may/could be different. So you could run something like gp which ide inside a script and decide upon the result to modify your environment.

Describe the behaviour you'd like

gp which ide tells you the IDE name.

Describe alternatives you've considered

if {
      pgrep -f 'sshd: gitpod@notty' \
        || pgrep -f "$HOME/.vscode-server/bin" \
        || test -e "$HOME/.ssh/authorized_keys";
} 1>/dev/null; then {
  printf '%s\n' "Gitpod on desktop";
  : "http://localhost:3000";
} else {
  printf '%s\n' "Gitpod on da web";
  : "$(gp url 3000)";
} fi

export HMR_HOST="$_"

Additional context

Please see these discord threads:

  • https://discord.com/channels/816244985187008514/1003809353213673542
  • https://discord.com/channels/816244985187008514/959977556692574248

axonasif avatar Aug 08 '22 15:08 axonasif

I don't really understand the intent. Could you put what you want to solve not how?

I am not sure gp ide is great idea, we are allowing multiple IDEs running in the same workspace, you can start from web and desktop then or start from desktop and go back to web without restart in both cases.

akosyakov avatar Aug 09 '22 06:08 akosyakov

The intent is to find out if a dev server is reachable using the localhost address (when using the desktop IDE, e.g. http://localhost:3000) or a Gitpod address (when using the browser IDE, e.g. https://for-bar-n2oi8b9a6wr.ws-eu60.gitpod.io/), because sometimes it's relevant for some developer tools.

medihack avatar Aug 13 '22 20:08 medihack

Hey @akosyakov 👋

I don't really understand the intent. Could you put what you want to solve not how?

As @medihack as described above, we want to know which IDE/ssh server backends are running for use in scripts.

I am not sure gp ide is great idea, we are allowing multiple IDEs running in the same workspace, you can start from web and desktop then or start from desktop and go back to web without restart in both cases.

Great point 🙏 Now after thinking again, I guess instead of trying to detect the specific active backend, it could instead list names for all the running backends. So, one could do something like gp <special-command> | grep -q <ide-backend-name>.

Here's another use case:

  • Imagine you used the ssh command to connect to a workspace.
  • Later, you also attached to an task terminal: gp tasks attach <id>
    • But since the terminal was created earlier by supervisor, so it doesn't have the SSH_CONNECTION variable in it's environment, otherwise we could use that to detect in a script.

axonasif avatar Aug 15 '22 09:08 axonasif

I think you are asking for https://github.com/gitpod-io/gitpod/issues/11849, i.e. you should run gp url <port> and it evaluates it in the context of last focused client and if a client can tunnel then gives you localhost:<port> otherwise exposed URL on internet.

akosyakov avatar Aug 15 '22 09:08 akosyakov

duplicate of https://github.com/gitpod-io/gitpod/issues/11849

akosyakov avatar Aug 15 '22 09:08 akosyakov