Add BASH auto completion

This commit is contained in:
Paweł Marciniak
2020-07-19 08:57:01 +02:00
committed by Iustin Pop
parent e0e9792238
commit a109c716d8
3 changed files with 47 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ SBINDIR= $(DESTDIR)/$(EXEC_PREFIX)/sbin
BINDIR= $(DESTDIR)$(EXEC_PREFIX)/bin
DATAROOTDIR= $(DESTDIR)/$(PREFIX)/share
MANDIR= $(DATAROOTDIR)/man
COMPLETIONINSTALLDIR=$(DESTDIR)/etc/bash_completion.d
DEFTAPE?= /dev/tape
INSTALL= install
@@ -20,6 +21,7 @@ DISTFILES = \
mt.c \
mtio.h \
README.md \
mt-st \
stinit.8 \
stinit.c \
stinit.def.examples \
@@ -39,9 +41,10 @@ version.h: Makefile
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DDEFTAPE='"$(DEFTAPE)"' -o $@ $<
install: $(PROGS)
$(INSTALL) -d $(BINDIR) $(SBINDIR) $(MANDIR) $(MANDIR)/man1 $(MANDIR)/man8
$(INSTALL) -d $(BINDIR) $(SBINDIR) $(MANDIR) $(MANDIR)/man1 $(MANDIR)/man8 $(COMPLETIONINSTALLDIR)
$(INSTALL) mt $(BINDIR)
$(INSTALL) -m 444 mt.1 $(MANDIR)/man1
$(INSTALL) -m 644 mt-st $(COMPLETIONINSTALLDIR)
(if [ -f $(MANDIR)/man1/mt.1.gz ] ; then \
rm -f $(MANDIR)/man1/mt.1.gz; gzip $(MANDIR)/man1/mt.1; fi)
$(INSTALL) stinit $(SBINDIR)
@@ -78,10 +81,10 @@ distcheck: dist
make install DESTDIR="$$DST" && \
numfiles=$$( \
find "$$DST" -type f \
\( -name mt -o -name stinit -o -name mt.1 -o -name stinit.8 \) | \
\( -name mt -o -name stinit -o -name mt.1 -o -name stinit.8 -o -name mt-st \) | \
wc -l) && \
echo "$$numfiles files installed (4 expected)" && \
test "$$numfiles" -eq 4
echo "$$numfiles files installed (5 expected)" && \
test "$$numfiles" -eq 5
release-tag:
git tag -s -m 'Release version $(VERSION).' mt-st-$(VERSION)

View File

@@ -72,6 +72,7 @@ The files:
- `stinit.c`: The stinit source
- `stinit.8`: The man page for stinit
- `stinit.def.examples`: example configurations for different devices
- `mt-st`: bash auto completion file
## Installation

39
mt-st Normal file
View File

@@ -0,0 +1,39 @@
#mt bash completion by Paweł Marciniak <sunwire<at>gmail.com>
#
_mt () {
local cur prev words cword
_init_completion || return
#possible commands
commands="weof wset eof fsf fsfm bsf bsfm fsr bsr fss bss rewind offline rewoffl eject retension eod seod seek tell status erase setblk lock unlock load compression setdensity drvbuffer stwrthreshold stoptions stsetoptions stclearoptions defblksize defdensity defdrvbuffer defcompression stsetcln sttimeout stlongtimeout densities setpartition mkpartition partseek asf stshowopt"
COMPREPLY=()
case $prev in
-v | --version)
return
;;
-f )
if [ -x "$(command -v udevadm)" ]; then
#list tape devices
for d in `udevadm trigger --verbose --dry-run --type=devices --subsystem-match=scsi_tape`; do
devs+="/dev/${d##*/} "
done
COMPREPLY=($(compgen -W "$devs" -- "$cur"))
else
_filedir
fi
return
;;
esac
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '-f -v' -- "$cur"))
return
fi
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
}
complete -F _mt mt