|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -BASHDDIR=$(dirname $0) |
| 3 | +BASHDDIR=$(dirname "$0") |
4 | 4 |
|
5 | | -USAGE="`basename $0` [-e <config>|-d config|-l]" |
| 5 | +# shellcheck disable=SC2086 |
| 6 | +USAGE="$(basename $0) [-e <config>|-d config|-l]" |
6 | 7 |
|
7 | 8 | function usage { |
8 | | - echo $USAGE |
| 9 | + echo "$USAGE" |
9 | 10 | cat <<EOF |
10 | 11 | Enable, disable or list available bash config. Run without any parameters it |
11 | 12 | will list currently enabled configs. |
|
19 | 20 | } |
20 | 21 |
|
21 | 22 | function enable_config { |
22 | | - SOURCE=$BASHDDIR/avaiable/$1 |
23 | | - TARGET=$BASHDDIR/enabled/$1 |
| 23 | + # first arg is the -e so renove it |
| 24 | + shift |
| 25 | + exit_state=0 |
| 26 | + for src in "$@"; do |
| 27 | + SOURCE=$BASHDDIR/available/$src |
| 28 | + TARGET=$BASHDDIR/enabled/$src |
24 | 29 |
|
25 | | - if [ ! -e "$SOURCE" ]; then |
26 | | - echo "No such config ($1)" |
27 | | - exit 1 |
28 | | - fi |
| 30 | + if [ ! -e "$SOURCE" ]; then |
| 31 | + echo "No such config ($1)" |
| 32 | + exit_state=1 |
| 33 | + fi |
29 | 34 |
|
30 | | - if [ -L "$TARGET" ]; then |
31 | | - echo "Config already enabled ($1)" |
32 | | - exit 1 |
33 | | - fi |
| 35 | + if [ -L "$TARGET" ]; then |
| 36 | + echo "Config already enabled ($1)" |
| 37 | + exit_state=1 |
| 38 | + fi |
34 | 39 |
|
35 | | - ln -s $(realpath $SOURCE) $TARGET |
| 40 | + # shellcheck disable=SC2046 |
| 41 | + ln -s $(realpath "$SOURCE") "$TARGET" |
| 42 | + echo "Enabled $src" |
| 43 | + done |
| 44 | + exit "$exit_state" |
36 | 45 | } |
37 | 46 |
|
38 | 47 | function disable_config { |
39 | 48 | TARGET=$BASHDDIR/enabled/$1 |
40 | | - rm -f $TARGET |
| 49 | + rm -f "$TARGET" |
41 | 50 | } |
42 | 51 |
|
43 | 52 | function list_configs { |
44 | | - ls -1 $BASHDDIR/avaiable |
| 53 | + ls -1 "$BASHDDIR/available" |
45 | 54 | } |
46 | 55 |
|
47 | 56 | while getopts "e:d:lh" options; do |
48 | 57 | case $options in |
49 | | - e) enable_config $OPTARG; exit;; |
50 | | - d) disable_config $OPTARG; exit;; |
| 58 | + e) enable_config "$@"; exit;; |
| 59 | + d) disable_config "$@"; exit;; |
51 | 60 | l) list_configs; exit;; |
52 | | - h) usage; exit;; |
| 61 | + h) ;; |
| 62 | + *) usage; exit;; |
53 | 63 | esac |
54 | 64 | done |
55 | 65 |
|
56 | 66 | # If we got this far without exiting it's a list currently enabled |
57 | | -ls -1 $BASHDDIR/enabled |
| 67 | +ls -1 "$BASHDDIR/enabled" |
0 commit comments