0

So, I'm tweaking my dotfiles to automatically install packages and I want to automatically detect whether the installation script is being ran in a Gitpod workspace. This is what I have at the moment:

if is-executable "gp"; then
    echo "Gitpod detected, not installing <pre-installed package>"
else
    # Continue with installation... rest of code goes here
fi

I know that gp is a command available in Gitpod due to it's CLI and the code above works fine, but it isn't really ideal, assuming that other packages also have the gp command outside of Gitpod (although I don't use them). So, what would be a better way to detect if a Bash script is being ran in Gitpod?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Can you skip the Gitpod check and instead check if the package you're about to install is already installed? That would express your intent better and be less brittle. – John Kugelman Jun 09 '22 at 14:25
  • I was thinking about checking Gitpod so I can automatically rule out packages that are already installed on Gitpod, but for this single scenario, I guess checking if the package is installed would be fine. What about if I needed the Gitpod CLI specifically to run certain commands and I needed to check if it was a Gitpod workspace? – RealStr1ke Jun 09 '22 at 14:33
  • What dot files? Your shell configuration files? Installing packages is something you should do at the *same time* as installing your dot files, not something you should need to repeatedly check for every time a shell starts. (Why check if `gp` is available when you only expect it to be unavailable *once*, instead of just installing it when you know it will be needed later?) – chepner Jun 09 '22 at 14:39
  • Forgot to clarify, this is the installation script of my dotfiles, as in `install.sh`. And yes, I mean shell configuration files. – RealStr1ke Jun 09 '22 at 14:45

1 Answers1

1

You can use this function from the snippet here:

function is::gitpod() {
      # Check for existence of this gitpod-specific file and the ENV var.
      test -e /ide/bin/gitpod-code && test -v GITPOD_REPO_ROOT;
}

Also, if you're interested, check out dotsh, it's already doing what you're trying to do here and even more!

AXON
  • 183
  • 1
  • 5