scmbreeze / scm_breeze

Adds numbered shortcuts to the output git status, and much more
https://madebynathan.com/2011/10/19/git-shortcuts-like-youve-never-seen-before/
MIT License
2.82k stars 192 forks source link

Switch to output parse of `--version` to determine ls version #318

Closed ghthor closed 2 years ago

ghthor commented 2 years ago

Alternative to #317 to fix #312.

I don't have a mac to test this on, if someone with a mac could test and confirm this is working as expected that would be excellent.

@patbl

$ if ! ls --version | grep GNU >/dev/null 2>&1; then echo "BSD"; else echo "GNU"; fi
GNU
Thu Jun 23 08:29:15 AM EDT 2022
0 ghthor@hivemind ~/.scm_breeze [test-bsd-ls]
jeffbyrnes commented 2 years ago

On macOS 12.4 Monterey, there is no --version flag:

Jeffs-iMac:~ jeffbyrnes$ ls --version | grep GNU
ls: unrecognized option `--version'
usage: ls [-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]

So it would seem this wonโ€™t work.

ghthor commented 2 years ago

On macOS 12.4 Monterey, there is no --version flag:

OO, we can probably work with this.

Let's try

if ! (ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then echo "BSD"; else echo "GNU"; fi
jeffbyrnes commented 2 years ago

I get

๐Ÿ•™ 11:22:55 jeffbyrnes in ~
โ™  if ! (ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then echo "BSD"; else echo "GNU"; fi
BSD
ghthor commented 2 years ago

I get

๐Ÿ•™ 11:22:55 jeffbyrnes in ~
โ™  if ! (ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then echo "BSD"; else echo "GNU"; fi
BSD

:thumbsup: