Skip to content

Commit 6db4163

Browse files
committed
Use $LS_COLORS to display the colors of the file names if possible.
Close #19.
1 parent 1fa7c03 commit 6db4163

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

k.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ k () {
125125
K_COLOR_OW=$(_k_bsd_to_ansi $LSCOLORS[21] $LSCOLORS[22])
126126
fi
127127

128-
# read colors if linux and $LS_COLORS is defined
129-
# if [[ $(uname) == 'Linux' && -n $LS_COLORS ]]; then
130-
131-
# fi
132-
133128
# ----------------------------------------------------------------------------
134129
# Loop over passed directories and files to display
135130
# ----------------------------------------------------------------------------
@@ -476,7 +471,12 @@ k () {
476471
# But we don't want to quote '.'; so instead we escape the escape manually and use q-
477472
NAME="${${NAME##*/}//$'\e'/\\e}" # also propagate changes to SYMLINK_TARGET below
478473

479-
if [[ $IS_DIRECTORY == 1 ]]; then
474+
if [[ "$LS_COLORS" ]] && ls --color -d . &>/dev/null; then
475+
# We are using an ls that supports using colors from $LS_COLORS (probably GNU ls here)
476+
pushd "${base_dir}" &>/dev/null
477+
NAME="$(ls --color=always -d "$NAME")"
478+
popd &>/dev/null
479+
elif [[ $IS_DIRECTORY == 1 ]]; then
480480
if [[ $IS_WRITABLE_BY_OTHERS == 1 ]]; then
481481
if [[ $HAS_STICKY_BIT == 1 ]]; then
482482
NAME=$'\e['"$K_COLOR_TW"'m'"$NAME"$'\e[0m';

0 commit comments

Comments
 (0)