Skip to content

Commit

Permalink
complete (source:argument): generate sabbrev completions after normal…
Browse files Browse the repository at this point in the history
… ones
  • Loading branch information
akinomyoga committed Mar 9, 2023
1 parent 5bfbd6f commit a6f168d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -245,6 +245,7 @@
- sabbrev: apply sabbrev to right-hand sides of variable assignments `#D2006` xxxxxxxx
- complete (`source:argument`): fallback to rhs completion also for `name+=rhs` `#D2006` xxxxxxxx
- auto-complete: limit the line length for auto-complete `#D2009` xxxxxxxx
- complete (`source:argument`): generate sabbrev completions after normal completions (motivated by mozirilla213) `#D2011` xxxxxxxx

## Fixes

Expand Down
36 changes: 22 additions & 14 deletions lib/core-complete.sh
Expand Up @@ -5215,20 +5215,7 @@ function ble/complete/source:argument/.generate-user-defined-completion {
fi
}

function ble/complete/source:argument {
local comp_opts=:

ble/complete/source:sabbrev

# failglob で展開に失敗した時は * を付加して再度展開を試みる
if [[ $comps_flags == *f* && $COMPS != *\* && :$comp_type: != *:[maA]:* ]]; then
local ret simple_flags simple_ibrace
ble/syntax:bash/simple-word/reconstruct-incomplete-word "$COMPS"
ble/complete/source/eval-simple-word "$ret*" && ((${#ret[*]})) &&
ble/complete/cand/yield-filenames file "${ret[@]}"
(($?==148)) && return 148
fi

function ble/complete/source:argument/generate {
local old_cand_count=$cand_count

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -5273,11 +5260,32 @@ function ble/complete/source:argument {
ble/complete/source/test-limit "${#ret[@]}" || return 1
ble/complete/cand/yield.initialize file_rhs
for cand in "${ret[@]}"; do
((cand_iloop++%bleopt_complete_polling_cycle==0)) && ble/complete/check-cancel && return 148
[[ -e $cand || -h $cand ]] || continue
[[ $FIGNORE ]] && ! ble/complete/.fignore/filter "$cand" && continue
ble/complete/cand/yield file_rhs "$prefix$cand" "$prefix"
done
fi

((cand_count>old_cand_count))
}

function ble/complete/source:argument {
local comp_opts=:

# failglob で展開に失敗した時は * を付加して再度展開を試みる
if [[ $comps_flags == *f* && $COMPS != *\* && :$comp_type: != *:[maA]:* ]]; then
local ret simple_flags simple_ibrace
ble/syntax:bash/simple-word/reconstruct-incomplete-word "$COMPS"
ble/complete/source/eval-simple-word "$ret*" && ((${#ret[*]})) &&
ble/complete/cand/yield-filenames file "${ret[@]}"
(($?==148)) && return 148
fi

ble/complete/source:argument/generate
(($?==148)) && return 148

ble/complete/source:sabbrev
}

# source:variable
Expand Down
49 changes: 49 additions & 0 deletions note.txt
Expand Up @@ -6630,6 +6630,55 @@ bash_tips

2023-03-08

* 2023-03-02 complete (source:argument): sabbrev 候補が気になるのは最初に表示されるから? (motivated by mozirilla213) [#D2011]
https://github.com/akinomyoga/ble.sh/discussions/288

後ろに回した方が良い気がする。修正した。

コマンド補間についても同様ではないか? と思ったが変数名よりは sabbrev の方が
先に来て欲しい。コマンド名と sabbrev だとどちらが先にくる事を期待するのかは
微妙である。コマンドは基本的に大量にある。一方で、sabbrev は有限個である。
具体的にコマンド名を入力してコマンド名が絞れてきた頃には sabbrev も絞られて
いると期待される。なので、コマンド名に関しては表示しなくて良い気がしてきた。

然しそう考えると引数の場合も本当に sabbrev を後回しにするべきなのか分からな
い。と思ったが、引数補間の場合にはオプションの数は少ない可能性がある。一方
で予め定義しておいた sabbrev が大量に存在している時には、sabbrev 候補で全部
が埋め尽くされて実際に知りたいオプションのリストを見る事ができなくなる。な
のでやはり引数補間の場合には sabbrev 候補は後ろに回すべきである。

* [棄却] prompt: $PWD in airline が更新されない? [#D2010]
https://github.com/akinomyoga/ble.sh/discussions/294#discussioncomment-5227252

bind -x の中でディレクトリを移動してもそれが反映されたりされなかったりする
という事。うーん。\w を使っていればちゃんと反映されるのではないか。

直接 $PWD があれば自動的に抽出される筈だし \w や \W があっても抽出されるの
では? と思ったが、勝手に変更をリアルタイムで追跡するのは変だという事になっ
た様な気もする。例えばコマンド終了直後の値を表示しておきたいのにすぐに変わっ
てしまっては困るのである。

然しそうだとしても別の理由でプロンプトの再評価が起こった時に結局表示が更新
されてしまうのだから、そういう揮発性の情報を表示する時には元より ble.sh で
はちゃんと別の変数に記録しておく必要があるのではないか。

→実際試してみると \w にしておけばちゃんと反映される。$PWD だと反映されない。
section 毎のキャッシュがちゃんと働いているからであろう。

これに関しては更新したければ適切に設計する必要がある。

* ok: wiki に説明を書く? と思ったら既にちゃんと add-hash が記述されていた。

実際に簡単なものを作って実演してみる(以下)。動いている。これは後で返信する。
これに関しては現状で修正する事はない気がする。

function ble/prompt/backslash:mypwd {
ble/prompt/unit/add-hash '$PWD'
ble/prompt/print "$PWD"
}
bleopt vim_airline_section_c='\q{mypwd}'
bind -x '"\C-t": cd - &>/dev/null'

* complete: limit line length for auto-complete [#D2009]

"a @b" の時に @ に { を入力すると固まる
Expand Down

0 comments on commit a6f168d

Please sign in to comment.