Created
December 14, 2025 06:42
-
-
Save petergi/9777350324e257687232c528d97eec58 to your computer and use it in GitHub Desktop.
This is a neat little piece of shell judo. It’s doing capability detection against a Git repository and then falling back gracefully. Conceptually, this is the Unix philosophy in action: attempt the simplest thing, and if reality disagrees, degrade politely.
In other words: optimistic, defensive, and mildly smug—in the best possible way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Try to show the contents of docs/ from the master branch. | |
| # - git show works for files, but may fail for directories. | |
| # - Suppress errors and limit output to 20 lines. | |
| # - If that fails, fall back to listing files under docs/ instead. | |
| # - Always show only the first 20 results to keep output predictable. | |
| git show master:docs/ 2>/dev/null | head -20 \ | |
| || git ls-tree -r master --name-only | grep '^docs/' | head -20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment