Skip to content

Commit

Permalink
utilities/bashcomp: Fix PS1 generation on new bash.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Timothy Redaelli <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
drizzt authored and igsilya committed May 29, 2023
1 parent c3e410a commit e3d0e84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions utilities/ovs-appctl-bashcomp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down
7 changes: 7 additions & 0 deletions utilities/ovs-vsctl-bashcomp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e3d0e84

Please sign in to comment.