handle variable length hint format in compact mode
This commit is contained in:
parent
10f64d892a
commit
acf4fd23ff
|
@ -5,6 +5,8 @@ source $CONF_CURRENT_DIR/utils.sh
|
||||||
|
|
||||||
TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer"
|
TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer"
|
||||||
|
|
||||||
|
declare -A fingers_defaults
|
||||||
|
|
||||||
# TODO empty patterns are invalid
|
# TODO empty patterns are invalid
|
||||||
function check_pattern() {
|
function check_pattern() {
|
||||||
echo "beep beep" | grep -e "$1" 2> /dev/null
|
echo "beep beep" | grep -e "$1" 2> /dev/null
|
||||||
|
@ -16,12 +18,17 @@ function check_pattern() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_option() {
|
function envify() {
|
||||||
local option_name="$(echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g")"
|
echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g"
|
||||||
local default_value="$2"
|
}
|
||||||
local transform_fn="$3"
|
|
||||||
|
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}"
|
local final_value="${option_value:-$default_value}"
|
||||||
|
|
||||||
if [[ ! -z "$transform_fn" ]]; then
|
if [[ ! -z "$transform_fn" ]]; then
|
||||||
|
@ -31,10 +38,18 @@ function set_option() {
|
||||||
tmux setenv -g "$option_name" "$final_value"
|
tmux setenv -g "$option_name" "$final_value"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read_from_config() {
|
||||||
|
tmux show-option -gqv "@$1"
|
||||||
|
}
|
||||||
|
|
||||||
function process_format () {
|
function process_format () {
|
||||||
echo -ne "$($TMUX_PRINTER "$1")"
|
echo -ne "$($TMUX_PRINTER "$1")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function strip_format () {
|
||||||
|
echo "$1" | sed "s/#\[[^]]*\]//g"
|
||||||
|
}
|
||||||
|
|
||||||
PATTERNS_LIST=(
|
PATTERNS_LIST=(
|
||||||
"((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)"
|
"((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)"
|
||||||
"([[:digit:]]{4,})"
|
"([[:digit:]]{4,})"
|
||||||
|
@ -63,13 +78,27 @@ done
|
||||||
|
|
||||||
PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}")
|
PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}")
|
||||||
|
|
||||||
set_option 'fingers-patterns' "$PATTERNS"
|
fingers_defaults=( \
|
||||||
set_option 'fingers-compact-hints' 1
|
[fingers-patterns]="$PATTERNS" \
|
||||||
set_option 'fingers-copy-command' ""
|
[fingers-compact-hints]=1 \
|
||||||
set_option 'fingers-hint-format' "#[fg=yellow,bold,reverse]%s" process_format
|
[fingers-copy-command]="" \
|
||||||
set_option 'fingers-highlight-format' "#[fg=yellow,bold]%s" process_format
|
[fingers-hint-format]="#[fg=yellow,bold,reverse]%s" \
|
||||||
set_option 'fingers-hint-format-secondary' "#[fg=yellow,bold] [%s]" process_format
|
[fingers-highlight-format]="#[fg=yellow,bold]%s" \
|
||||||
set_option 'fingers-highlight-format-secondary' "#[fg=yellow,bold]%s" process_format
|
[fingers-hint-format-secondary]="#[fg=yellow,bold] [%s]" \
|
||||||
|
[fingers-highlight-format-secondary]="#[fg=yellow,bold]%s" \
|
||||||
|
)
|
||||||
|
|
||||||
# TODO add fingers_bg
|
set_tmux_env 'fingers-patterns'
|
||||||
# TODO add fingers_fg
|
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
|
||||||
|
|
|
@ -107,11 +107,15 @@ BEGIN {
|
||||||
|
|
||||||
if (COMPACT_HINTS) {
|
if (COMPACT_HINTS) {
|
||||||
hint_format = ENVIRON["FINGERS_HINT_FORMAT"]
|
hint_format = ENVIRON["FINGERS_HINT_FORMAT"]
|
||||||
|
hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_NOCOLOR"]
|
||||||
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT"]
|
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT"]
|
||||||
|
highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOLOR"]
|
||||||
compound_format = hint_format highlight_format
|
compound_format = hint_format highlight_format
|
||||||
} else {
|
} else {
|
||||||
hint_format = ENVIRON["FINGERS_HINT_FORMAT_SECONDARY"]
|
hint_format = ENVIRON["FINGERS_HINT_FORMAT_SECONDARY"]
|
||||||
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_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
|
compound_format = highlight_format hint_format
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +143,7 @@ BEGIN {
|
||||||
hint_lookup = hint_lookup hint ":" line_match "\n"
|
hint_lookup = hint_lookup hint ":" line_match "\n"
|
||||||
|
|
||||||
if (COMPACT_HINTS) {
|
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);
|
line_match = substr(line_match, hint_len + 1, length(line_match) - hint_len);
|
||||||
hint_match = sprintf(compound_format, hint, line_match);
|
hint_match = sprintf(compound_format, hint, line_match);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue