-
Notifications
You must be signed in to change notification settings - Fork 0
/
shebang_func.sh
47 lines (40 loc) · 1.11 KB
/
shebang_func.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
#!/usr/bin/env bash
function shebang() {
description='
#: Title: shebang
#: Synopsis: generate plaintext file with shebang line, opening in edit mode via vi[m]
#: Date: 2016-05-30
#: Version: 0.1.0
#: Options: shebang [options] ./path/to/file
#: : [-h],[--help]: print usage info
#: : [-v][--version]: print version number and last update
#: : [--details]: print standardize script metadata
'
local funcname=$(echo "$description" | grep '^#: Title: ' | sed 's/#: Title: //g')
local version=$(echo "$description" | grep '^#: Version: ' | sed 's/#: Version: //g')
local updated="$(echo "$description" | grep '^#: Date: ' | sed 's/#: Date: //g')"
function scriptinfo() {
echo
echo "$(type $funcname | head -n 1)" # | head -c 1)"
echo "$description" | sed 's/^#: //g' # cut -c 4-
}
case "$1" in
--details|-h|--help)
scriptinfo
return 0
;;
-v|--version)
printf "\n%s\n\n" "$funcname : $version : $updated"
return 0
;;
*)
:
;;
esac
{
echo '#!/usr/bin/env bash'
echo
echo
} > "$1"
vi -c 'startinsert' +3 "$1"
}