diff --git a/ble.pp b/ble.pp index b8acff21..26a19758 100644 --- a/ble.pp +++ b/ble.pp @@ -910,11 +910,52 @@ function ble/base/initialize-cache-directory { fi ble/base/.create-user-directory _ble_base_cache "$cache_dir/$UID" } +function ble/base/migrate-cache-directory/.move { + local old=$1 new=$2 + [[ -e $old ]] || return 0 + if [[ -e $new || -L $old ]]; then + ble/bin/rm -rf "$old" + else + ble/bin/mv "$old" "$new" + fi +} +function ble/base/migrate-cache-directory/.check-old-prefix { + local old_prefix=$_ble_base_cache/$1 + local new_prefix=$_ble_base_cache/$2 + local file + for file in "$old_prefix"*; do + local old=$file + local new=$new_prefix${file#"$old_prefix"} + ble/base/migrate-cache-directory/.move "$old" "$new" + done +} +function ble/base/migrate-cache-directory { + local failglob= + shopt -q failglob && { failglob=1; shopt -u failglob; } + + ble/base/migrate-cache-directory/.check-old-prefix cmap+default.binder-source decode.cmap.allseq + ble/base/migrate-cache-directory/.check-old-prefix cmap+default decode.cmap + ble/base/migrate-cache-directory/.check-old-prefix ble-decode-bind decode.bind + + local file + for file in "$_ble_base_cache"/*.term; do + local old=$file + local new=$_ble_base_cache/term.${file#"$_ble_base_cache/"}; new=${new%.term} + ble/base/migrate-cache-directory/.move "$old" "$new" + done + + ble/base/migrate-cache-directory/.move "$_ble_base_cache/man" "$_ble_base_cache/complete.mandb" + + [[ $failglob ]] && shopt -s failglob +} if ! ble/base/initialize-cache-directory; then ble/util/print "ble.sh: failed to initialize \$_ble_base_cache." 1>&2 builtin unset -v _ble_bash BLE_VERSION BLE_VERSINFO return 1 fi +ble/base/migrate-cache-directory + + function ble/base/print-usage-for-no-argument-command { local name=${FUNCNAME[1]} desc=$1; shift ble/util/print-lines \ @@ -960,7 +1001,13 @@ function ble-update/.make { function ble-update/.reload { local ext=$? if [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then - if [[ $- == *i* && $_ble_attached ]] && ! ble/util/is-running-in-subshell; then + if [[ ! -e $_ble_base/ble.sh ]]; then + ble/util/print "ble-update: new ble.sh not found at '$_ble_base/ble.sh'." >&2 + return 1 + elif [[ ! -s $_ble_base/ble.sh ]]; then + ble/util/print "ble-update: new ble.sh '$_ble_base/ble.sh' is empty." >&2 + return 1 + elif [[ $- == *i* && $_ble_attached ]] && ! ble/util/is-running-in-subshell; then ble-reload fi return $? @@ -1215,6 +1262,11 @@ function ble-attach { _ble_attached= BLE_ATTACHED= ble-edit/detach + ble/term/leave + ble/base/restore-bash-options + ble/base/restore-POSIXLY_CORRECT + ble/base/restore-builtin-wrappers + builtin eval -- "$_ble_bash_FUNCNEST_restore" return 1 fi diff --git a/keymap/emacs.sh b/keymap/emacs.sh index 52628b64..8a103ecd 100644 --- a/keymap/emacs.sh +++ b/keymap/emacs.sh @@ -206,7 +206,8 @@ function ble-decode/keymap:emacs/define { function ble-decode/keymap:emacs/initialize { local fname_keymap_cache=$_ble_base_cache/keymap.emacs - if [[ $fname_keymap_cache -nt $_ble_base/keymap/emacs.sh && + if [[ -s $fname_keymap_cache && + $fname_keymap_cache -nt $_ble_base/keymap/emacs.sh && $fname_keymap_cache -nt $_ble_base/lib/init-cmap.sh ]]; then source "$fname_keymap_cache" && return 0 fi diff --git a/keymap/vi.sh b/keymap/vi.sh index 25c5bcf4..d567743e 100644 --- a/keymap/vi.sh +++ b/keymap/vi.sh @@ -8094,7 +8094,8 @@ function ble-decode/keymap:vi_cmap/define { function ble-decode/keymap:vi/initialize { local fname_keymap_cache=$_ble_base_cache/keymap.vi - if [[ $fname_keymap_cache -nt $_ble_base/keymap/vi.sh && + if [[ -s $fname_keymap_cache && + $fname_keymap_cache -nt $_ble_base/keymap/vi.sh && $fname_keymap_cache -nt $_ble_base/lib/init-cmap.sh ]]; then source "$fname_keymap_cache" && return 0 fi diff --git a/keymap/vi_digraph.sh b/keymap/vi_digraph.sh index 7b2b50e5..f78fe8e8 100644 --- a/keymap/vi_digraph.sh +++ b/keymap/vi_digraph.sh @@ -49,7 +49,8 @@ function ble-decode/keymap:vi_digraph/define { function ble-decode/keymap:vi_digraph/initialize { local fname_keymap_cache=$_ble_base_cache/keymap.vi_digraph - if [[ $fname_keymap_cache -nt $_ble_base/keymap/vi_digraph.sh && + if [[ -s $fname_keymap_cache && + $fname_keymap_cache -nt $_ble_base/keymap/vi_digraph.sh && $fname_keymap_cache -nt $_ble_base/keymap/vi_digraph.txt ]]; then source "$fname_keymap_cache" return 0 diff --git a/lib/core-complete.sh b/lib/core-complete.sh index c21c0a4a..b411f4d0 100644 --- a/lib/core-complete.sh +++ b/lib/core-complete.sh @@ -3057,7 +3057,7 @@ function ble/complete/mandb/.generate-cache { function ble/complete/mandb/load-cache { local command=${1##*/} local lc_messages=${LC_ALL:-${LC_MESSAGES:-${LANG:-C}}} - local fcache=$_ble_base_cache/man/$lc_messages/$command + local fcache=$_ble_base_cache/complete.mandb/$lc_messages/$command if ! [[ -s $fcache && $fcache -nt $_ble_base/lib/core-complete.sh ]]; then [[ -d ${fcache%/*} ]] || ble/bin/mkdir -p "${fcache%/*}" ble/complete/mandb/.generate-cache "$command" >| "$fcache" && diff --git a/lib/init-bind.sh b/lib/init-bind.sh index aa2dfafe..a5496dcd 100644 --- a/lib/init-bind.sh +++ b/lib/init-bind.sh @@ -2,8 +2,8 @@ # 現在の bash の version に従って以下の二つのファイルを生成します: # -# $_ble_base_cache/ble-decode-bind.$_ble_bash.$bleopt_input_encoding.bind -# $_ble_base_cache/ble-decode-bind.$_ble_bash.$bleopt_input_encoding.unbind +# $_ble_base_cache/decode.bind.$_ble_bash.$bleopt_input_encoding.bind +# $_ble_base_cache/decode.bind.$_ble_bash.$bleopt_input_encoding.unbind # # Note: #D1300 bind -s で束縛するマクロの非終端文字は # decode.sh (ble/decode/nonblocking-read) でチェックする必要がある。 @@ -25,8 +25,8 @@ function ble/init:bind/append-macro { } function ble/init:bind/generate-binder { - local fbind1=$_ble_base_cache/ble-decode-bind.$_ble_bash.$bleopt_input_encoding.bind - local fbind2=$_ble_base_cache/ble-decode-bind.$_ble_bash.$bleopt_input_encoding.unbind + local fbind1=$_ble_base_cache/decode.bind.$_ble_bash.$bleopt_input_encoding.bind + local fbind2=$_ble_base_cache/decode.bind.$_ble_bash.$bleopt_input_encoding.unbind ble/edit/info/show text "ble.sh: updating binders..." diff --git a/lib/init-msleep.sh b/lib/init-msleep.sh index 1eb44a27..57bbc546 100644 --- a/lib/init-msleep.sh +++ b/lib/init-msleep.sh @@ -2,7 +2,7 @@ function ble/util/msleep/.load-compiled-builtin/compile { local builtin_path=$1 - [[ -x $builtin_path && $builtin_path -nt $_ble_base/lib/init-msleep.sh ]] && return 0 + [[ -x $builtin_path && -s $builtin_path && $builtin_path -nt $_ble_base/lib/init-msleep.sh ]] && return 0 local CC=cc ble/bin#has gcc && CC=gcc diff --git a/lib/init-msys1.sh b/lib/init-msys1.sh index b0ea2e8b..ca50e72d 100644 --- a/lib/init-msys1.sh +++ b/lib/init-msys1.sh @@ -34,7 +34,7 @@ function ble-edit/io:msys1/get-winpid.proc { } function ble-edit/io:msys1/compile-helper { local helper=$1 - [[ -x $helper && $helper -nt $_ble_base/lib/init-msys1.sh ]] && return 0 + [[ -x $helper && -s $helper && $helper -nt $_ble_base/lib/init-msys1.sh ]] && return 0 # /mingw/bin/gcc local include='#include' # '#' で始まる行はインストール時に消される diff --git a/lib/init-term.sh b/lib/init-term.sh index 5b2a21db..2473631c 100644 --- a/lib/init-term.sh +++ b/lib/init-term.sh @@ -293,7 +293,7 @@ function ble/init:term/initialize { ble/init:term/register-varname "_ble_term_sgr_ab" # save - ble/util/declare-print-definitions "${varnames[@]}" >| "$_ble_base_cache/$TERM.term" + ble/util/declare-print-definitions "${varnames[@]}" >| "$_ble_base_cache/term.$TERM" } ble/util/put "ble/term.sh: updating tput cache for TERM=$TERM... " >&2 diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index dc073da9..71234113 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -118,6 +118,7 @@ - complete: work around `bash-completion` bugs (reported by oc1024) `#D1533` 9d4ad56 - main: work around MSYS2 .inputrc (reported by n1kk) `#D1534` 9e786ae - util (`modifyOtherKeys`): work around a quirk of Kitty (reported by NoahGorny) `#D1549` f599525 +- global: work around empty `vi_imap` cache by `tmux-resurrect` `#D1562` 0000000 ## Internal changes and fixes diff --git a/note.txt b/note.txt index ae7c6f74..024effc0 100644 --- a/note.txt +++ b/note.txt @@ -1272,6 +1272,10 @@ bash_tips bug-bash, third-party bugs ------------------------------------------------------------------------------- +2021-05-20 + + * grc: -F を指定したら正規表現の種類が競合しているとのエラーになる + 2021-05-16 * complete: tar xf groff-1.19.2.ta[TAB] でエラーが発生する @@ -1511,72 +1515,6 @@ bash_tips にならず ^A^A になっているのは関数内で実行している時である。対話でも ^A^A にしかならない。 -2021-05-13 - - * vi_imap が empty と表示されるとの事 - https://github.com/akinomyoga/ble.sh/issues/109 - - "ble.sh: The keymap 'vi_imap' is empty." というエラーメッセージが出るとの事 - だが他には何もメッセージは出ないのだろうか。試しに keymap.vi を空にしてロー - ドしてみると…再現した。 - - * bash ble.sh --clear-cache オプションを実装した方が良い。 - - * ファイルが存在するかどうかのチェックをしている箇所は、全て有限の大きさを持っているかどうかを確認した方が良い。 - - * 空の keymap になっていたらキャッシュ無しで初期化し直す機能を付けた方が良いかもしれない。 - - うーん。何と再現しなくなってしまった様である。 - こうなるとコードを見て憶測で修正するしかなくなる。 - - # { - # ble/decode/keymap#load isearch dump - # ble/decode/keymap#load nsearch dump - # ble/decode/keymap#load vi_imap dump - # ble/decode/keymap#load vi_nmap dump - # ble/decode/keymap#load vi_omap dump - # ble/decode/keymap#load vi_xmap dump - # ble/decode/keymap#load vi_cmap dump - # } 3>| "$fname_keymap_cache" - - あー。もしかすると原因が分かったかもしれない。そもそも前に自分が問題を経験 - した時にもそうだったが、ble/decode/keymap#load を改名した事が原因なのであっ - た。此処で、ble.sh が部分的に更新されていたりすると問題になるという事なのだ - ろうという気がする。tmux-resurrect が一体何をしようとしているのかは結局謎な - のであるが、うーん。 - - そもそも報告者が最新の物でも再現するとかしないとか言っていた時に、毎回 make - をしていたのかというのも疑問の一つである。と思ったが rebuilding と言ってい - るので、其処の所はちゃんとやっているのだろうという気がする。 - - a あー。もしかすると複数の異なる ble.sh を使っていて cache が混合していると - いうのは十分考えられる可能性である。と思ったが本当にそれで問題が発生する - だろうか。何れにしても呼び出す vi.sh は同じディレクトリにいる ble.sh から - 呼び出される筈で中途半端に更新されていない限りは不整合は起こらない筈なの - である。 - - 或いは tmux-resurrect が下手に関数等を保存しているのだとすると変な事が起 - こっても仕方ない → 試しに関数を定義して保存・復元して見たが関数は消滅し - ていた。つまり、そういう事は関係ない。 - - 或いは vi.sh の timestamp が偶然未来に設定されてしまったりする様な場合に - も問題が起こったりするかもしれない。 - - うーん。やはり timestamp が壊れない限りはこれによって変な事が起こったりす - る可能性は低い気がする。 - - b 後タイムスタンプが nfs などによってずれていたりするとそういう事があったり - するかもしれない。timestamp が信用できない時にはどうしようもない。これは - 個々の使用者の側で注意して時刻を合わせてもらうしかない。 - - * done: 失敗したとしても端末の状態が壊れない様にする。 - - ? コードを見てみると初期化に失敗した時には完全に空 map になってロードされな - いのではなくて safe keymap に fallback する筈なのだが何故そうなっていない - のだろうか。 - - これは再現できるので修正はそんなに難しいことはない筈。 - * syntax 1>&$fd- は使えない @@ -4607,6 +4545,78 @@ bash_tips 2021-05-20 + * 2021-05-13 tmux-resurrect により vi_imap が empty になる問題 (reported by RakibFiha) [#D1562] + https://github.com/akinomyoga/ble.sh/issues/109 + + "ble.sh: The keymap 'vi_imap' is empty." というエラーメッセージが出るとの事 + だが他には何もメッセージは出ないのだろうか。試しに keymap.vi を空にしてロー + ドしてみると…再現した。 + + * bash ble.sh --clear-cache オプションを実装した方が良い。 + + * ファイルが存在するかどうかのチェックをしている箇所は、全て有限の大きさを持っているかどうかを確認した方が良い。 + + * 空の keymap になっていたらキャッシュ無しで初期化し直す機能を付けた方が良いかもしれない。 + + うーん。何と再現しなくなってしまった様である。 + こうなるとコードを見て憶測で修正するしかなくなる。 + + # { + # ble/decode/keymap#load isearch dump + # ble/decode/keymap#load nsearch dump + # ble/decode/keymap#load vi_imap dump + # ble/decode/keymap#load vi_nmap dump + # ble/decode/keymap#load vi_omap dump + # ble/decode/keymap#load vi_xmap dump + # ble/decode/keymap#load vi_cmap dump + # } 3>| "$fname_keymap_cache" + + あー。もしかすると原因が分かったかもしれない。そもそも前に自分が問題を経験 + した時にもそうだったが、ble/decode/keymap#load を改名した事が原因なのであっ + た。此処で、ble.sh が部分的に更新されていたりすると問題になるという事なのだ + ろうという気がする。tmux-resurrect が一体何をしようとしているのかは結局謎な + のであるが、うーん。 + + そもそも報告者が最新の物でも再現するとかしないとか言っていた時に、毎回 make + をしていたのかというのも疑問の一つである。と思ったが rebuilding と言ってい + るので、其処の所はちゃんとやっているのだろうという気がする。 + + a あー。もしかすると複数の異なる ble.sh を使っていて cache が混合していると + いうのは十分考えられる可能性である。と思ったが本当にそれで問題が発生する + だろうか。何れにしても呼び出す vi.sh は同じディレクトリにいる ble.sh から + 呼び出される筈で中途半端に更新されていない限りは不整合は起こらない筈なの + である。 + + 或いは tmux-resurrect が下手に関数等を保存しているのだとすると変な事が起 + こっても仕方ない → 試しに関数を定義して保存・復元して見たが関数は消滅し + ていた。つまり、そういう事は関係ない。 + + 或いは vi.sh の timestamp が偶然未来に設定されてしまったりする様な場合に + も問題が起こったりするかもしれない。 + + うーん。やはり timestamp が壊れない限りはこれによって変な事が起こったりす + る可能性は低い気がする。 + + b 後タイムスタンプが nfs などによってずれていたりするとそういう事があったり + するかもしれない。timestamp が信用できない時にはどうしようもない。これは + 個々の使用者の側で注意して時刻を合わせてもらうしかない。 + + * done: 失敗したとしても端末の状態が壊れない様にする。 + + ? コードを見てみると初期化に失敗した時には完全に空 map になってロードされな + いのではなくて safe keymap に fallback する筈なのだが何故そうなっていない + のだろうか。 + + これは再現できるので修正はそんなに難しいことはない筈。 + + 2021-05-20 もう返事もないし再現もできないし、向こうでも何だか解決した様な雰 + 囲気を出しているので取り敢えず対症療法を push する事にする。 + + * 他にも似たような現象が起こる可能性があるのでキャッシュファイルについて全 + て -s を用いてチェックする事にする。 + * この際なので _ble_base_cache 内の構造・ファイル名についても整理する事にし + た。 + * syntax: ${a~} に対応していない [#D1561] 何れ消えると思っていたがどうも未だ消える気配はない様だ。取り敢えず使える環 diff --git a/src/decode.sh b/src/decode.sh index 63179ee9..42f1159d 100644 --- a/src/decode.sh +++ b/src/decode.sh @@ -2586,8 +2586,8 @@ function ble/decode/cmap/initialize { _ble_decode_cmap_initialized=1 local init=$_ble_base/lib/init-cmap.sh - local dump=$_ble_base_cache/cmap+default.$_ble_decode_kbd_ver.$TERM.dump - if [[ $dump -nt $init ]]; then + local dump=$_ble_base_cache/decode.cmap.$_ble_decode_kbd_ver.$TERM.dump + if [[ -s $dump && $dump -nt $init ]]; then source "$dump" else ble/edit/info/immediate-show text 'ble.sh: generating "'"$dump"'"...' @@ -2606,9 +2606,10 @@ function ble/decode/cmap/initialize { if ((_ble_bash>=40300)); then # 3文字以上 bind/unbind ソースの生成 (init-bind.sh bindAllSeq で使用) - local fbinder=$_ble_base_cache/cmap+default.binder-source + local fbinder=$_ble_base_cache/decode.cmap.allseq _ble_decode_bind_fbinder=$fbinder - if ! [[ $_ble_decode_bind_fbinder -nt $init ]]; then + if ! [[ -s $_ble_decode_bind_fbinder.bind && $_ble_decode_bind_fbinder.bind -nt $init && + -s $_ble_decode_bind_fbinder.unbind && $_ble_decode_bind_fbinder.unbind -nt $init ]]; then ble/edit/info/immediate-show text 'ble.sh: initializing multichar sequence binders... ' ble/decode/cmap/.generate-binder-template >| "$fbinder" binder=ble/decode/cmap/.emit-bindx source "$fbinder" >| "$fbinder.bind" @@ -2831,8 +2832,8 @@ _ble_decode_bind_encoding= function ble/decode/bind/bind { _ble_decode_bind_encoding=$bleopt_input_encoding - local file=$_ble_base_cache/ble-decode-bind.$_ble_bash.$_ble_decode_bind_encoding.bind - [[ $file -nt $_ble_base/lib/init-bind.sh ]] || source "$_ble_base/lib/init-bind.sh" + local file=$_ble_base_cache/decode.bind.$_ble_bash.$_ble_decode_bind_encoding.bind + [[ -s $file && $file -nt $_ble_base/lib/init-bind.sh ]] || source "$_ble_base/lib/init-bind.sh" # * 一時的に 'set convert-meta off' にする。 # @@ -2852,7 +2853,7 @@ function ble/decode/bind/bind { } function ble/decode/bind/unbind { ble/function#try ble/encoding:"$bleopt_input_encoding"/clear - source "$_ble_base_cache/ble-decode-bind.$_ble_bash.$_ble_decode_bind_encoding.unbind" + source "$_ble_base_cache/decode.bind.$_ble_bash.$_ble_decode_bind_encoding.unbind" } function ble/decode/rebind { [[ $_ble_decode_bind_state == none ]] && return 0 diff --git a/src/util.sh b/src/util.sh index 20dff4e7..89cf85fb 100644 --- a/src/util.sh +++ b/src/util.sh @@ -4612,10 +4612,10 @@ function ble/term/DA2R.hook { esac } function ble/term/.initialize { - if [[ $_ble_base/lib/init-term.sh -nt $_ble_base_cache/$TERM.term ]]; then - source "$_ble_base/lib/init-term.sh" + if [[ -s $_ble_base_cache/term.$TERM && $_ble_base_cache/term.$TERM -nt $_ble_base/lib/init-term.sh ]]; then + source "$_ble_base_cache/term.$TERM" else - source "$_ble_base_cache/$TERM.term" + source "$_ble_base/lib/init-term.sh" fi ble/string#reserve-prototype "$_ble_term_it"