bash-utils.sh
1 # -*- bash -*- 2 # 3 # utilities for maint/ scripts. 4 5 # Shellcheck is confused. 6 # It thinks it ought to be checking this as a standalone script, and prints 7 # -- SC2148 (error): Tips depend on target shell and yours is unknown. 8 # Add a shebang or a 'shell' directive. 9 # shellcheck shell=bash 10 11 unalias -a 12 shopt -s expand_aliases 13 14 fail () { 15 echo >&2 "error: $*" 16 exit 12 17 } 18 19 x () { 20 echo >&2 "x $*" 21 "$@" 22 } 23 24 alias reject_all_arguments=' 25 if [ $# != 0 ]; then 26 fail "bad usage: no arguments allowed" 27 fi 28 ' 29 30 # shellcheck disable=SC2142 31 alias reject_options=' 32 case "${1-}" in 33 --) shift ;; 34 -*) echo >&2 "$0: No options allowed"; exit 12 ;; 35 esac 36 ' 37 38 # Prints a list of the files in git, with a #! that looks like (ba)sh 39 git_grep_for_shell_script_shebangs () { 40 git grep -P --line-number '^#! ?(/usr/bin/env |/bin/)(:?ba)?sh\b' \ 41 | sed -n 's/:1:[^:]*$//p' 42 }