File: jo.bash

package info (click to toggle)
jo 1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 436 kB
  • sloc: ansic: 1,734; sh: 525; makefile: 41; exp: 18
file content (38 lines) | stat: -rw-r--r-- 1,014 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
# bash completion for jo(1)

_jo() {

    # Don't split words on =, for =@ and =% handling
    COMP_WORDBREAKS=${COMP_WORDBREAKS//=}

    # No completion if an exit causing flag is around
    local i
    for i in ${!COMP_WORDS[@]}; do
        [[ $i -ne $COMP_CWORD && ${COMP_WORDS[i]} == -*[hvV]* ]] && return 0
    done

    # Complete available options following a dash
    if [[ $2 == -* ]]; then
        COMPREPLY=( $(compgen -W '-a -B -h -p -v -V' -- "$2") )
        return 0
    fi

    # Complete filenames on =@ and =%
    if [[ $2 == *=[@%]* ]]; then
        local file prefix
        file="${2#*=[@%]}"
        prefix="${2:0:${#2}-${#file}}"
        compopt -o filenames
        COMPREPLY=( $(compgen -f -- "$file") )
        if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
            if [[ -d "${COMPREPLY[0]}" ]]; then
                COMPREPLY[0]+=/
                compopt -o nospace
            fi
            COMPREPLY[0]="$prefix${COMPREPLY[0]}"
        fi
        return 0
    fi

} &&
complete -F _jo jo