user configurable patterns

This commit is contained in:
Jorge Morante 2016-04-30 00:35:52 +02:00
parent fce012bb93
commit f3d392f63d
6 changed files with 76 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
fingers.log
copy-test.txt

42
scripts/config.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
DIRNAME="$(dirname "$0")"
function check_pattern() {
echo "beep beep" | grep -e "$1" 2> /dev/null
if [[ $? == "2" ]]; then
echo 0
else
echo 1
fi
}
source "$DIRNAME/utils.sh"
PATTERNS_LIST=(
"((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*)"
"([[:digit:]]{5,})"
"([0-9a-f]{7}|[0-9a-f]{40})"
)
IFS=$'\n'
USER_DEFINED_PATTERNS=($(tmux show-options -g | grep ^@fingers-pattern | sed 's/^@fingers-pattern-[0-9] "\(.*\)"$/(\1)/'))
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[@]}")
export PATTERNS

7
scripts/debug.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
DIRNAME="$(dirname "$0")"
function log() {
echo "$1" >> $DIRNAME/../fingers.log
}

View File

@ -1,5 +1,8 @@
#!/bin/bash
DIRNAME="$(dirname "$0")"
source $DIRNAME/config.sh
#TODO move this out of here!
current_pane_id=$1
fingers_pane_id=$2
@ -23,15 +26,13 @@ function fancy() {
clear_screen
PATTERNS=
lines=''
while read -r line
do
lines+="$line\n"
done < /dev/stdin
matches=`echo -e $lines | (grep -oniE "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*)|([[:digit:]]{5,})|([0-9a-f]{7,40})" 2> /dev/null) | sort -u`
matches=`echo -e $lines | (grep -oniE "$PATTERNS" 2> /dev/null) | sort -u`
match_count=`echo "$matches" | wc -l`
output="$lines"

16
scripts/utils.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
function array_join() {
local IFS="$1"; shift; echo "$*";
}
function array_concat() {
echo "$*"
}
function display_message() {
local original_display_time=$(tmux show-option -gqv display-time)
tmux set-option -g display-time $2
tmux display-message "$1"
tmux set-option -g display-time $original_display_time
}

View File

@ -1,4 +1,8 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
tmux bind-key F run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"
DEFAULT_FINGERS_KEY="F"
FINGERS_KEY=$(tmux show-option -gqv @fingers-key)
FINGERS_KEY=${FINGERS_KEY:-$DEFAULT_FINGERS_KEY}
tmux bind-key $FINGERS_KEY run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"