From c0abc9522bc523f70a30a99e3409efa63e3e16d1 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 9 Jul 2022 18:14:51 +0900 Subject: [PATCH] util (ble/function#pop): allow popping unset function --- docs/ChangeLog.md | 3 ++- note.txt | 9 +++++++++ src/util.sh | 6 ++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index a398d1ae..0288b90a 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -338,6 +338,7 @@ - complete: work around a false warning messages of gawk-4.0.2 `#D1709` 9771693 - main: work around `XDG_RUNTIME_DIR` of a different user by `su` (reported by zim0369) `#D1712` 8d37048 - main (`ble/util/readlink`): work around non-standard or missing `readlink` (motivated by peterzky) `#D1720` a41279e + - util (`ble/function#pop`): allow popping unset function `#D1834` XXXXXXX - menu (`menu-style:desc`): work around xenl quirks for relative cursor movements (reported by telometto) `#D1728` 3e136a6 - global: work around the arithmetic syntax error of `10#` in Bash-5.1 `#D1734` 7545ea3 - global: adjust implementations for Bash 5.2 `patsub_replacement` `#D1738` 4590997 @@ -363,7 +364,7 @@ - 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 XXXXXXX +- progcomp: disable `command_not_found_handle` (reported by telometto, wisnoskij) `#D1834` 64d471a d5fe1d1 ## Internal changes and fixes diff --git a/note.txt b/note.txt index ab1d97f1..a78aae37 100644 --- a/note.txt +++ b/note.txt @@ -6586,6 +6586,15 @@ bash_tips で寧ろ入力ではなくて出力の方を組み替えている。なのに出力は出来て入力は できないというのも変な事である。 + * 2022-07-09 使っていたら元から command_not_found_handle が定義されていなかっ + た時に pop 時に問題が発生する。これは ble/function#{push,pop} の実装の問 + 題である。 + + これは function#push 時に関数定義を与えなかった時に関数を unset する機能 + を導入した時の手落ちと考えられる。調べてみるとこれは a41279e (#D1720) に + おける変更である。この時に一応 function#pop に対しても対応する変更がなさ + れているが、それが不完全だったという事。 + 2022-07-07 * main: fd 0, 1 が TTY かどうかのチェックが常に偽になっている [#D1833] diff --git a/src/util.sh b/src/util.sh index 4bc99d3e..fcb43954 100644 --- a/src/util.sh +++ b/src/util.sh @@ -3141,9 +3141,11 @@ function ble/function#pop { if ble/is-function "$name"; then builtin unset -f "$name" return 0 - else - ble/util/print "ble/function#push: $name is not a function." >&2 + elif ble/bin#has "$name"; then + ble/util/print "ble/function#pop: $name is not a function." >&2 return 1 + else + return 0 fi else local def; ble/function#getdef "ble/function#push/$index:$name"