From d3c90c9656d1f6d19cbc5ccddeae8949c780dee5 Mon Sep 17 00:00:00 2001 From: Carl Mercier Date: Mon, 24 May 2021 14:38:33 -0400 Subject: [PATCH 1/3] Fixed indent --- mcfly.fish | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mcfly.fish b/mcfly.fish index cdbbfe2a..27fbfdd1 100644 --- a/mcfly.fish +++ b/mcfly.fish @@ -67,10 +67,10 @@ 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 mcfly_key_bindings From dee9dbb4a7d9eaad7f904d2e4b67d86d59aec83d Mon Sep 17 00:00:00 2001 From: Carl Mercier Date: Mon, 24 May 2021 14:40:36 -0400 Subject: [PATCH 2/3] Detect terminal color and set env on initialization --- mcfly.bash | 6 +++++- mcfly.fish | 9 ++++++++- mcfly.zsh | 6 +++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mcfly.bash b/mcfly.bash index 197fe170..bd7e32cc 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,8 @@ if [[ $- =~ .*i.* ]]; then bind "'\C-r': '\C-amcfly: \e# mcfly search\C-m'" fi fi + + if [[ "$COLORFGBG" =~ \;15$ ]]; then + export MCFLY_LIGHT=TRUE + fi fi diff --git a/mcfly.fish b/mcfly.fish index 27fbfdd1..8d980017 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) @@ -73,5 +73,12 @@ if status is-interactive 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 + end + end + mcfly_key_bindings + mcfly_detect_terminal_color end diff --git a/mcfly.zsh b/mcfly.zsh index 9fda135d..a26fa2ac 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,8 @@ if [[ $- =~ .*i.* ]]; then } zle -N mcfly-history-widget bindkey '^R' mcfly-history-widget + + if [[ "$COLORFGBG" =~ \;15$ ]]; then + export MCFLY_LIGHT=TRUE + fi fi From 55554beb8fd94a12edb3c28ca9ff682b87f59ef8 Mon Sep 17 00:00:00 2001 From: Carl Mercier Date: Wed, 26 May 2021 07:07:51 -0400 Subject: [PATCH 3/3] Detect light mode in Apple Terminal --- mcfly.bash | 2 ++ mcfly.fish | 5 +++++ mcfly.zsh | 2 ++ 3 files changed, 9 insertions(+) diff --git a/mcfly.bash b/mcfly.bash index bd7e32cc..561adcb6 100644 --- a/mcfly.bash +++ b/mcfly.bash @@ -81,5 +81,7 @@ if [[ $- =~ .*i.* ]]; then 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 8d980017..8c6a2264 100644 --- a/mcfly.fish +++ b/mcfly.fish @@ -76,6 +76,11 @@ if status is-interactive 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 diff --git a/mcfly.zsh b/mcfly.zsh index a26fa2ac..fb3c6a2b 100644 --- a/mcfly.zsh +++ b/mcfly.zsh @@ -93,5 +93,7 @@ if [[ $- =~ .*i.* ]]; then 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