From c5fd7ad00e4aee69d5da0b4cc56258901e91bc2a Mon Sep 17 00:00:00 2001 From: Patrick R Date: Mon, 24 Jan 2022 14:21:15 +0100 Subject: [PATCH 1/2] Adds proper installation of bash-autocomplete As usual things require more work than expected. This is the most general bash-completion installation strategy I could find short of appending to the shell configuration file. --- install.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index e2adae2..83ca633 100755 --- a/install.sh +++ b/install.sh @@ -265,10 +265,31 @@ CAUTION: '$BIN' is not on your \$PATH. You fi fi -if type complete >/dev/null 2>/dev/null; then - $E complete -W "latex bibtex go gloss show clean" swth + +if type complete >/dev/null 2>/dev/null ; then + if type pkg-config >/dev/null 2>/dev/null ; then + COMPLETE_INSTALL_DIR=$(pkg-config --variable=compatdir bash-completion) + if [ ! -z "$COMPLETE_INSTALL_DIR" ]; then + if [ ! -w "$COMPLETE_INSTALL_DIR" ]; then + printf "\n$COMPLETE_INSTALL_DIR is not writable, continue as root (sudo)? [NO|yes] " + EOLD=$E + read ANS + case "$ANS" in + [Yy][Ee][Ss]) E=sudo ;; + *) exit 2 ;; + esac + fi + $ECHO 'complete -W "latex bibtex go gloss show clean" swth' | $E tee -a "$COMPLETE_INSTALL_DIR"/swth >/dev/null + E=$EOLD + else + $ECHO ">> no automatic installation directory found, skipping configuration of auto completion." + fi +else + $ECHO ">> \`pkg-config' not found, skipping configuration of auto completion." +fi else - $ECHO ">> \`complete' not found, skipping configuration of auto completion." + $ECHO ">> \`complete' not found, skipping configuration of auto completion." fi + $ECHO "Done" From 4fe29952b39b266a32518925e23082ef4fedab6d Mon Sep 17 00:00:00 2001 From: Patrick R Date: Wed, 8 Feb 2023 10:29:31 +0100 Subject: [PATCH 2/2] Moves the installation of the auto completion from the install.sh to the actual swth tool. Reworks the checking of pre-requisites --- install.sh | 27 --------------------------- swth | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/install.sh b/install.sh index 83ca633..3c6f8ff 100755 --- a/install.sh +++ b/install.sh @@ -265,31 +265,4 @@ CAUTION: '$BIN' is not on your \$PATH. You fi fi - -if type complete >/dev/null 2>/dev/null ; then - if type pkg-config >/dev/null 2>/dev/null ; then - COMPLETE_INSTALL_DIR=$(pkg-config --variable=compatdir bash-completion) - if [ ! -z "$COMPLETE_INSTALL_DIR" ]; then - if [ ! -w "$COMPLETE_INSTALL_DIR" ]; then - printf "\n$COMPLETE_INSTALL_DIR is not writable, continue as root (sudo)? [NO|yes] " - EOLD=$E - read ANS - case "$ANS" in - [Yy][Ee][Ss]) E=sudo ;; - *) exit 2 ;; - esac - fi - $ECHO 'complete -W "latex bibtex go gloss show clean" swth' | $E tee -a "$COMPLETE_INSTALL_DIR"/swth >/dev/null - E=$EOLD - else - $ECHO ">> no automatic installation directory found, skipping configuration of auto completion." - fi -else - $ECHO ">> \`pkg-config' not found, skipping configuration of auto completion." -fi -else - $ECHO ">> \`complete' not found, skipping configuration of auto completion." -fi - - $ECHO "Done" diff --git a/swth b/swth index 1f4a0b1..5e2f661 100755 --- a/swth +++ b/swth @@ -27,9 +27,11 @@ OPTIONS --lua use LuaLaTeX --biber use Biber instead of BibTeX - --help output this help and exit - --dry-run don't execute, just say what would be - --version output version information and exit + --help output this help and exit + --dry-run don't execute, just say what would be + --install-completion install bash autocompletion + --version output version information and exit + COMMAND @@ -352,6 +354,38 @@ _go() { _bibtex && _latex && _latex && _latex && _show } +_install_completion() { + if ! bash --version >/dev/null 2>/dev/null ; then + $ECHO ">> \`bash' not found, skipping configuration of auto completion." + exit 300 + fi + if ! bash -c type complete >/dev/null 2>/dev/null ; then + $ECHO ">> \`complete' not found, skipping configuration of auto completion." + exit 300 + fi + if ! bash -c type pkg-config >/dev/null 2>/dev/null ; then + $ECHO ">> \`pkg-config' not found, skipping configuration of auto completion." + exit 300 + fi + + COMPLETE_INSTALL_DIR=$(pkg-config --variable=compatdir bash-completion) + if [ ! -z "$COMPLETE_INSTALL_DIR" ]; then + if [ ! -w "$COMPLETE_INSTALL_DIR" ]; then + printf "\n$COMPLETE_INSTALL_DIR is not writable, continue as root (sudo)? [NO|yes] " + EOLD=$E + read ANS + case "$ANS" in + [Yy][Ee][Ss]) E=sudo ;; + *) exit 2 ;; + esac + fi + $ECHO 'complete -W "latex bibtex go gloss show clean" swth' | $E tee -a "$COMPLETE_INSTALL_DIR"/swth >/dev/null + E=$EOLD + else + $ECHO ">> no automatic installation directory found, skipping configuration of auto completion." + fi +} + _author() { if [ "$MODE" != "bachelor" ]; then $ECHO "$PROGRAM: adding an author outside BSc mode is not meaningful, aborting" @@ -424,6 +458,10 @@ while [ $# -gt 0 ]; do $ECHO "$PROGRAM $VERSION" exit 0 ;; + --install-completion) + _install_completion + exit 0 + ;; --verbose | -verbose | -v) VERBOSE=true ;; --dry-run | -n) DRY=true ;; --bachelor | -B | -BA | -BSc) MODE=bachelor ;;