From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: [PATCH] sqlhish: Add bash completion for the sqlhist utility
Date: Thu, 10 Apr 2025 11:48:37 -0400 [thread overview]
Message-ID: <20250410114837.144cec8e@gandalf.local.home> (raw)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Add a bash completion script for the sqlhist utility that utilizes the
tracefs_sql.bash completion script to fill out the sql lines.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
samples/sqlhist.bash | 61 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 samples/sqlhist.bash
diff --git a/samples/sqlhist.bash b/samples/sqlhist.bash
new file mode 100644
index 0000000..44f7e9a
--- /dev/null
+++ b/samples/sqlhist.bash
@@ -0,0 +1,61 @@
+# sqlhist completion
+
+# use the library tracefs_sql() completion
+
+thisdir=`dirname $BASH_SOURCE`
+if [ -e $thisdir/tracefs_sql.bash ]; then
+. $thisdir/tracefs_sql.bash
+elif [ -e $thisdir/../src/tracefs_sql.bash ]; then
+. $thisdir/../src/tracefs_sql.bash
+else
+sqlhist_completion()
+{
+ return
+}
+fi
+
+found_select()
+{
+ local words=("$@")
+ local i=$COMP_CWORD
+
+ while [ $i -gt 0 ]; do
+ let i=$i-1
+ local w=$(echo ${words[$i]} | tr A-Z a-z)
+ if [ $w == "select" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+_sqlhist_complete()
+{
+ local cur=""
+ local prev=""
+ local words=()
+
+ # Not to use COMP_WORDS to avoid buggy behavior of Bash when
+ # handling with words including ":", like:
+ #
+ # prev="${COMP_WORDS[COMP_CWORD-1]}"
+ # cur="${COMP_WORDS[COMP_CWORD]}"
+ #
+ # Instead, we use _get_comp_words_by_ref() magic.
+ _get_comp_words_by_ref -n : cur prev words
+
+ if `found_select ${words[@]}` ; then
+ sqlhist_completion "$prev" "$cur" ${words[@]}
+ return
+ fi
+ local cmds=$(sqlhist -h 2>&1 | \
+ grep '^ *-' | sed -e 's/^ *\(-[^ ]*\).*/\1/')
+ COMPREPLY=( $(compgen -W "${cmds} SELECT" -- "${cur}") )
+ if [ ${#COMPREPLY[@]} -eq 0 ]; then
+ local w="select"
+ if [ "$w" != "${w##$cur}" ]; then
+ COMPREPLY=("$w")
+ fi
+ fi
+}
+complete -F _sqlhist_complete sqlhist
--
2.47.2
reply other threads:[~2025-04-10 15:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250410114837.144cec8e@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).