making bash_completion install smarter

This commit is contained in:
James Tomasino 2018-03-03 18:24:05 -05:00
parent bb778691ce
commit ba532b7f26
3 changed files with 47 additions and 34 deletions

View File

@ -1,7 +1,13 @@
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man MANDIR ?= $(PREFIX)/share/man
CPLDIR ?= $$(pkg-config --variable=completionsdir bash-completion) ifneq ($(wildcard /etc/bash_completion.d/.),)
CPLDIR ?= /etc/bash_completion.d
else
ifneq ($(shell command -v pkg-config 2> /dev/null))
CPLDIR ?= $$(pkg-config --variable=completionsdir bash-completion)
endif
endif
install: install:
@echo Installing the executable to $(DESTDIR)$(BINDIR) @echo Installing the executable to $(DESTDIR)$(BINDIR)

56
burrow
View File

@ -65,7 +65,7 @@ END
function parse_input() { function parse_input() {
parsed=$(getopt --options=$arg_options --longoptions=$arg_longoptions --name "$0" -- "$@") parsed=$(getopt --options=$arg_options --longoptions=$arg_longoptions --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
exit 2 die "Invalid input" 2
fi fi
eval set -- "$parsed" eval set -- "$parsed"
@ -93,8 +93,7 @@ function parse_input() {
break break
;; ;;
*) *)
echo "Internal error: $1" die "Internal error: $1" 3
exit 3
;; ;;
esac esac
done done
@ -131,8 +130,18 @@ function update_gopher_date() {
function check_directory() { function check_directory() {
if [[ ! -d "$1" ]] if [[ ! -d "$1" ]]
then then
echo "Missing directory: $1 aborting." die "Missing directory: $1 aborting."
exit 1 fi
}
function die {
if [[ ! -z "$1" ]]; then
echo "$1";
if [[ "$2" =~ /^[0-9]+$/ ]] ; then
exit "$2"
else
exit 1
fi
fi fi
} }
@ -153,11 +162,13 @@ function make_post() {
use_date="$4" use_date="$4"
update_root="$5" update_root="$5"
check_directory "$config_dir_gopher"
check_directory "${config_dir_gopher}${type}"
read -r -e -p "$query" title read -r -e -p "$query" title
if [[ $title == "" ]] if [[ $title == "" ]]
then then
echo "Cancelled." die "Cancelled." 0
exit 0
fi fi
type_gophermap="${config_dir_gopher}${type}/gophermap" type_gophermap="${config_dir_gopher}${type}/gophermap"
@ -216,7 +227,7 @@ function make_post() {
if [[ $config_autoindent == true ]] && [[ $flag_noautoindent == 0 ]] if [[ $config_autoindent == true ]] && [[ $flag_noautoindent == 0 ]]
then then
echo "Processing for links and autoindenting" echo "Processing for links and autoindenting"
temp_links=$(mktemp -t "$(basename "$0").links.XXXXXXX") || exit 1 temp_links=$(mktemp -t "$(basename "$0").links.XXXXXXX") || die "Failed to create temporary file" 1
sed -n '/^Links:$/,$p' "$post_file" | tail -n +2 > "$temp_links" sed -n '/^Links:$/,$p' "$post_file" | tail -n +2 > "$temp_links"
sed -i '/^Links:$/,$d' "$post_file" sed -i '/^Links:$/,$d' "$post_file"
sed -i 's/^/ /' "$post_file" sed -i 's/^/ /' "$post_file"
@ -226,7 +237,7 @@ function make_post() {
fi fi
echo "Updating $type" echo "Updating $type"
temp_gophermap=$(mktemp -t "$(basename "$0").gophermap.XXXXXXX") || exit 1 temp_gophermap=$(mktemp -t "$(basename "$0").gophermap.XXXXXXX") || die "Failed to create temporary file" 1
if $use_gophermap; then if $use_gophermap; then
if $use_date; then if $use_date; then
@ -279,18 +290,6 @@ function make_post() {
fi fi
} }
function topic_new() {
make_post "What topic? " "$config_dir_topics" true false true
}
function recipe_new() {
make_post "What is the name of your recipe? " "$config_dir_recipebox" false false true
}
function phlog_new() {
make_post "Enter a title for your post: " "$config_dir_phlog" true true true
}
function create_config() { function create_config() {
if [[ ! -f "$HOME/.config/burrow/config" ]] && if [[ ! -f "$HOME/.config/burrow/config" ]] &&
[[ ! -f "$HOME/.config/burrow" ]] && [[ ! -f "$HOME/.config/burrow" ]] &&
@ -332,8 +331,7 @@ function main() {
if [[ $arg_shortlist -gt 0 ]] if [[ $arg_shortlist -gt 0 ]]
then then
echo "phlog topic recipe create-config update-git -v -h -d --version --help --debug --noautoindent" die "phlog topic recipe create-config update-git -v -h -d --version --help --debug --noautoindent" 0
exit 0
fi fi
if [[ $flag_version -gt 0 ]] if [[ $flag_version -gt 0 ]]
@ -371,23 +369,17 @@ function main() {
if [[ ${arg_recipe} -gt 0 ]] if [[ ${arg_recipe} -gt 0 ]]
then then
check_directory "$config_dir_gopher" make_post "What is the name of your recipe? " "$config_dir_recipebox" false false true
check_directory "${config_dir_gopher}${config_dir_recipebox}"
recipe_new
fi fi
if [[ ${arg_topic} -gt 0 ]] if [[ ${arg_topic} -gt 0 ]]
then then
check_directory "$config_dir_gopher" make_post "What is the name of your topic? " "$config_dir_topics" true false true
check_directory "${config_dir_gopher}${config_dir_topics}"
topic_new
fi fi
if [[ ${arg_phlog} -gt 0 ]] if [[ ${arg_phlog} -gt 0 ]]
then then
check_directory "$config_dir_gopher" make_post "Enter a title for your post: " "$config_dir_phlog" true true true
check_directory "${config_dir_gopher}${config_dir_phlog}"
phlog_new
fi fi
} }

View File

@ -11,4 +11,19 @@ _burrow()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( compgen -W "$helplist" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$helplist" -- "$cur" ) )
} }
complete -F _burrow burrow
# Detect if current shell is ZSH, and if so, load this file in bash
# compatibility mode.
if [ -n "$ZSH_VERSION" ]; then
autoload bashcompinit
bashcompinit
fi
complete -o default -o nospace -F _burrow burrow
# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
complete -o default -o nospace -F _burrow burrow.exe
fi