]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pipesz: add bash-completion script
authorNathan Sharp <nwsharp@live.com>
Tue, 12 Apr 2022 04:59:30 +0000 (22:59 -0600)
committerKarel Zak <kzak@redhat.com>
Wed, 18 May 2022 08:35:34 +0000 (10:35 +0200)
Signed-off-by: Nathan Sharp <nwsharp@live.com>
bash-completion/Makemodule.am
bash-completion/pipesz [new file with mode: 0644]
meson.build

index f85211476f0fcb943adcd05890439d36ebe1bf2b..5d59b5593fa4339e3ea0c551cb7c10e57de46f1a 100644 (file)
@@ -335,5 +335,8 @@ endif
 if BUILD_HARDLINK
 dist_bashcompletion_DATA += bash-completion/hardlink
 endif
+if BUILD_PIPESZ
+dist_bashcompletion_DATA += bash-completion/pipesz
+endif
 
 endif # BUILD_BASH_COMPLETION
diff --git a/bash-completion/pipesz b/bash-completion/pipesz
new file mode 100644 (file)
index 0000000..592075c
--- /dev/null
@@ -0,0 +1,102 @@
+_pipesz_module()
+{
+       local WORD OPTS OPTARG OPTEND SOPT LOPT TARG
+       local SOPTS=(g s f n i o e c q v h V)
+       local LOPTS=(get set file fd stdin stdout stderr check quiet verbose help version)
+       local AOPTS=(0 1 1 1 0 0 0 0 0 0 0 0) # takes argument
+       local TOPTS=(1 0 1 1 1 1 1 0 0 0 0 0) # specifies target
+       local XOPTS=(0 0 0 0 0 0 0 0 0 0 1 1) # exits immediately
+       local MOPTS=(0 0 1 1 0 0 0 0 0 0 0 0) # repeatable
+       local NOPTS=(0 0 0 0 0 0 0 0 0 0 0 0) # number of repeats
+       local IDXG=0 IDXS=1                   # index of --get and --set
+
+       for ((i=1; i<COMP_CWORD; i++)); do
+               WORD=${COMP_WORDS[i]}
+
+               if [[ ${NOPTS[$IDXG]} -eq 0 ]]; then
+                       case $WORD in
+                               --)
+                                       _command_offset $((i+1))
+                                       return 0;;
+                               [^-]*)
+                                       _command_offset $i
+                                       return 0;;
+                       esac
+               fi
+
+               for ((j=0; j<${#NOPTS[@]}; j++)); do
+                       SOPT=${SOPTS[$j]}
+                       LOPT=${LOPTS[$j]}
+
+                       case $WORD in
+                               --$LOPT) OPTEND=l;;
+                               --*) continue;;
+                               -*$SOPT) OPTEND=s;;
+                               -*$SOPT*) OPTEND=n;;
+                               *) continue;;
+                       esac
+
+                       if [[ ${XOPTS[$j]} -ne 0 ]]; then
+                               COMPREPLY=()
+                               return 0
+                       fi
+
+                       ((NOPTS[j]++))
+
+                       [[ ${TOPTS[$j]} -ne 0 ]] && TARG=y
+                       [[ $OPTEND != n ]] && ((i+=AOPTS[j]))
+                       [[ $OPTEND == l ]] && break
+               done
+       done
+
+       case $3 in
+               --fd) OPTARG=n;;
+               --file) OPTARG=f;;
+               --size) OPTARG=s;;
+               --*) ;;
+               -*n) OPTARG=n;;
+               -*f) OPTARG=f;;
+               -*s) OPTARG=s;;
+       esac
+
+       case $OPTARG in
+               f)
+                       compopt -o filenames
+                       COMPREPLY=( $(compgen -f -- "$2") )
+                       return 0;;
+               n)
+                       COMPREPLY=( $(compgen -W "0 1 2" -- "$2") )
+                       return 0;;
+               s)
+                       WORD=$2
+                       if [[ ! $WORD =~ ^[0-9]+[a-zA-Z]*$ ]]; then
+                               COMPREPLY=()
+                               return 0
+                       fi
+
+                       while [[ $WORD =~ [a-zA-Z]$ ]]; do WORD=${WORD:0:-1}; done
+
+                       compopt -o nosort
+                       COMPREPLY=( $(compgen -W "$WORD $WORD{K,M,G}{B,iB}" -- "$2") )
+                       return 0;;
+       esac
+
+       for ((j=0; j<${#NOPTS[@]}; j++)); do
+               [[ $j -eq $IDXG && ${NOPTS[$IDXS]} -ne 0 ]] && continue
+               [[ $j -eq $IDXS && ${NOPTS[$IDXG]} -ne 0 ]] && continue
+               [[ $COMP_CWORD -ne 1 && ${XOPTS[$j]} -ne 0 ]] && continue
+               [[ ${NOPTS[$j]} -gt 0 && ${MOPTS[$j]} -eq 0 ]] && continue
+
+               [[ $2 != --* && $2 == -* ]] && OPTS+=" -${SOPTS[$j]}"
+               OPTS+=" --${LOPTS[$j]}"
+       done
+
+       if [[ ! $TARG || ${NOPTS[$IDXG]} -ne 0 ]]; then
+               COMPREPLY=( $(compgen -W "$OPTS" -- "$2") )
+       else
+               compopt -o filenames
+               COMPREPLY=( $(compgen -c -W "$OPTS --" -- "$2") )
+       fi
+}
+
+complete -F _pipesz_module pipesz
index 0e4a94bb5059a1fc0d2befa6480ea2eaf63bad4c..460c322e786106baa10af7f793fcd30456a9393b 100644 (file)
@@ -2694,6 +2694,7 @@ exe = executable(
 if opt and not is_disabler(exe)
   exes += exe
   manadocs += ['misc-utils/pipesz.1.adoc']
+  bashcompletions += ['pipesz']
 endif
 
 exe = executable(