diff --git a/scripts/config.sh b/scripts/config.sh index b430117..82ef374 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -5,6 +5,8 @@ source $CONF_CURRENT_DIR/utils.sh TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer" +declare -A fingers_defaults + # TODO empty patterns are invalid function check_pattern() { echo "beep beep" | grep -e "$1" 2> /dev/null @@ -16,12 +18,17 @@ function check_pattern() { fi } -function set_option() { - local option_name="$(echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g")" - local default_value="$2" - local transform_fn="$3" +function envify() { + echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g" +} + +function set_tmux_env() { + local option_name="$(envify $1)" + local default_value="${fingers_defaults[$1]}" + local transform_fn="$2" + + option_value=$(read_from_config "$1") - local option_value=$(tmux show-option -gqv "@$1") local final_value="${option_value:-$default_value}" if [[ ! -z "$transform_fn" ]]; then @@ -31,10 +38,18 @@ function set_option() { tmux setenv -g "$option_name" "$final_value" } +function read_from_config() { + tmux show-option -gqv "@$1" +} + function process_format () { echo -ne "$($TMUX_PRINTER "$1")" } +function strip_format () { + echo "$1" | sed "s/#\[[^]]*\]//g" +} + PATTERNS_LIST=( "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)" "([[:digit:]]{4,})" @@ -63,13 +78,27 @@ done PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}") -set_option 'fingers-patterns' "$PATTERNS" -set_option 'fingers-compact-hints' 1 -set_option 'fingers-copy-command' "" -set_option 'fingers-hint-format' "#[fg=yellow,bold,reverse]%s" process_format -set_option 'fingers-highlight-format' "#[fg=yellow,bold]%s" process_format -set_option 'fingers-hint-format-secondary' "#[fg=yellow,bold] [%s]" process_format -set_option 'fingers-highlight-format-secondary' "#[fg=yellow,bold]%s" process_format +fingers_defaults=( \ + [fingers-patterns]="$PATTERNS" \ + [fingers-compact-hints]=1 \ + [fingers-copy-command]="" \ + [fingers-hint-format]="#[fg=yellow,bold,reverse]%s" \ + [fingers-highlight-format]="#[fg=yellow,bold]%s" \ + [fingers-hint-format-secondary]="#[fg=yellow,bold] [%s]" \ + [fingers-highlight-format-secondary]="#[fg=yellow,bold]%s" \ +) -# TODO add fingers_bg -# TODO add fingers_fg +set_tmux_env 'fingers-patterns' +set_tmux_env 'fingers-compact-hints' +set_tmux_env 'fingers-copy-command' +set_tmux_env 'fingers-hint-format' process_format +set_tmux_env 'fingers-highlight-format' process_format +set_tmux_env 'fingers-hint-format-secondary' process_format +set_tmux_env 'fingers-highlight-format-secondary' process_format + +for option in fingers-{hint,highlight}-format{,-secondary}; do + env_name="$(envify "$option")_NOCOLOR" + option_value="$(read_from_config "$option")" + default_value="${fingers_defaults[$option]}" + tmux setenv -g "$env_name" "$(strip_format "${option_value:-$default_value}")" +done diff --git a/scripts/hinter.awk b/scripts/hinter.awk index fb6b9b0..3978769 100644 --- a/scripts/hinter.awk +++ b/scripts/hinter.awk @@ -107,11 +107,15 @@ BEGIN { if (COMPACT_HINTS) { hint_format = ENVIRON["FINGERS_HINT_FORMAT"] + hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_NOCOLOR"] highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT"] + highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOLOR"] compound_format = hint_format highlight_format } else { hint_format = ENVIRON["FINGERS_HINT_FORMAT_SECONDARY"] highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_SECONDARY"] + hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_SECONDARY_NOCOLOR"] + highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_SECONDARY_NOCOLOR"] compound_format = highlight_format hint_format } @@ -139,7 +143,7 @@ BEGIN { hint_lookup = hint_lookup hint ":" line_match "\n" if (COMPACT_HINTS) { - hint_len = length(hint) + hint_len = length(sprintf(hint_format_nocolor, hint)) line_match = substr(line_match, hint_len + 1, length(line_match) - hint_len); hint_match = sprintf(compound_format, hint, line_match); } else {