summaryrefslogtreecommitdiff
path: root/maint/rust-maint-common/bash-utils.sh
blob: 1865669747d494d2d7f8aa6d6838659aaf658099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- bash -*-
#
# utilities for maint/ scripts.

# Shellcheck is confused.
# It thinks it ought to be checking this as a standalone script, and prints
#   -- SC2148 (error): Tips depend on target shell and yours is unknown.
#             Add a shebang or a 'shell' directive.
# shellcheck shell=bash

unalias -a
shopt -s expand_aliases

fail () {
    echo >&2 "error: $*"
    exit 12
}

x () {
    echo >&2 "x $*"
    "$@"
}

alias reject_all_arguments='
    if [ $# != 0 ]; then
	fail "bad usage: no arguments allowed"
    fi
'

# shellcheck disable=SC2142
alias reject_options='
case "$1" in
    --) shift ;;
    -*) echo >&2 "$0: No options allowed"; exit 12 ;;
esac
'

# Prints a list of the files in git, with a #! that looks like (ba)sh
git_grep_for_shell_script_shebangs () {
    git grep -P --line-number '^#! ?(/usr/bin/env |/bin/)(:?ba)?sh\b' \
	| sed -n 's/:1:[^:]*$//p'
}