-2
\$\begingroup\$

The following aliases return all the same number of results, on my Cygwin (on Windows):

file-history1 = log --
file-history2 = log
file-history5 = "!f() { git show -s $(git rev-list --date-order HEAD -- $1); }; f"
file-history6 = !sh -c 'git show -s $(git rev-list --date-order HEAD -- $0)'

But what would be the best / worse ones in there?

I'd like to write portable aliases, that will work similarly on Windows (Cygwin or Git Bash) / Linux / MacOS...

I do have a favor for #5 and #6 as they show that they expect an argument. But that would be disregarded if they don't execute properly on other platforms...

\$\endgroup\$
2
  • \$\begingroup\$ I think you need to be a little bit more specific in regards to portability - what versions of git would you want to support, and which shells? Remember that macos has a really old version of bash and nowadays uses zsh by default. I honestly think the esaiest thing would be to test this in containers of the types of OSes, etc. that you hope to support. \$\endgroup\$
    – ades
    Commented Jan 9, 2022 at 14:24
  • \$\begingroup\$ So, the question comes down to: is the writing of a function more portable than the use of a shell command? \$\endgroup\$ Commented Jan 11, 2022 at 10:02

1 Answer 1

1
\$\begingroup\$

Ignoring other requirements or needs you might have (like what @ades mentions in the first comment) I'd vote for option 2: file-history = log

I'd say that for the sole reasons that

  1. It is simpler
  2. It has no dependencies

As a rule of thumb I've learnt the painful hard way, is simpler means less chance of breaking, lower maintenance/debug costs, easy of understanding for you later or other people, portability, ...

So, if it works for you given any other requirements, I'd say go with the simplest, which looks like (2).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.