File: library.sh

package info (click to toggle)
bash-completion 1%3A2.1-4.3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,740 kB
  • sloc: exp: 8,230; makefile: 948; sh: 727; perl: 59; python: 26; xml: 13; ansic: 6
file content (73 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (4)
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
62
63
64
65
66
67
68
69
70
71
72
73
# Bash library for bash-completion DejaGnu testsuite


# @param $1  Char to add to $COMP_WORDBREAKS
# @see remove_comp_wordbreak_char()
add_comp_wordbreak_char() {
    [[ "${COMP_WORDBREAKS//[^$1]}" ]] || COMP_WORDBREAKS+=$1
} # add_comp_wordbreak_char()


# Diff environment files to detect if environment is unmodified
# @param $1  File 1
# @param $2  File 2
# @param $3  Additional sed script
diff_env() {
    diff "$1" "$2" | sed -e "
# Remove diff line indicators
        /^[0-9,]\{1,\}[acd]/d
# Remove diff block separators
        /---/d
# Remove underscore variable
        /[<>] _=/d
# Remove PPID bash variable
        /[<>] PPID=/d
# Remove BASH_REMATCH bash variable
        /[<>] BASH_REMATCH=/d
        $3"
} # diff_env()


# Output array elements, sorted and separated by newline
# Unset variable after outputting.
# @param $1  Name of array variable to process
echo_array() {
    local name=$1[@]
    printf "%s\n" "${!name}" | sort
} # echo_array()


# Check if current bash version meets specified minimum
# @param $1  (integer) Major version number
# @param $2  (integer) Minor version number
# @param $3  (integer) Patch level
# @return  0 if success, > 0 if not
is_bash_version_minimal() {
    [[      (
                ${BASH_VERSINFO[0]} -gt $1
            ) || (
                ${BASH_VERSINFO[0]} -eq $1 &&
                ${BASH_VERSINFO[1]} -gt $2
            ) || (
                ${BASH_VERSINFO[0]} -eq $1 &&
                ${BASH_VERSINFO[1]} -eq $2 &&
                ${BASH_VERSINFO[2]} -ge $3
            )
    ]]
} # is_bash_version_minimal()


# @param $1  Char to remove from $COMP_WORDBREAKS
# @see add_comp_wordbreak_char()
remove_comp_wordbreak_char() {
    COMP_WORDBREAKS=${COMP_WORDBREAKS//$1}
} # remove_comp_wordbreak_char()


# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh