diff --git a/scripts/config.sh b/scripts/config.sh index 44f47d1..6deee7a 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -14,6 +14,25 @@ function check_pattern() { fi } +function identity_fn() { + echo -ne "$1" +} + +function export_option() { + local option_name="$(echo $1 | tr '[:lower:]' '[:upper:]' | sed "s/-/_/g")" + local default_value="$2" + local transform_fn="$3" + + local option_value=$(tmux show-option -gqv "@$1") + local final_value="${option_value:-$default_value}" + + if [[ ! -z "$transform_fn" ]]; then + final_value="$($transform_fn "$final_value")" + fi + + eval "export ${option_name}=\"$(echo -e "$final_value")\"" +} + source "$CURRENT_DIR/utils.sh" PATTERNS_LIST=( @@ -45,12 +64,19 @@ done PATTERNS=$(array_join "|" "${PATTERNS_LIST[@]}") export PATTERNS -DEFAULT_FINGER_COMPACT_HINTS=1 -FINGERS_COMPACT_HINTS=$(tmux show-option -gqv @fingers-compact-hints) -FINGERS_COMPACT_HINTS=${FINGERS_COMPACT_HINTS:-$DEFAULT_FINGER_COMPACT_HINTS} -export FINGERS_COMPACT_HINTS +export_option 'fingers-compact-hints' 1 +export_option 'fingers-hint-format' 1 +export_option 'fingers-copy-command' "" -export FINGERS_HINT_FORMAT=$(echo -e "\033[30;1;43m%s\033[0m") -export FINGERS_HIGHLIGHT_FORMAT=$(echo -e "\033[1;33m%s\033[0m") -export FINGERS_HINT_FORMAT_SECONDARY=$(echo -e "\033[1;33m[%s]\033[0m") -export FINGERS_HIGHLIGHT_FORMAT_SECONDARY=$(echo -e "\033[1;33m%s\033[0m ") +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 diff --git a/scripts/fingers.sh b/scripts/fingers.sh index 1c70a57..6c28d13 100755 --- a/scripts/fingers.sh +++ b/scripts/fingers.sh @@ -8,8 +8,6 @@ source $CURRENT_DIR/hints.sh source $CURRENT_DIR/utils.sh source $CURRENT_DIR/help.sh -FINGERS_COPY_COMMAND=$(tmux show-option -gqv @fingers-copy-command) - current_pane_id=$1 fingers_pane_id=$2 pane_input_temp=$3 diff --git a/scripts/print.sh b/scripts/print.sh new file mode 100755 index 0000000..ccad91a --- /dev/null +++ b/scripts/print.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +tmux_format="TMUX_PRINTER_FORMAT${1}TMUX_PRINTER_FORMAT_END" +style_conf=$(mktemp "/tmp/tmux-printer.XXXXXX") +empty_conf=$(mktemp "/tmp/tmux-printer.XXXXXX") + +touch "$empty_conf" +echo "set -g status-left '$tmux_format'" >> "$style_conf" +echo "set -g status-left-length 255" >> "$style_conf" +echo "set -g status-right ''" >> "$style_conf" + +PREV_TMUX=$TMUX +TMUX='' + +tmux -L tmux-printer-outer -f "$empty_conf" new -s tmux-printer-outer -d +tmux -L tmux-printer-outer send-keys "TMUX='' tmux -L tmux-printer-inner -f \"$style_conf\"" +tmux -L tmux-printer-outer send-keys Enter +sleep 0.1 # tmux wait? +output=$( \ + tmux -L tmux-printer-outer capture-pane -p -e | \ + grep --color=never -Eo "TMUX_PRINTER_FORMAT.*TMUX_PRINTER_FORMAT_END" | \ + sed "s/TMUX_PRINTER_FORMAT\(_END\)\?//g" \ + ) + +tmux -L tmux-printer-outer kill-server +tmux -L tmux-printer-inner kill-server + +TMUX=$PREV_TMUX + +echo -ne "$output$(tput sgr0)"