[ovs-dev] [RFC 3/3] ovs-vsctl-bashcomp: Documentation and unit tests.

Alex Wang alexw at nicira.com
Mon Mar 9 00:30:19 UTC 2015


Sorry for the delayed reply, I tested it, & looked fine to me,

So, Ben, what do you think about this workaround?

Thanks,
Alex Wang,

On Fri, Mar 6, 2015 at 7:35 AM, Peter Amidon <peter at picnicpark.org> wrote:

> On Thu, 05 Mar 2015 21:58:38 -0800: Ben Pfaff <blp at nicira.com> wrote:
>   > Without digging into it, it's not obvious to me why you need to know
> the
>   > bash prompt.  Can you just set a known prompt instead?
>
> In a few cases the script has to print some output to the user (e.g. if
> the user attempts to complete while on an argument that should name a
> new bridge, the script can't complete it). If that happens, we thought
> that the best experience for the user would be printing out the command
> line exactly as it appeared when the user first entered it, ideally with
> the same prompt as was originally used, after the message.
>
> Unfortunately, since PS1 can contain escape sequences that are only
> recognized by bash, when printing a prompt, the only reliable way to get
> the prompt seems to be starting a subshell, exporting the current
> environment, and capturing the prompt as was used in the subshell.
>
> However, for testing, it makes sense to use a known value; the script
> originally did this in a way that still resulted in using a subshell,
> but we can change it to detect test settings before trying to start a
> shell.  Below is an incremental diff that passes all the tests without
> hanging when run in parallel; used interactively, it appears to work as
> expected.
>
>     ---Peter
>
> diff --git a/utilities/ovs-vsctl-bashcomp.bash
> b/utilities/ovs-vsctl-bashcomp.bash
> index ba4429f..911f600 100755
> --- a/utilities/ovs-vsctl-bashcomp.bash
> +++ b/utilities/ovs-vsctl-bashcomp.bash
> @@ -409,6 +409,10 @@ _ovs_vsctl_complete_target () {
>
>  # Extract PS1 prompt.
>  _ovs_vsctl_get_PS1 () {
> +    if [ "$test" = "true" ]; then
> +        printf -- "> "
> +        return;
> +    fi
>
>      # Original inspiration from
>      #
> http://stackoverflow.com/questions/10060500/bash-how-to-evaluate-ps1-ps2,
> @@ -637,12 +641,6 @@ _ovs_vsctl_bashcomp () {
>                    <<< "$tmp"
>          export COMP_WORDS
>          export COMP_CWORD="$((${#COMP_WORDS[@]}-1))"
> -        export PS1="> "
> -        # This is used to make the PS1-extraction code not emit extra
> -        # escape sequences; it seems like bash assumes that unknown
> -        # terminal names are dumb which means this should work even in
> -        # the unlikely occurence of the terminal "dumb" not existing.
> -        export TERM="dumb"
>      fi
>
>      # Extract the conf.db path.
>



More information about the dev mailing list