Skip to content

Commit

Permalink
decode (bind): do not treat non-beginning "#" as comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jun 19, 2022
1 parent 6d20f51 commit 65c4138
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -160,6 +160,7 @@
- util (`blehook`): fix a bug that the the hook arguments are lost (reported by SuperSandro2000) `#D1804` 479795d
- complete (`source:command/get-desc`): show function location and body `#D1788` 496e798
- edit (`ble-detach`): prepend a space to `stty sane` for `HISTIGNORE=' *'` `#D1796` 26b532e
- decode (bind): do not treat non-beginning `#` as comments `#D1820` XXXXXXX

## Fixes

Expand Down
12 changes: 12 additions & 0 deletions note.txt
Expand Up @@ -6431,6 +6431,18 @@ bash_tips

2022-06-19

* decode (bind): inputrc に含まれる # の処理 [#D1820]

% 変数によって処理したり処理しなかったりの様だ。特に文字列を受け取るオプショ
% ンに関しては # 以降の削除はされない。一方で on/off のオプションの場合には
% '#' 以降は無視されている様に見える。→と思ったが違った。単に最初の空白で
% 切っているだけだった。

Bash-5.1 以降では on/off オプションについては空白で区切った最初の単語だけを
見る。Bash-5.0 以前は (# が含まれていたとしても) 全体を見る。うーん。ble.sh
内部では勝手に '#' 以降を削除してから処理しているがこれは正しくない。後で修
正する。これは 0.3 以前に遡って適用する。

* util: rlvar enable-bracketed-paste off に対応する (motivated by ArianaAsl) [#D1819]
https://github.com/akinomyoga/ble.sh/discussions/199

Expand Down
13 changes: 9 additions & 4 deletions src/decode.sh
Expand Up @@ -3595,10 +3595,15 @@ function ble/builtin/bind/option:u/search-recursive {
function ble/builtin/bind/option:- {
local ret; ble/string#trim "$1"; local arg=$ret

# コメント除去 (quote されていない "空白+#" 以降はコメント)
local q=\' ifs=$_ble_term_IFS
local rex='^(([^\"'$q$ifs']|"([^\"]|\\.)*"|'$q'([^\'$q']|\\.)*'$q'|\\.|['$ifs']+[^#'$_ifs'])*)['$ifs']+#'
[[ $arg =~ $rex ]] && arg=${BASH_REMATCH[1]}
# Note (#D1820): これまで行の途中から始まるコメントを除去していたが、実際に
# inputrc 色々書き込んで調べると特に無視されている訳では無い事が分かった。
# なので、行頭に # がある場合にのみ処理を中断することにする。
[[ ! $arg || $arg == '#'* ]] && return 0

# # コメント除去 (quote されていない "空白+#" 以降はコメント)
# local q=\' ifs=$_ble_term_IFS
# local rex='^(([^\"'$q$ifs']|"([^\"]|\\.)*"|'$q'([^\'$q']|\\.)*'$q'|\\.|['$ifs']+[^#'$_ifs'])*)['$ifs']+#'
# [[ $arg =~ $rex ]] && arg=${BASH_REMATCH[1]}

local ifs=$_ble_term_IFS
if [[ $arg == 'set'["$ifs"]* ]]; then
Expand Down

0 comments on commit 65c4138

Please sign in to comment.