[prev in list] [next in list] [prev in thread] [next in thread]
List: util-linux-ng
Subject: [PATCH RFC 4/4] pipesz: add bash-completion script
From: Nathan Sharp <nwsharp () live ! com>
Date: 2022-04-12 4:59:30
Message-ID: SN6PR04MB39838B437662DE2EDD999740C2ED9 () SN6PR04MB3983 ! namprd04 ! prod ! outlook ! com
[Download RAW message or body]
Signed-off-by: Nathan Sharp <nwsharp@live.com>
---
bash-completion/Makemodule.am | 3 +
bash-completion/pipesz | 102 ++++++++++++++++++++++++++++++++++
meson.build | 1 +
3 files changed, 106 insertions(+)
create mode 100644 bash-completion/pipesz
diff --git a/bash-completion/Makemodule.am b/bash-completion/Makemodule.am
index f852114..5d59b55 100644
--- a/bash-completion/Makemodule.am
+++ b/bash-completion/Makemodule.am
@@ -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
index 0000000..592075c
--- /dev/null
+++ b/bash-completion/pipesz
@@ -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
diff --git a/meson.build b/meson.build
index a94b02f..58b8ea6 100644
--- a/meson.build
+++ b/meson.build
@@ -2689,6 +2689,7 @@ exe = executable(
if opt and not is_disabler(exe)
exes += exe
manadocs += ['misc-utils/pipesz.1.adoc']
+ bashcompletions += ['pipesz']
endif
exe = executable(
--
2.35.1
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic