Skip to content

Commit 226ad22

Browse files
authored
feat: enable JIT detection of ls flavor (#348)
When utilizing direnv and nix on darwin, you can enter directories and have the ls flavor change from BSD to GNU. This change fixes those cases by not caching which ls flavor we found at initialization time and instead JIT'ing which flavor we have at each execution point.
2 parents b5e81bd + 2b2a0d9 commit 226ad22

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/git/shell_shortcuts.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ fi
9898
# Function wrapper around 'll'
9999
# Adds numbered shortcuts to output of ls -l, just like 'git status'
100100
if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby >/dev/null 2>&1; then
101-
# BSD ls is different to Linux (GNU) ls
102-
# Test for BSD ls
103-
if ! (ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then
104-
# ls is BSD
105-
_ls_bsd="BSD"
106-
fi
107-
108101
# Test if readlink supports -f option, test for greadlink on Mac, then fallback to perl
109102
if \readlink -f / >/dev/null 2>&1; then
110103
_abs_path_command=(readlink -f)
@@ -117,14 +110,20 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby >/dev/nul
117110
unalias ll >/dev/null 2>&1
118111
unset -f ll >/dev/null 2>&1
119112
function ls_with_file_shortcuts {
113+
# BSD ls is different to Linux (GNU) ls
114+
if ! (\ls --version 2>/dev/null || echo "BSD") | grep GNU >/dev/null 2>&1; then
115+
# ls is BSD
116+
local _ls_bsd="BSD"
117+
fi
118+
120119
local ll_output
121120
local ll_command # Ensure sort ordering of the two invocations is the same
122121
if [ "$_ls_bsd" != "BSD" ]; then
123122
ll_command=(\ls -hv --group-directories-first)
124123
ll_output="$("${ll_command[@]}" -l --color "$@")"
125124
else
126125
ll_command=(\ls)
127-
ll_output="$(CLICOLOR_FORCE=1 "${ll_command[@]}" -lG "$@")"
126+
ll_output="$("${ll_command[@]}" -lG --color=always "$@")"
128127
fi
129128

130129
if breeze_shell_is "zsh"; then
@@ -215,7 +214,7 @@ EOF
215214
if [ -z $_ls_bsd ]; then
216215
ll_files="$(QUOTING_STYLE=literal "${ll_command[@]}" --color=never "$@")"
217216
else
218-
ll_files="$("${ll_command[@]}" "$@")"
217+
ll_files="$("${ll_command[@]}" --color=never "$@")"
219218
fi
220219

221220
local IFS=$'\n'

0 commit comments

Comments
 (0)