-1

I'm trying to test if a git repository has the showuntrackedfiles option set to no.

My first aproch was:

if test (git config --get status.showuntrackedfiles) = no 
    echo "hi"
else
    echo "bye"
end

but this breaks if showuntrackedfiles is not set.

test: Missing argument at index 2

(Type 'help test' for related documentation)
bye

The only workaround I've found is:

if test (git config --get status.showuntrackedfiles; or echo "") = no 
    echo "hi"
else
    echo "bye"
end

but it seems hacky. Is there a better way of approaching this?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Susensio
  • 820
  • 10
  • 19

1 Answers1

1

No less hacky, but here's a way to see if a command substitution returned nothing:

set output (git config ...)
if test (count $output) -gt 0 -a $output = no; ...

Recall fish variables are lists, so count is checking if the list has more then zero elements.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352