diff --git a/mcfly.bash b/mcfly.bash index 197fe170..561adcb6 100644 --- a/mcfly.bash +++ b/mcfly.bash @@ -59,7 +59,7 @@ function mcfly_prompt_command { # Set $PROMPT_COMMAND run mcfly_prompt_command and then any existing $PROMPT_COMMAND. PROMPT_COMMAND="mcfly_prompt_command;$PROMPT_COMMAND" -# If this is an interactive shell, take ownership of ctrl-r. +# If this is an interactive shell, take ownership of ctrl-r and set terminal color. if [[ $- =~ .*i.* ]]; then if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then # shellcheck disable=SC2016 @@ -78,4 +78,10 @@ if [[ $- =~ .*i.* ]]; then bind "'\C-r': '\C-amcfly: \e# mcfly search\C-m'" fi fi + + if [[ "$COLORFGBG" =~ \;15$ ]]; then + export MCFLY_LIGHT=TRUE + elif [[ "$TERM_PROGRAM" == "Apple_Terminal" && $(defaults read -g AppleInterfaceStyle 2> /dev/null) != 'Dark' ]]; then + export MCFLY_LIGHT=TRUE + fi fi diff --git a/mcfly.fish b/mcfly.fish index cdbbfe2a..8c6a2264 100644 --- a/mcfly.fish +++ b/mcfly.fish @@ -42,7 +42,7 @@ function __mcfly_add_command -d 'Add run commands to McFly database' -e fish_pos eval $__MCFLY_CMD add --exit '$last_status' --old-dir '$__MCFLY_OLD_PWD' -- '$argv[1]' end -# If this is an interactive shell, set up key binding functions. +# If this is an interactive shell, set up key binding functions and terminal color. if status is-interactive function __mcfly-history-widget -d "Search command history with McFly" set -l mcfly_output (mktemp -t mcfly.output.XXXXXXXX) @@ -67,11 +67,23 @@ if status is-interactive end function mcfly_key_bindings -d "Default key bindings for McFly" - bind \cr __mcfly-history-widget - if bind -M insert >/dev/null 2>&1 - bind -M insert \cr __mcfly-history-widget - end + bind \cr __mcfly-history-widget + if bind -M insert >/dev/null 2>&1 + bind -M insert \cr __mcfly-history-widget + end + end + + function mcfly_detect_terminal_color -d 'Attempt to determine if running in light mode' + if string match -r '\;15$' $COLORFGBG &> /dev/null + set -gx MCFLY_LIGHT TRUE + else if test "$TERM_PROGRAM" = "Apple_Terminal" + set apple_interface (defaults read -g AppleInterfaceStyle 2> /dev/null) + if [ "$apple_interface" != 'Dark' ] + set -gx MCFLY_LIGHT TRUE + end + end end mcfly_key_bindings + mcfly_detect_terminal_color end diff --git a/mcfly.zsh b/mcfly.zsh index 9fda135d..fb3c6a2b 100644 --- a/mcfly.zsh +++ b/mcfly.zsh @@ -61,7 +61,7 @@ exit_logger() { } zshexit_functions+=(exit_logger) -# If this is an interactive shell, take ownership of ctrl-r. +# If this is an interactive shell, take ownership of ctrl-r and set terminal color. if [[ $- =~ .*i.* ]]; then mcfly-history-widget() { () { @@ -90,4 +90,10 @@ if [[ $- =~ .*i.* ]]; then } zle -N mcfly-history-widget bindkey '^R' mcfly-history-widget + + if [[ "$COLORFGBG" =~ \;15$ ]]; then + export MCFLY_LIGHT=TRUE + elif [[ "$TERM_PROGRAM" == "Apple_Terminal" && $(defaults read -g AppleInterfaceStyle 2> /dev/null) != 'Dark' ]]; then + export MCFLY_LIGHT=TRUE + fi fi