diff mbox series

[lttng-tools] Bash completion: ignore namespace for xmllint parsing

Message ID 20180528213148.18880-1-jonathan.rajotte-julien@efficios.com
State Accepted, archived
Delegated to: Jérémie Galarneau
Headers show
Series [lttng-tools] Bash completion: ignore namespace for xmllint parsing | expand

Commit Message

Jonathan Rajotte May 28, 2018, 9:31 p.m. UTC
xmllint cli does not "easily" support namespace.

One can use the local_name() xpath function and other "trick".
The simplest trick for bash completion is to ignore the namespace
altogether.

Replacing "xmlns" by "ignore" does the job.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 extras/lttng-bash_completion | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jérémie Galarneau June 6, 2018, 12:18 a.m. UTC | #1
Merged in master, stable-2.10, and stable-2.9.

Thanks!
Jérémie

On Mon, May 28, 2018 at 05:31:48PM -0400, Jonathan Rajotte wrote:
> xmllint cli does not "easily" support namespace.
> 
> One can use the local_name() xpath function and other "trick".
> The simplest trick for bash completion is to ignore the namespace
> altogether.
> 
> Replacing "xmlns" by "ignore" does the job.
> 
> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
> ---
>  extras/lttng-bash_completion | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/extras/lttng-bash_completion b/extras/lttng-bash_completion
> index ef1a71ab..c7482c54 100644
> --- a/extras/lttng-bash_completion
> +++ b/extras/lttng-bash_completion
> @@ -18,7 +18,7 @@
>  # Generates COMPREPLY with the existing session names
>  _lttng_complete_sessions() {
>  	local sessions
> -	sessions=$(lttng --mi xml list |  xmllint --xpath "//command/output/sessions/session/name" - 2>/dev/null | sed  -e 's/<name>//g' -e $'s/<\/name>/\\n/g')
> +	sessions=$(lttng --mi xml list | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/sessions/session/name" - 2>/dev/null | sed  -e 's/<name>//g' -e $'s/<\/name>/\\n/g')
>  	COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
>  	return
>  }
> @@ -27,7 +27,7 @@ _lttng_complete_sessions() {
>  # Generates COMPREPLY with the available kernel event
>  _lttng_complete_kernel_events() {
>  	local kernel_event
> -	kernel_event=$(lttng --mi xml list -k | xmllint --xpath "//command/output/domains/domain[./type = 'KERNEL']/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
> +	kernel_event=$(lttng --mi xml list -k |sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'KERNEL']/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
>  	COMPREPLY=( $(compgen -W "${kernel_event}" -- $cur) )
>  	return
>  }
> @@ -35,7 +35,7 @@ _lttng_complete_kernel_events() {
>  # Generates COMPREPLY with the available ust event
>  _lttng_complete_ust_events() {
>  	local ust_event
> -	ust_event=$(lttng --mi xml list -u | xmllint --xpath "//command/output/domains/domain[./type = 'UST']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
> +	ust_event=$(lttng --mi xml list -u | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'UST']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
>  	COMPREPLY=( $(compgen -W "${ust_event}" -- $cur) )
>  	return
>  }
> @@ -43,7 +43,7 @@ _lttng_complete_ust_events() {
>  # Generates COMPREPLY with the available jul event
>  _lttng_complete_jul_events() {
>  	local jul_event
> -	jul_event=$(lttng --mi xml list -j | xmllint --xpath "//command/output/domains/domain[./type = 'JUL']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
> +	jul_event=$(lttng --mi xml list -j | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'JUL']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
>  	COMPREPLY=( $(compgen -W "${jul_event}" -- $cur) )
>  	return
>  }
> -- 
> 2.17.0
>
diff mbox series

Patch

diff --git a/extras/lttng-bash_completion b/extras/lttng-bash_completion
index ef1a71ab..c7482c54 100644
--- a/extras/lttng-bash_completion
+++ b/extras/lttng-bash_completion
@@ -18,7 +18,7 @@ 
 # Generates COMPREPLY with the existing session names
 _lttng_complete_sessions() {
 	local sessions
-	sessions=$(lttng --mi xml list |  xmllint --xpath "//command/output/sessions/session/name" - 2>/dev/null | sed  -e 's/<name>//g' -e $'s/<\/name>/\\n/g')
+	sessions=$(lttng --mi xml list | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/sessions/session/name" - 2>/dev/null | sed  -e 's/<name>//g' -e $'s/<\/name>/\\n/g')
 	COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
 	return
 }
@@ -27,7 +27,7 @@  _lttng_complete_sessions() {
 # Generates COMPREPLY with the available kernel event
 _lttng_complete_kernel_events() {
 	local kernel_event
-	kernel_event=$(lttng --mi xml list -k | xmllint --xpath "//command/output/domains/domain[./type = 'KERNEL']/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
+	kernel_event=$(lttng --mi xml list -k |sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'KERNEL']/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
 	COMPREPLY=( $(compgen -W "${kernel_event}" -- $cur) )
 	return
 }
@@ -35,7 +35,7 @@  _lttng_complete_kernel_events() {
 # Generates COMPREPLY with the available ust event
 _lttng_complete_ust_events() {
 	local ust_event
-	ust_event=$(lttng --mi xml list -u | xmllint --xpath "//command/output/domains/domain[./type = 'UST']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
+	ust_event=$(lttng --mi xml list -u | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'UST']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
 	COMPREPLY=( $(compgen -W "${ust_event}" -- $cur) )
 	return
 }
@@ -43,7 +43,7 @@  _lttng_complete_ust_events() {
 # Generates COMPREPLY with the available jul event
 _lttng_complete_jul_events() {
 	local jul_event
-	jul_event=$(lttng --mi xml list -j | xmllint --xpath "//command/output/domains/domain[./type = 'JUL']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
+	jul_event=$(lttng --mi xml list -j | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'JUL']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
 	COMPREPLY=( $(compgen -W "${jul_event}" -- $cur) )
 	return
 }