dotbot icon indicating copy to clipboard operation
dotbot copied to clipboard

Command output for conditionals appears to fail for Git Bash

Open matthew-brett opened this issue 2 years ago • 1 comments

Please forgive me if I misunderstood the syntax, but I have a clause in my install file for Windows installs:

    ~/Documents/WindowsPowerShell/Profile.ps1 :
      path: Profile.ps1
      if: '[ $(command -v powershell) ]'

This always skips. Investigating, this version of the if clause does not skip:

      if: '[ -d "/c/Windows/System32" ]'

nor does this:

    if '[ `echo` ]'

but this does:

      if: '[ `echo yes` ]'

On the other hand, if I run this from the Git Bash shell, I get the expected "is true" output:

$ if [ `echo yes` ]; then echo 'is true'; fi

Is there something specific going on in Git Bash and the conditional clauses here?

matthew-brett avatar Jun 15 '22 12:06 matthew-brett

You're using bash conditional syntax, which may not be appropriate on Windows.

Dotbot runs the if block using Python's subprocess module, which doesn't guarantee that you'll be running in whatever shell you started in. For example, if you're running the install script in Powershell, the if block will run in the equivalent of cmd.exe.

One solution may be to use Python to check your paths. Something similar to this may work:

if: python -c "import pathlib, sys; sys.exit(0) if pathlib.Path(r'C:\Windows\System32').is_dir() else sys.exit(1)"

kurtmckee avatar Aug 02 '22 13:08 kurtmckee

@matthew-brett closing due to inactivity. If this is not resolved, feel free to re-open.

anishathalye avatar Dec 17 '22 20:12 anishathalye