From 4e29ff39e7b0fc309f10c32021a8536229d8a464 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Tue, 5 Jan 2021 18:02:40 +0100 Subject: [PATCH] bash: fix LS_COLORS The solarize script evalss the output of the dircolors(1) but the LS_COLORS variable gets exported in its environmnent, not the calling shell where we actually need it so ls(1) and other programs wiill inherit it. Therefore, the evaluation of the dircolors(1) output is moved to the change_bg() function in the shell, so that the LS_COLORS variable is available to any children of the shell. The reason why I had missed this is that in most systems I have ls aliased to exa, which does not care about LS_COLORS and has its own coloring system. On cygwin, however, exa is not available and I noticed that the colors were missind; and indeed, on systems with exa the colors are also missing if I run ls as \ls. --- bin/solarize | 5 ----- files/bashrc | 15 +++++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bin/solarize b/bin/solarize index 3d92f81..9f71e8e 100755 --- a/bin/solarize +++ b/bin/solarize @@ -128,11 +128,6 @@ main() { tmux set-environment -g BACKGROUND "$BACKGROUND" tmux source-file "$XDG_CONFIG_HOME/tmux/tmux-colors.conf" fi - - ls_colors="$HOME/.config/dircolors/solarized-$BACKGROUND" - if type dircolors >/dev/null && [ -f "$ls_colors" ]; then - eval "$(dircolors "$ls_colors")" - fi } main diff --git a/files/bashrc b/files/bashrc index 2ac615a..637bfc5 100644 --- a/files/bashrc +++ b/files/bashrc @@ -11,7 +11,7 @@ export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" -export BACKGROUND="dark" +export BACKGROUND="${BACKGROUND:-dark}" export EDITOR="nvim" export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc" export LANG="en_US.UTF-8" @@ -75,7 +75,16 @@ if command -v brew >/dev/null 2>&1; then fi stty -ixon # disable ctrl-s and ctrl-q -command -v solarize >/dev/null && solarize + +change_bg() { + BACKGROUND="$1"; + command -v solarize &>/dev/null && solarize; + + local f="$HOME/.config/dircolors/solarized-$BACKGROUND" + [ -f "$f" ] && type dircolors &>/dev/null && eval "$(dircolors "$f")" +} +export change_bg +change_bg "$BACKGROUND" ############################################################################## # Customize shell options & variables @@ -203,8 +212,6 @@ alias light='change_bg light' mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || return; } -change_bg() { BACKGROUND="$1"; command -v solarize >/dev/null && solarize; } - ############################################################################## # Run external customizations ##############################################################################