Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > gnu.bash.bug > #16792
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Koichi Murase <myoga.murase@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | How to use PROMPT_COMMAND(S) without breaking other scripts |
| Date | Sun, 23 Aug 2020 11:35:29 +0900 |
| Lines | 50 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.828.1598150151.2469.bug-bash@gnu.org> (permalink) |
| References | <CAKOZuevPZ1xwhLmLzXt_a=G+azDTouO52MCA=wvh=-M82wzaSQ@mail.gmail.com> <17a0ba52-32ee-b9bc-72ff-3587b2050fbd@case.edu> <CAFLRLk9vNPM5NtypB2UNcDqMZfG3Lmi3zEMGfPqZNacmHCoAoA@mail.gmail.com> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| X-Trace | usenet.stanford.edu 1598150151 14608 209.51.188.17 (23 Aug 2020 02:35:51 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=GaxE5qLEQaUpnJmileamg4Drs5yFz5TaP4f0f63n3ck=; b=SMFR/dADueYVVGMWSC62HWET+2ilkPZHFVB+FzHzYJA3fl+rtkE2/epe5ROuEFPG67 bwP9AeDq6LM51dapgCU2bvFlZRuJP0pO3GiplzkpE9YS+0K9xOWTTMZ7H9teV/bS9o8d KJl9S3h4beczQLyj83b1WvXfVpZ7hQ7aWPSuxFNLR8+ArLUFYqTEc24MiNJVxFkxNVs9 +elJt/XMLzQqVktSGPFfdf/2y+NYTM4ROwVQE7N4ox7jnqN6KUqqPoD9Py2RW+90FZ7q Cg0ionlPBvB188eKyxS9kjLmG0mydpPSiPcKdf2mjYje25OUCnYKwRLB20MbNjFeyGXB bMFg== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=GaxE5qLEQaUpnJmileamg4Drs5yFz5TaP4f0f63n3ck=; b=btHJyJs7pELjqx9gaRWG5vAjCE1bcIc5eVc+i6VjPxp5dzIWDa2W8tlxUVNhJ+2Nx/ ytQxA15sOcb4o419iWjItHJ66oBbGhMlTMhBWVr3JOhENnOAg87lwBuLxod5qIeasJQq Lj08ZiKacrGjr15hfRvkccgVqBcrlr7n8+YxOi7ir86I5+dNdEE6yVwTSEaCeEhG2KUr YRl2ERcUFKa8A0XXzLwDA+QsLN5GRQ+evpcnlBO0LLRvApexCShMhm9xiTBJPXYXNoOh HvP8TQDykQiwexBtkVbUSP5N/rbrp3RsD5Viq6GiHe7Vex6mUAKhBm/lDOKHhRY7xyZj q3fg== |
| X-Gm-Message-State | AOAM533GYAjqkvltjJEfBvRqjFzCoVxecV18+J+qmt93DsyhYJiod4S3 oYZcXLR50NutQnGjkhBVOmB5NVocbtEQvhL8Z/Yq+9OzDOI= |
| X-Google-Smtp-Source | ABdhPJw8gDMajYrorbfihdaGaMT3DzA26j3wp+xjZal6J7JSeOYDihYItHJJD58pOPdtwm4zlYqVbki8io8XwO94uyA= |
| X-Received | by 2002:a17:906:fa15:: with SMTP id lo21mr315902ejb.42.1598150141801; Sat, 22 Aug 2020 19:35:41 -0700 (PDT) |
| In-Reply-To | <17a0ba52-32ee-b9bc-72ff-3587b2050fbd@case.edu> |
| Received-SPF | pass client-ip=2a00:1450:4864:20::636; envelope-from=myoga.murase@gmail.com; helo=mail-ej1-x636.google.com |
| X-detected-operating-system | by eggs.gnu.org: No matching host in p0f cache. That's all we know. |
| X-Spam_score_int | -20 |
| X-Spam_score | -2.1 |
| X-Spam_bar | -- |
| X-Spam_report | (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no |
| X-Spam_action | no action |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAFLRLk9vNPM5NtypB2UNcDqMZfG3Lmi3zEMGfPqZNacmHCoAoA@mail.gmail.com> |
| X-Mailman-Original-References | <CAKOZuevPZ1xwhLmLzXt_a=G+azDTouO52MCA=wvh=-M82wzaSQ@mail.gmail.com> <17a0ba52-32ee-b9bc-72ff-3587b2050fbd@case.edu> |
| Xref | csiph.com gnu.bash.bug:16792 |
Show key headers only | View raw
Hi, I have a question on the behavior of the new array PROMPT_COMMANDS
and the best practice to use it.
In coming Bash 5.1, the new array variable `PROMPT_COMMANDS' is
available in the replacement of `PROMPT_COMMAND'. When the array
`PROMPT_COMMANDS' has one or more elements, the scalar version
`PROMPT_COMMAND' is disabled.
Is there a background that the scalar version is disabled in the
presence of the array version? Because of this behavior, I am
wondering how to write a source script in the way not interfering with
other source scripts which might use either of `PROMPT_COMMANDS' or
`PROMPT_COMMAND'.
* If I use the newer form `PROMPT_COMMANDS+=(my-function)', other
scripts that use `PROMPT_COMMAND' will be broken. Maybe I can write
in the following way to convert `PROMPT_COMMAND' to
`PROMPT_COMMANDS', but it still does not resolve the problem of the
scripts sourced after my script.
if [[ $PROMPT_COMMAND ]]; then
PROMPT_COMMANDS+=("$PROMPT_COMMAND")
unset PROMPT_COMMAND
fi
PROMPT_COMMANDS+=(my-function)
* If I use the older form with `PROMPT_COMMAND', it will be broken
when another script sets the variable `PROMPT_COMMANDS'. Maybe I
can switch to `PROMPT_COMMANDS' only when the array already exists,
but it again does not work when the other script sourced after mine
newly sets `PROMPT_COMMANDS'.
if ((${#PROMPT_COMMANDS})); then
PROMPT_COMMANDS+=(my-function)
else
PROMPT_COMMAND="my-function${PROMPT_COMMAND:+;}$PROMPT_COMMAND"
fi
Here, my question is what is the best practice to use the new array
variable `PROMPT_COMMANDS' in the way that it does not break the
conventional scripts that use `PROMPT_COMMAND'.
# The related commit is 5f49ef47d (commit bash-20200323 snapshot).
# Here are the related threads:
# https://lists.gnu.org/archive/html/bug-bash/2018-01/threads.html#00067
# https://lists.gnu.org/archive/html/bug-bash/2018-02/threads.html#00019
--
Koichi
Back to gnu.bash.bug | Previous | Next | Find similar
How to use PROMPT_COMMAND(S) without breaking other scripts Koichi Murase <myoga.murase@gmail.com> - 2020-08-23 11:35 +0900
csiph-web