-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·78 lines (64 loc) · 1.34 KB
/
run.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /bin/sh
#
# run.sh
# Copyright (C) 2015 susy <susy@simbad>
#
# Distributed under terms of the MIT license.
#
#[[ -x $0 ]] && chmod +x $0
absdir=$(dirname $(dirname $(readlink -f $0)))
folder=$(basename $(readlink -f $(dirname $0)))
Pprint ()
{
printf "\n$(tput setaf ${1})${2}$(tput sgr0)"
}
fail=$(Pprint 1 \✗)
good=$(Pprint 2 \✓)
hold=$(Pprint 3 \؟)
Depend ()
{
pkg=$1
hash "$pkg" 2>/dev/null && {
printf "${good} Found command '${pkg}' on system path ..."
} || {
printf >&2 "$fail Command %s not found" $(Pprint 4 $pkg); missing=1
}
}
Require ()
{
typeset -a req
req=$@ missing=0
for pkg in ${req}; do Depend $pkg; done
[[ $missing = 1 ]] && {
printf "${fail} Missing dependencies, aborting ..."
kill -INT $$
}
unset req missing pkg
}
Install ()
{
Require npm
Depend http-server
if [[ $missing = 1 ]]; then
while getopts "g" opt; do
case $opt in
(g)
global='-g'
;;
(*) global=''
;;
esac
done
shift $((OPTIND-1))
npm i $global $@
fi
printf "\n"
}
Run ()
{
Install -g http-server
printf "%s Change directory %s\n" $(Pprint 7 '⇒') $absdir; cd $absdir
printf "%s " $(Pprint 6 '→')
http-server $folder
}
Run