From 5b835cab8c3f58f992433783be59e4b813d8387f Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Sat, 20 Jan 2018 15:02:34 -0500 Subject: [PATCH] added command completion --- Makefile | 16 +++++++++++----- burrow | 16 ++++++++++++---- burrow.d | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 burrow.d diff --git a/Makefile b/Makefile index 1dd048b..258f07e 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,27 @@ PREFIX ?= /usr BINDIR ?= $(PREFIX)/bin MANDIR ?= $(PREFIX)/share/man +CPLDIR ?= /etc/bash_completion.d install: @echo Installing the executable to $(DESTDIR)$(BINDIR) - @mkdir -p $(DESTDIR)$(BINDIR) - @cp -f burrow $(DESTDIR)$(BINDIR)/burrow - @chmod 755 $(DESTDIR)$(BINDIR)/burrow + @mkdir -p $(DESTDIR)$(BINDIR) + @cp -f burrow $(DESTDIR)$(BINDIR)/burrow + @chmod 755 $(DESTDIR)$(BINDIR)/burrow @echo Installing the manual page to $(DESTDIR)$(MANDIR)/man1 - @mkdir -p $(DESTDIR)$(MANDIR) + @mkdir -p $(DESTDIR)$(MANDIR) @cp -f burrow.1 $(DESTDIR)$(MANDIR)/man1/burrow.1 - @chmod 644 $(DESTDIR)$(MANDIR)/man1/burrow.1 + @chmod 644 $(DESTDIR)$(MANDIR)/man1/burrow.1 + @echo Installing the command completion to $(DESTDIR)$(CPLDIR) + @cp -f burrow.d $(DESTDIR)$(CPLDIR)/burrow.d + @chmod 644 $(DESTDIR)$(CPLDIR)/burrow.d uninstall: @echo Removing the executable from $(DESTDIR)$(BINDIR) @rm -f $(DESTDIR)$(BINDIR)/burrow @echo Removing the manual page from $(DESTDIR)$(MANDIR)/man1 @rm -f $(DESTDIR)$(BINDIR)/man1/burrow.1 + @echo Removing the command completion from $(DESTDIR)$(CPLDIR) + @rm -f $(DESTDIR)$(CPLDIR)/burrow.d .PHONY: install uninstall diff --git a/burrow b/burrow index 88f8f9a..01bd3b7 100755 --- a/burrow +++ b/burrow @@ -32,7 +32,7 @@ ARGUMENTS (multiple allowed): phlog - create new phlog entry recipe - add new recipe to box create-config - create a default configuration file -update-git - pulls gopher git repo if exists +update-git - silently pulls gopher git repo if it exists OPTIONAL FLAGS: help [-h] - show this help @@ -41,6 +41,14 @@ verbose [-v] - verbose logging END } +pushd () { + command pushd "$@" 2>/dev/null 1>&2 +} + +popd () { + command popd 2>/dev/null 1>&2 +} + function parseopts() { while getopts ":hv" opt do @@ -84,7 +92,7 @@ function day_suffix() { esac } -function update_gopher() { +function update_gopher_date() { sed --in-place='' "s/.*Last\ Updated:.*/ ==== Last Updated: $(date +"%B %d$(day_suffix), %Y") ====/" "${config_location_gopher}/gophermap" } @@ -129,7 +137,7 @@ function recipe_new() { $editor "$post_path" echo -e "0$title\t$(basename "$post_path")\n$(cat "${config_location_recipebox}/gophermap")" > "${config_location_recipebox}/gophermap" sort -fo "${config_location_recipebox}/gophermap" "${config_location_recipebox}/gophermap" - update_gopher + update_gopher_date if [[ $config_post_recipebox_command != "" ]] then @@ -197,7 +205,7 @@ function phlog_new() { rm "$links" echo -e "1$(date +%Y-%m-%d) - $title\t$(basename "$post_dir")\n$(cat "${config_location_phlog}/gophermap")" > "${config_location_phlog}/gophermap" - update_gopher + update_gopher_date if [[ $config_post_phlog_command != "" ]] then diff --git a/burrow.d b/burrow.d new file mode 100644 index 0000000..0993f73 --- /dev/null +++ b/burrow.d @@ -0,0 +1,14 @@ +_burrow() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="phlog recipe create-config update-git -v -h" + + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} +complete -F _burrow burrow