Skip to content

Commit

Permalink
make the fzf header configurable #116
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Apr 24, 2024
1 parent f8d15d9 commit e9e3184
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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
Expand Down
40 changes: 33 additions & 7 deletions scripts/extrakto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
;;
Expand Down

0 comments on commit e9e3184

Please sign in to comment.