-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·42 lines (39 loc) · 1.03 KB
/
run
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
#!/usr/bin/env bash
#
# Run a command, via local directories first, then the environment/PATH.
# shellcheck disable=SC2145
set -e
################################################################################
# Run a command, via local directories first, then the environment/PATH.
# Globals:
# None
# Options:
# None
# Arguments:
# [] $args Command to execute.
# Returns:
# None
################################################################################
run () {
local id="${1:-}"
if [[ -n "${id}" ]]; then
# Try to execute local scripts first.
if [[ -x "./${id}" ]]; then
"./$@"
elif [[ -x "./bin/${id}" ]]; then
"./bin/$@"
elif [[ -x "./scripts/${id}" ]]; then
"./scripts/$@"
elif [[ -x "./functions/${id}" ]]; then
"./functions/$@"
elif [[ -x "./scripts/aliases/${id}" ]]; then
"./scripts/aliases/$@"
elif [[ -x "./scripts/functions/${id}" ]]; then
"./scripts/functions/$@"
else
# Or pass it to the command line.
"$@"
fi
fi
}
run "$@"