load configuration with tmux setenv

This commit is contained in:
Jorge Morante 2017-04-23 11:11:24 +02:00
parent 844d6b8315
commit 759fc183c7
5 changed files with 27 additions and 30 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/utils.sh
CONF_CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CONF_CURRENT_DIR/utils.sh
# TODO empty patterns are invalid
function check_pattern() {
@ -14,11 +14,7 @@ function check_pattern() {
fi
}
function identity_fn() {
echo -ne "$1"
}
function export_option() {
function set_option() {
local option_name="$(echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g")"
local default_value="$2"
local transform_fn="$3"
@ -30,10 +26,12 @@ function export_option() {
final_value="$($transform_fn "$final_value")"
fi
eval "export ${option_name}=\"$(echo -e "$final_value")\""
tmux setenv "$option_name" "$(echo -ne "$final_value")"
}
source "$CURRENT_DIR/utils.sh"
function process_format () {
echo -e "$($CONF_CURRENT_DIR/print.sh "$1")\e[0m"
}
PATTERNS_LIST=(
"((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)"
@ -62,21 +60,14 @@ for pattern in "${PATTERNS_LIST[@]}" ; do
done
PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}")
export PATTERNS
export_option 'fingers-compact-hints' 1
export_option 'fingers-hint-format' 1
export_option 'fingers-copy-command' ""
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' "[%%s]" process_format
set_option 'fingers-highlight-format-secondary' " #%%s" process_format
function process_format () {
echo -ne "$($CURRENT_DIR/print.sh "$1")"
}
echo "wtf: $(process_format "#[fg=yellow]%s")" >> $CURRENT_DIR/../fingers.log
export_option 'fingers-hint-format' "#[fg=yellow,bold,reverse]%%s" process_format
export_option 'fingers-highlight-format' "#[fg=yellow,bold]%%s" process_format
export_option 'fingers-hint-format-secondary' "#[fg=yellow,bold][%%s]" process_format
export_option 'fingers-highlight-format-secondary' " #[fg=yellow,bold]%%s" process_format
printenv | grep FINGERS >> $CURRENT_DIR/../fingers.log
# TODO add fingers_bg
# TODO add fingers_fg

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash
# TODO load fingers env
eval "$(tmux show-env -s | grep ^FINGERS)"
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/config.sh
source $CURRENT_DIR/actions.sh
source $CURRENT_DIR/hints.sh
source $CURRENT_DIR/utils.sh
@ -163,3 +165,5 @@ while read -rsn1 char; do
exit 0
done < /dev/tty
log "fingers.sh end"

View File

@ -1,6 +1,6 @@
BEGIN {
n_matches = 0;
COMPACT_HINTS = ENVIRON["COMPACT_HINTS"];
COMPACT_HINTS = ENVIRON["FINGERS_COMPACT_HINTS"];
HINTS[0] = "p"
HINTS[1] = "o"
@ -103,7 +103,7 @@ BEGIN {
HINTS[98] = "as"
HINTS[99] = "aa"
finger_patterns = ENVIRON["FINGER_PATTERNS"];
finger_patterns = ENVIRON["FINGERS_PATTERNS"];
if (COMPACT_HINTS) {
hint_format = ENVIRON["FINGERS_HINT_FORMAT"]

View File

@ -30,7 +30,7 @@ function show_hints() {
local compact_hints=$2
clear_screen "$fingers_pane_id"
get_stdin | COMPACT_HINTS=$compact_hints FINGER_PATTERNS=$PATTERNS gawk -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table
get_stdin | gawk -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table
}
function show_hints_and_swap() {

View File

@ -2,9 +2,11 @@
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/scripts/config.sh
DEFAULT_FINGERS_KEY="F"
FINGERS_KEY=$(tmux show-option -gqv @fingers-key)
FINGERS_KEY=${FINGERS_KEY:-$DEFAULT_FINGERS_KEY}
tmux run -b "$CURRENT_DIR/scripts/health-check.sh"
tmux bind-key $FINGERS_KEY run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh"
tmux bind-key $FINGERS_KEY run-shell "tmux capture-pane -p | $CURRENT_DIR/scripts/tmux-fingers.sh 2> $CURRENT_DIR/../fingers.log"