From e9e3184aca6ed1068743db8cba4face8b1222ad5 Mon Sep 17 00:00:00 2001 From: Christian Zangl Date: Wed, 24 Apr 2024 23:57:50 +0200 Subject: [PATCH] make the fzf header configurable #116 --- README.md | 2 ++ scripts/extrakto.sh | 40 +++++++++++++++++++++++++++++++++------- scripts/helpers.sh | 4 ++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1a6caad..5a69b60 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ All but `@extrakto_key` are controlled by fzf and must follow its conventions. | `@extrakto_editor` | | This defaults to `$EDITOR` if not set. | | `@extrakto_fzf_layout` |`default` | Control the fzf layout which is "bottom-up" by default. If you prefer "top-down" layout instead set this to `reverse`. In fact, this value is passed to the fzf `--layout` parameter. Possible values are: `default`, `reverse` and `reverse-list` | | `@extrakto_fzf_tool` | `fzf` | Set this to path of fzf if it can't be found in your `PATH`. | +| `@extrakto_fzf_header` | `i c o e f g h` | Define the fzf header to show keys for insert, copy, open, edit, filter, grab and help. You can reorder or omit information you don't need.| | `@extrakto_fzf_unset_default_opts` | `true` | Unsets custom FZF_DEFAULT_OPTS as it can potentially cause problems in extrakto operations | | `@extrakto_open_tool` | `auto` | Set this to path of your own tool or `auto` to use your platforms *open* implementation. | | `@extrakto_popup_position` | `C` | Set position of the tmux popup window. Possible values are in the `display-popup` entry in `man tmux`. Set this to `x,y` to set the x and y positions to `x` and `y` respectively. | @@ -117,6 +118,7 @@ set -g @extrakto_clip_tool "xsel --input --clipboard" # works better for nvim set -g @extrakto_copy_key "tab" # use tab to copy to clipboard set -g @extrakto_insert_key "enter" # use enter to insert selection set -g @extrakto_fzf_unset_default_opts "false" # keep our custom FZF_DEFAULT_OPTS +set -g @extrakto_fzf_header "i c f g" # for small screens shorten the fzf header ``` ## Custom Filters diff --git a/scripts/extrakto.sh b/scripts/extrakto.sh index 13910f2..bd1e281 100755 --- a/scripts/extrakto.sh +++ b/scripts/extrakto.sh @@ -36,6 +36,7 @@ clip_tool=$(get_option "@extrakto_clip_tool") clip_tool_run=$(get_option "@extrakto_clip_tool_run") editor=$(get_option "@extrakto_editor") fzf_tool=$(get_option "@extrakto_fzf_tool") +fzf_header=$(get_option "@extrakto_fzf_header") open_tool=$(get_option "@extrakto_open_tool") copy_key=$(get_option "@extrakto_copy_key") insert_key=$(get_option "@extrakto_insert_key") @@ -146,13 +147,38 @@ capture() { mode=$(get_next_mode "initial") - header_tmpl="${COLORS[BOLD]}${insert_key}${COLORS[OFF]}=insert" - header_tmpl+=", ${COLORS[BOLD]}${copy_key}${COLORS[OFF]}=copy" - [[ -n "$open_tool" ]] && header_tmpl+=", ${COLORS[BOLD]}${open_key}${COLORS[OFF]}=open" - header_tmpl+=", ${COLORS[BOLD]}${edit_key}${COLORS[OFF]}=edit" - header_tmpl+=", ${COLORS[BOLD]}${filter_key}${COLORS[OFF]}=filter [${COLORS[YELLOW]}${COLORS[BOLD]}:filter:${COLORS[OFF]}]" - header_tmpl+=", ${COLORS[BOLD]}${grab_key}${COLORS[OFF]}=grab [${COLORS[YELLOW]}${COLORS[BOLD]}:ga:${COLORS[OFF]}]" - header_tmpl+=", ${COLORS[BOLD]}${help_key}${COLORS[OFF]}=help" + header_tmpl="" + for o in $fzf_header; do + if [[ ! -z $header_tmpl ]]; then + header_tmpl+=", " + fi + case "$o" in + "i") + header_tmpl+="${COLORS[BOLD]}${insert_key}${COLORS[OFF]}=insert" + ;; + "c") + header_tmpl+="${COLORS[BOLD]}${copy_key}${COLORS[OFF]}=copy" + ;; + "o") + [[ -n "$open_tool" ]] && header_tmpl+="${COLORS[BOLD]}${open_key}${COLORS[OFF]}=open" + ;; + "e") + header_tmpl+="${COLORS[BOLD]}${edit_key}${COLORS[OFF]}=edit" + ;; + "f") + header_tmpl+="${COLORS[BOLD]}${filter_key}${COLORS[OFF]}=filter [${COLORS[YELLOW]}${COLORS[BOLD]}:filter:${COLORS[OFF]}]" + ;; + "g") + header_tmpl+="${COLORS[BOLD]}${grab_key}${COLORS[OFF]}=grab [${COLORS[YELLOW]}${COLORS[BOLD]}:ga:${COLORS[OFF]}]" + ;; + "h") + header_tmpl+="${COLORS[BOLD]}${help_key}${COLORS[OFF]}=help" + ;; + *) + header_tmpl+="(config error)" + ;; + esac + done get_cap() { case "$mode" in diff --git a/scripts/helpers.sh b/scripts/helpers.sh index e6133a8..8782629 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -42,6 +42,10 @@ get_option() { echo $(get_tmux_option $option "fzf") ;; + "@extrakto_fzf_header") + echo $(get_tmux_option $option "i c o e f g h") + ;; + "@extrakto_open_tool") echo $(get_tmux_option $option "auto") ;;