diff --git a/lib/misc.sh b/lib/misc.sh deleted file mode 100644 index a647895..0000000 --- a/lib/misc.sh +++ /dev/null @@ -1,41 +0,0 @@ -# Miscellaneous shell-related functions. - - -# Print boolean value of the exit code of the command passed as argument. -bool() { - "$@" && echo "true" || echo "false" -} - -# Return whether a string is present in a list of strings. -contains_string() { - local match="$1" - local strings="$2" - - local s - for s in $strings; do - if [ "$s" == "$match" ]; then - return 0 - fi - done - return 1 -} - -# Return whether the shell is interactive. -is_interactive() { - [[ $- == *i* ]] -} - -# Source a system file. If no filename is given, list the available names. -s() { - local sourcedir="$SYSTEM_DIR/source" - if [ $# -eq 0 ]; then - ls -1 "$sourcedir" - return - fi - - local file - for file in "$@"; do - # shellcheck disable=SC1090 - . "$sourcedir/$file" - done -} diff --git a/rc.d/210-source.sh b/rc.d/210-source.sh new file mode 100644 index 0000000..50d76a9 --- /dev/null +++ b/rc.d/210-source.sh @@ -0,0 +1,16 @@ +# Helper to source global definition files. + +# Source a system file. If no filename is given, list the available names. +s() { + local sourcedir="$SYSTEM_DIR/source" + if [ $# -eq 0 ]; then + ls -1 "$sourcedir" + return + fi + + local file + for file in "$@"; do + # shellcheck disable=SC1090 + . "$sourcedir/$file" + done +} diff --git a/rc.d/300-completion.sh b/rc.d/300-completion.sh index fbdf58b..de8526e 100644 --- a/rc.d/300-completion.sh +++ b/rc.d/300-completion.sh @@ -1,7 +1,7 @@ # Autocompletion configuration - -if is_interactive; then +# only load completion for interactive shells +if [[ $- == *i* ]]; then source_if_exists /etc/bash_completion _bcomp_s() {