2016-05-02 21:15:29 +02:00
|
|
|
#!/usr/bin/env bash
|
2016-04-30 00:35:52 +02:00
|
|
|
|
2017-04-23 11:11:24 +02:00
|
|
|
CONF_CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
source $CONF_CURRENT_DIR/utils.sh
|
2016-04-30 00:35:52 +02:00
|
|
|
|
2017-04-23 18:50:13 +02:00
|
|
|
TMUX_PRINTER="$CONF_CURRENT_DIR/../vendor/tmux-printer/tmux-printer"
|
|
|
|
|
2017-05-02 13:08:15 +02:00
|
|
|
declare -A fingers_defaults
|
|
|
|
|
2016-05-08 17:06:02 +02:00
|
|
|
# TODO empty patterns are invalid
|
2016-04-30 00:35:52 +02:00
|
|
|
function check_pattern() {
|
|
|
|
echo "beep beep" | grep -e "$1" 2> /dev/null
|
|
|
|
|
|
|
|
if [[ $? == "2" ]]; then
|
|
|
|
echo 0
|
|
|
|
else
|
|
|
|
echo 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-02 13:08:15 +02:00
|
|
|
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")
|
2017-04-12 08:31:30 +02:00
|
|
|
|
|
|
|
local final_value="${option_value:-$default_value}"
|
|
|
|
|
|
|
|
if [[ ! -z "$transform_fn" ]]; then
|
|
|
|
final_value="$($transform_fn "$final_value")"
|
|
|
|
fi
|
|
|
|
|
2017-05-01 09:06:06 +02:00
|
|
|
tmux setenv -g "$option_name" "$final_value"
|
2017-04-12 08:31:30 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 13:08:15 +02:00
|
|
|
function read_from_config() {
|
|
|
|
tmux show-option -gqv "@$1"
|
|
|
|
}
|
|
|
|
|
2017-04-23 11:11:24 +02:00
|
|
|
function process_format () {
|
2017-05-01 10:03:59 +02:00
|
|
|
echo -ne "$($TMUX_PRINTER "$1")"
|
2017-04-23 11:11:24 +02:00
|
|
|
}
|
2016-04-30 00:35:52 +02:00
|
|
|
|
2017-05-02 13:08:15 +02:00
|
|
|
function strip_format () {
|
|
|
|
echo "$1" | sed "s/#\[[^]]*\]//g"
|
|
|
|
}
|
|
|
|
|
2017-04-02 18:19:15 +02:00
|
|
|
PATTERNS_LIST=(
|
|
|
|
"((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)"
|
|
|
|
"([[:digit:]]{4,})"
|
|
|
|
"([0-9a-f]{7,40})"
|
|
|
|
"((https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*)"
|
|
|
|
"([[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3})"
|
|
|
|
)
|
2016-04-30 00:35:52 +02:00
|
|
|
|
|
|
|
IFS=$'\n'
|
2016-10-21 22:28:24 +02:00
|
|
|
USER_DEFINED_PATTERNS=($(tmux show-options -g | sed -n 's/^@fingers-pattern-[0-9]\{1,\} "\(.*\)"$/(\1)/p'))
|
2016-04-30 00:35:52 +02:00
|
|
|
unset IFS
|
|
|
|
|
|
|
|
PATTERNS_LIST=("${PATTERNS_LIST[@]}" "${USER_DEFINED_PATTERNS[@]}")
|
|
|
|
|
|
|
|
i=0
|
|
|
|
for pattern in "${PATTERNS_LIST[@]}" ; do
|
|
|
|
is_pattern_good=$(check_pattern "$pattern")
|
|
|
|
|
|
|
|
if [[ $is_pattern_good == 0 ]]; then
|
|
|
|
display_message "fingers-error: bad user defined pattern $pattern" 5000
|
|
|
|
PATTERNS_LIST[$i]="nope{4000}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
i=$((i + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}")
|
2017-04-12 08:31:30 +02:00
|
|
|
|
2017-05-02 13:08:15 +02:00
|
|
|
fingers_defaults=( \
|
|
|
|
[fingers-patterns]="$PATTERNS" \
|
|
|
|
[fingers-compact-hints]=1 \
|
|
|
|
[fingers-copy-command]="" \
|
2018-02-14 22:54:02 +01:00
|
|
|
[fingers-copy-command-uppercase]="" \
|
2017-05-02 15:46:28 +02:00
|
|
|
|
|
|
|
[fingers-hint-position]="left" \
|
|
|
|
[fingers-hint-format]="#[fg=yellow,bold]%s" \
|
2017-10-06 18:18:32 +02:00
|
|
|
[fingers-highlight-format]="#[fg=yellow,nobold,dim]%s" \
|
2017-05-02 15:46:28 +02:00
|
|
|
|
|
|
|
[fingers-hint-position-nocompact]="right" \
|
|
|
|
[fingers-hint-format-nocompact]="#[fg=yellow,bold][%s]" \
|
2017-10-06 18:18:32 +02:00
|
|
|
[fingers-highlight-format-nocompact]="#[fg=yellow,nobold,dim]%s" \
|
2017-05-02 13:08:15 +02:00
|
|
|
)
|
2017-02-14 08:41:27 +01:00
|
|
|
|
2017-05-02 13:08:15 +02:00
|
|
|
set_tmux_env 'fingers-patterns'
|
|
|
|
set_tmux_env 'fingers-compact-hints'
|
|
|
|
set_tmux_env 'fingers-copy-command'
|
2018-02-14 22:54:02 +01:00
|
|
|
set_tmux_env 'fingers-copy-command-uppercase'
|
2017-05-02 15:34:08 +02:00
|
|
|
|
2017-05-02 15:22:07 +02:00
|
|
|
set_tmux_env 'fingers-hint-position'
|
2017-05-02 13:08:15 +02:00
|
|
|
set_tmux_env 'fingers-hint-format' process_format
|
|
|
|
set_tmux_env 'fingers-highlight-format' process_format
|
|
|
|
|
2017-05-02 15:46:28 +02:00
|
|
|
set_tmux_env 'fingers-hint-position-nocompact'
|
|
|
|
set_tmux_env 'fingers-hint-format-nocompact' process_format
|
|
|
|
set_tmux_env 'fingers-highlight-format-nocompact' process_format
|
|
|
|
|
2017-05-02 15:34:08 +02:00
|
|
|
|
2017-05-02 15:46:28 +02:00
|
|
|
for option in fingers-{hint,highlight}-format{,-nocompact}; do
|
2017-05-02 13:08:15 +02:00
|
|
|
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
|