laktak / extrakto

extrakto for tmux - quickly select, copy/insert/complete text without a mouse
MIT License
878 stars 45 forks source link

Use current word as initial query for fzf #114

Closed bonnefoi closed 3 months ago

bonnefoi commented 8 months ago

Hello,

I have modified extrakto.sh to use a query initialized to the current word before the cursor:

        esac
    }
    query="$($HOME/bin/tmux_get_cursor_position)"
    while true; do
        header=$header_tmpl
        header=${header/:ga:/$grab_area}
        header=${header/:filter:/$mode}

The content of the script tmux_get_cursor_position:

# from https://unix.stackexchange.com/questions/714209/get-cursor-location-in-tty-without-reading-from-stdin-need-help-with-redirectio/714322#714322
#!/bin/bash
_fetch_cursor_position() {
  local pos
  pos="$(tmux display-message -p -F '#{cursor_x} #{cursor_y}')"
  _cursor_row="${pos#* }"
  _cursor_col="${pos% *}"
}
_fetch_cursor_position
cursor_line="$(tmux capture-pane -p -S $(( $_cursor_row )) -E $_cursor_row)"
last_word="${cursor_line:0:${_cursor_col}}"
[[ "$last_word" =~ ([^ ])+$ ]]
prefix="${BASH_REMATCH}"
echo $prefix

Do you think it's possible to make it works as the query is added to the result ?

laktak commented 6 months ago

Sorry, I missed your question ... although I'm not exactly sure what you are asking. Are you trying to make it work like autocomplete?