diff mbox series

[ovs-dev,v2,1/1] utilities/bashcomp: Fix PS1 generation on new bash

Message ID a4b64d1989397490eaf3ab7f044ef83e41caf512.1685121321.git.tredaelli@redhat.com
State Accepted
Commit e3d0e84ed3f0a49dfb7107db56ce709aaeaf1ac7
Headers show
Series Fix PS1 generation on new bash | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Timothy Redaelli May 26, 2023, 5:16 p.m. UTC
The current implementation used to extract PS1 prompt for ovs-vsctl is
broken on recent Bash releases.
Starting from Bash 4.4 it's possible to use @P expansion in order to get
the quoted PS1 directly.

This commit makes the 2 bash completion files to use @P expansion in order
to get the quoted PS1 on Bash >= 4.4.

Reported-at: https://bugzilla.redhat.com/2170344
Reported-by: Martin Necas <mnecas@redhat.com>
Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 utilities/ovs-appctl-bashcomp.bash | 7 +++++++
 utilities/ovs-vsctl-bashcomp.bash  | 7 +++++++
 2 files changed, 14 insertions(+)

Comments

Ilya Maximets May 29, 2023, 7:25 p.m. UTC | #1
On 5/26/23 19:16, Timothy Redaelli wrote:
> The current implementation used to extract PS1 prompt for ovs-vsctl is
> broken on recent Bash releases.
> Starting from Bash 4.4 it's possible to use @P expansion in order to get
> the quoted PS1 directly.
> 
> This commit makes the 2 bash completion files to use @P expansion in order
> to get the quoted PS1 on Bash >= 4.4.
> 
> Reported-at: https://bugzilla.redhat.com/2170344
> Reported-by: Martin Necas <mnecas@redhat.com>
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>

Thanks!  Applied and backported down to 2.17.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/utilities/ovs-appctl-bashcomp.bash b/utilities/ovs-appctl-bashcomp.bash
index 4384be8ae..0a9af1a18 100644
--- a/utilities/ovs-appctl-bashcomp.bash
+++ b/utilities/ovs-appctl-bashcomp.bash
@@ -223,6 +223,13 @@  printf_stderr() {
 # The code below is taken from Peter Amidon.  His change makes it more
 # robust.
 extract_bash_prompt() {
+    # On Bash 4.4+ just use the @P expansion
+    if ((BASH_VERSINFO[0] > 4 ||
+        (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4))); then
+        _BASH_PROMPT="${PS1@P}"
+        return
+    fi
+
     local myPS1 v
 
     myPS1="$(sed 's/Begin prompt/\\Begin prompt/; s/End prompt/\\End prompt/' <<< "$PS1")"
diff --git a/utilities/ovs-vsctl-bashcomp.bash b/utilities/ovs-vsctl-bashcomp.bash
index fc8245bfb..c5ad24fb7 100644
--- a/utilities/ovs-vsctl-bashcomp.bash
+++ b/utilities/ovs-vsctl-bashcomp.bash
@@ -413,6 +413,13 @@  _ovs_vsctl_get_PS1 () {
         return;
     fi
 
+    # On Bash 4.4+ just use the @P expansion
+    if ((BASH_VERSINFO[0] > 4 ||
+        (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4))); then
+        printf '%s\n' "${PS1@P}"
+        return
+    fi
+
     # Original inspiration from
     # http://stackoverflow.com/questions/10060500/bash-how-to-evaluate-ps1-ps2,
     # but changed quite a lot to make it more robust.