Skip to content

Commit

Permalink
complete: add completion integration with "zoxide"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 9, 2022
1 parent 973ae8c commit a96bafe
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contrib
3 changes: 2 additions & 1 deletion docs/ChangeLog.md
Expand Up @@ -364,7 +364,8 @@
- progcomp: work around the cobra V2 description hack (reported by SuperSandro2000) `#D1803` 71d0736
- complete: work around blocking `_scp_remote_files` and `_dnf` (reported by iantra) `#D1807` a4a779e 46f5c13
- history: work around broken timestamps in `HISTFILE` (reported by johnyaku) `#D1831` 5ef28eb
- progcomp: disable `command_not_found_handle` (reported by telometto, wisnoskij) `#D1834` 64d471a d5fe1d1 XXXXXXX
- progcomp: disable `command_not_found_handle` (reported by telometto, wisnoskij) `#D1834` 64d471a d5fe1d1 973ae8c
- complete: add completion integration with `zoxide` (reported by ferdinandyb) `#D1838` XXXXXXX

## Internal changes and fixes

Expand Down
6 changes: 6 additions & 0 deletions lib/core-complete.sh
Expand Up @@ -3490,6 +3490,12 @@ function ble/complete/progcomp/.compgen {
ble/util/conditional-sync \
ble/function#advice/do \
"! ble/complete/check-cancel <&$_ble_util_fd_stdin" 128 progressive-weight:killall' 2>/dev/null

# WA for zoxide TAB
if [[ $comp_func == _z ]]; then
ble-import -f contrib/integration/zoxide
ble/contrib:integration/zoxide/adjust
fi
fi
if [[ $comp_prog ]]; then
# aws
Expand Down
49 changes: 49 additions & 0 deletions memo/D1838.bashrc
@@ -0,0 +1,49 @@
# bashrc -*- mode: sh; mode: sh-bash -*-

# 2022-07-10 Debug fzf & zoxide completion

source ~/.mwg/src/ble.sh/out/ble.sh --norc
_ble_contrib_fzf_base=~/.mwg/git/junegunn/fzf
if [[ ${BLE_VERSION-} ]]; then
ble-import -d contrib/fzf-completion
ble-import -d contrib/fzf-key-bindings
#eval "$(zoxide init bash | grep -v '\\\e\[[0-9]n')"
eval "$(zoxide init bash)"

function _z() {
[[ :$comp_type: == *:auto:* || :$comp_type: == *:[maA]:* ]] && return
compopt -o noquote
#--------------------------------------------------------------------------

# Only show completions when the cursor is at the end of the line.
[[ ${#COMP_WORDS[@]} -eq $((COMP_CWORD + 1)) ]] || return

# If there is only one argument, use `cd` completions.
if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then
\builtin mapfile -t COMPREPLY < \
<(\builtin compgen -A directory -S / -- "${COMP_WORDS[-1]}" || \builtin true)
# If there is a space after the last word, use interactive selection.
elif [[ -z ${COMP_WORDS[-1]} ]]; then
\builtin local result
result="$(\command zoxide query -i -- "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}")" &&
COMPREPLY=("${__zoxide_z_prefix}${result@Q}")
\builtin printf '\e[5n'
fi

ble/textarea#invalidate

#--------------------------------------------------------------------------
# 単一候補生成の場合は他の候補 (sabbrev 等) を消去して単一確定させる
if ((ADVICE_EXIT==0&&${#COMPREPLY[@]}==1)); then
ble/complete/candidates/clear
[[ $old_cand_count ]] &&
! ble/variable#is-global old_cand_count &&
old_cand_count=0
fi
} >/dev/null

else
PATH=$PWD/bin:$PATH
source "$_ble_contrib_fzf_base/shell/completion.bash"
eval "$(zoxide init bash)"
fi
35 changes: 35 additions & 0 deletions note.txt
Expand Up @@ -6461,6 +6461,41 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-07-10

* complete: zoxide completion が動かない (reported by ferdinandyb) [#D1838]
https://github.com/akinomyoga/ble.sh/issues/207

zoxide も fzf と同様の戦略を用いている。

* ok: zoxide については (以前試した時の fzf と違って) stdout/stderr をちゃ
んと繋ぎ変えている様だ? 或いは単に中で呼び出している最新の fzf が
stdout,stderr を /dev/tty に繋ぎ変えているだけかもしれないが。

* ok: zoxide は中で \builtin bind や \builtin printf を用いているので振る舞
いを上書きするのは困難である。builtin を上書きしようにも \builtin local
も使われている事からこれを関数の中で実行する訳にも行かない。

或いは printf, bind を enable で一時的に削除するという事も可能かもしれな
いが色々テストするのが面倒である。

というより stdout は封じているのだし、bind は特に悪さをするという訳でもな
い様な気がするので単にそのまま放置していても特に問題は起こらないのでは。
→取り敢えずそのままにしておいても特に問題は生じていない様な気がする。

x 生成した候補がちゃんと反映されない。何故だろうか。

と思ったら分かったかもしれない。何か端末に送信している為に端末からの返答
が届いていて is-stdin-ready に引っ掛かって補完がキャンセルされている。

% うーん。そしてそれは恐らく 1 ではなくて独自に開いた /dev/tty 経由で送信
% されているので抑制する方法がない。

% → \builtin printf をコメントアウトしたら動く様になった。というか既定で
% は stdout/stderr は抑制していなかった様な気もする。然し、builtin printf
% を抑制する方法がないので困る。と思ったが全体を >/dev/null としてしまえ
% ば良いのでは? 実際にその様にして見たら動く様だ。

2022-07-09

* fzf kill completion が動かない (reported by ferdinandyb) [#D1837]
Expand Down

0 comments on commit a96bafe

Please sign in to comment.