diff --git a/README.md b/README.md index d6612b6..639e52a 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,8 @@ set -g @fingers-pattern-1 'yolo' set -g @fingers-pattern-50 'whatever' ``` -Patterns are case insensitive, and grep's extended syntax ( ERE ) should be used. +Patterns are case insensitive, and grep's extended syntax ( ERE ) should be used. Patterns +matching the empty string are disallowed. `man grep` for more info. If the introduced regexp contains an error, an error will be shown when diff --git a/scripts/config.sh b/scripts/config.sh index b90df94..1939fcf 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -7,7 +7,6 @@ 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 @@ -18,6 +17,14 @@ function check_pattern() { fi } +function check_matches_empty_string() { + if ! grep -e "$1" <<< "" >/dev/null; then + echo 0 + else + echo 1 + fi +} + function envify() { echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g" } @@ -109,6 +116,14 @@ for pattern in "${PATTERNS_LIST[@]}" ; do PATTERNS_LIST[$i]="nope{4000}" fi + pattern_matches_empty=$(check_matches_empty_string "$pattern") + + if [[ $pattern_matches_empty == 0 ]]; then + display_message "fingers-error: user defined pattern $pattern matched the empty string" 5000 + PATTERNS_LIST[$i]="nope{4000}" + fi + + i=$((i + 1)) done