diff --git a/ble.pp b/ble.pp index 5dd6bdf0..3d5adc39 100644 --- a/ble.pp +++ b/ble.pp @@ -1670,6 +1670,20 @@ function ble/util/readlink { #--------------------------------------- +function ble/init/adjust-environment { + builtin unset -f "$FUNCNAME" + + if [[ ${IN_NIX_SHELL-} ]]; then + # Since "nix-shell" overwrites BASH to the path to a binary image different + # from the current one, the Bash process crashes on attempting loading + # loadable builtins. We rewrite it to the correct one. + local ret= + ble/util/readlink "/proc/$$/exe" 2>/dev/null + [[ -x $ret ]] && BASH=$ret + fi +} +ble/init/adjust-environment + _ble_bash_path= function ble/bin/.load-builtin { local name=$1 path=$2 @@ -2624,6 +2638,47 @@ function ble/base/load-rcfile { fi } +# ble-attach needs to be performed at the very end of the Bash startup file. +# However, in some environment, the terminal or the session manager would start +# Bash with a custom startup file, and ~/.bashrc is sourced from the custom +# startup file. In this case, when the user puts "ble-attach" at the end of +# ~/.bashrc, other settings would continue to be executed even after the +# execution of "ble-attach". +function ble/base/attach/.needs-prompt-attach { + local ext=1 + + [[ $1 == *:force:* ]] && return 1 + + # nix-shell loads the Bash startup file from inside its custom file "rc". + if [[ ${IN_NIX_SHELL-} && "${BASH_SOURCE[*]}" == */rc ]]; then + # We force prompt-attach when ble-attach is run inside "nix-shell rc". + ext=0 + fi + + if [[ ${VSCODE_INJECTION-} ]]; then + # VS Code also tries to source ~/.bashrc from its + # "shellIntegration-bash.sh". VS Code shell integration seems to set the + # variable "VSCODE_INJECTION" while it sources the user's startup file, and + # it unsets the variable after the initialization. + ext=0 + elif [[ ${kitty_bash_inject-} ]]; then + # When the startup file is sourced from kitty's shell ingteration + # "kitty.bash", the variable "kitty_bash_inject" is set. The variable is + # unset after the initialization. If we find it, we cancel the manual + # attaching and switch to the prompt attach. + ext=0 + elif [[ ${ghostty_bash_inject-} ]]; then + # Ghostty seems to use a shell-integration code derived from kitty's. By + # the way, kitty is licensed under GPL-3.0, while Ghostty is licensed under + # the MIT license. Is it allowed to include a derivative of a part of + # kitty in the MIT-licensed Ghostty? It may be non-trivial whether the + # shell integration is an essential part of Ghostty. + ext=0 + fi + + return "$ext" +} + ## @fn ble-attach [opts] function ble-attach { #%if leakvar @@ -2670,31 +2725,24 @@ function ble-attach { #%if leakvar ble/debug/leakvar#check $"leakvar" A4-adjust #%end.i - if [[ ${IN_NIX_SHELL-} ]]; then - # nix-shell rc の中から実行している時は強制的に prompt-attach にする - if [[ "${BASH_SOURCE[*]}" == */rc && $1 != *:force:* ]]; then - ble/base/install-prompt-attach - _ble_attached= - BLE_ATTACHED= - ble/base/restore-BASH_REMATCH - ble/base/restore-bash-options - ble/base/restore-builtin-wrappers - ble/base/restore-POSIXLY_CORRECT + + if ble/base/attach/.needs-prompt-attach; then + ble/base/install-prompt-attach + _ble_attached= + BLE_ATTACHED= + ble/base/restore-BASH_REMATCH + ble/base/restore-bash-options + ble/base/restore-builtin-wrappers + ble/base/restore-POSIXLY_CORRECT #%if leakvar ble/debug/leakvar#check $"leakvar" A4b1 #%end.i - builtin eval -- "$_ble_bash_FUNCNEST_restore" - return 0 - fi - - # nix-shell は BASH を誤った値に書き換えるので上書きする。 - local ret - ble/util/readlink "/proc/$$/exe" - [[ -x $ret ]] && BASH=$ret + builtin eval -- "$_ble_bash_FUNCNEST_restore" + return 0 + fi #%if leakvar ble/debug/leakvar#check $"leakvar" A4b2 #%end.i - fi # reconnect standard streams ble/fd/save-external-standard-streams diff --git a/contrib b/contrib index 1b9051ff..a5d3a2e0 160000 --- a/contrib +++ b/contrib @@ -1 +1 @@ -Subproject commit 1b9051ff4ea95e82a08cc31d06578407f3a139bf +Subproject commit a5d3a2e017c32f0c59a5bd609e43bf78b1b50f9e diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 170ac795..493773c3 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -210,6 +210,7 @@ - canvas: update tables for Unicode 16.0.0 `#D2283` 5b43ca3f 25a10a6f - complete: work around `mawk <= 1.3.4-20230525` type-inference bug (reported by KaKi87) `#D2295` 546499b5 - main: work around macOS sed (reported by Mossop) `#D2298` a16aa594 +- main: delay attaching in kitty, Ghostty, and VS Code Terminal `#D2215` xxxxxxxx ## Contrib @@ -242,6 +243,7 @@ - integration/fzf-initialize: (reported by 3ximus) `#D2285` a36d13ce - config: add `github499-append-to-last-modified` (motivated by vaab) `#D2286` 32f290df - integration: add `skim` integration for completion (reported by cmm) `#D2287` a36d13ce +- integration/zoxide: fix the problem of unquoted filenames (reported by tessus) `#D2216` xxxxxxxx ## Documentation diff --git a/note.txt b/note.txt index 517b14c3..b27ab082 100644 --- a/note.txt +++ b/note.txt @@ -7728,8 +7728,57 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2025-01-07 + + * integration/zoxide: compopt -o noquote は余分 (reported by tessus) [#D2316] + https://github.com/akinomyoga/ble.sh/issues/549 + + うーん。integration/zoxide.bash で明示的に compopt -o noquote を指定してい + るのが悪かった。元々何処からこの compopt -o noquote が来たのかと思ったが、 + 最初の commit から存在している様だ。そして、どうもこれは + fzf-completion.bash を zoxide 用に修正した時に、fzf 用の設定をそのまま持っ + てきたという事の様である。 + + そもそも fzf で compopt -o noquote を指定していたのは fzf によって履歴項目 + が補完された時には余分の quote は不要だと判断したからであった。然し、zoxide + は単にディレクトリ名を指定するだけのコマンドなので compopt -o noquote を指 + 定する必要性もない様に思われる。 + + 更に、fzf に関しては以下の報告によって compopt -o noquote は使用しない形に + 改められた。つまり、その修正の漏れとも言える。 + + https://github.com/akinomyoga/ble.sh/issues/250 + https://github.com/akinomyoga/ble.sh/commit/0c6291f0c1609b6159013e6ba4aeae3acb35db14 + https://github.com/akinomyoga/blesh-contrib/commit/e102241466dfda8cf3e7efb6891e223102e0b2a9 + + 何れにしても単に compopt -o noquote を削除すれば良いだけの話に思われる。 + 2025-01-05 + * main: 特定の環境で ble-attach の実行を延期する [#D2315] + https://github.com/akinomyoga/ble.sh/issues/543 + https://github.com/akinomyoga/ble.sh/discussions/524#discussioncomment-11656742 + + ghostty も kitty を真似して ENV 経由で初期化して .bashrc をスキップし、手動 + で .bashrc を読み込もうとしている。その後で PS1 を修正している。これによっ + て問題が発生しているのである。これはマニュアルにある通りに設定していないか + ら悪いのだと書いたが issue を閉じてくれない。というか説明したのにバグだとか + 主張している。 + + 実は既に nix shell では ble-attach を延期して prompt-attach に切り替える様 + にしている。なので、ghostty についてもその様に変更する事にする。kitty も同 + 様に修正する。更に VS Code terminal でも同様の事をしている為に問題が起こっ + ていた。これについても修正する。 + + ? 或いはトップレベルのファイルで ble-attach しているかどうかをチェックして + そうでなかったら警告を発生する様にする? 然し、既に関数内部やファイル内部 + から呼び出すように設定している人も多いし、そもそも問題が起こらないように + ちゃんとしている人もいる。という事を考えると、単にそれで警告を出力するよ + うに変更するのも気が引ける。 + + もしその様にするのであれば最初から警告を出力する様にするべきだった。今に + なって変更する事はできない。 + * edit (TMOUT): (reported by Anyborr, georglauterbach) [#D2314] https://github.com/akinomyoga/ble.sh/issues/424#issuecomment-2016531757 https://github.com/akinomyoga/ble.sh/issues/548