File: sqlhist.bash

package info (click to toggle)
libtracefs 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,368 kB
  • sloc: ansic: 12,953; makefile: 609; sh: 509; yacc: 188; lex: 106
file content (61 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
tracefs_sql_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
	tracefs_sql_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