-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.utils
executable file
·84 lines (79 loc) · 2.8 KB
/
args.utils
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
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
#
# ############################################################################
# Project: xSHELL (none)
# File...: args.utils
# Created: Thursday, 2021/05/20 - 00:26:27
# Author.: Fabiano Matos, fgm ([email protected])
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Monday, 2024/12/09 - 00:41:15
# Modified By..: @fbnmtz, ([email protected])
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 1.0.10.457
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
_xLIB_ARGS_UTILS_=true
# define version of script
xversion(){
# set app version (dynamic from header comments or static)
[ -z "$_VERSION_" ] && _VERSION_="$(head -n 20 "$0" | \
grep '# Version:' -m1 | \
tr -d ' ' | \
cut -d ':' -f2 | \
cut -d '.' -f1-3 \
)"
# get release candidate
local release_candidate="$(head -n 20 "$0" | \
grep '# Version:' -m1 | \
tr -d ' ' | \
cut -d ':' -f2 | \
cut -d '.' -f4 \
)"
_VERSIONRC_="$_VERSION_-rc$release_candidate"
[ -z "$_VERSION_" ] && _VERSION_='0.0.1'
}
# define when script was created
xcreated(){
# set app version (dynamic from header comments or static)
[ -z "$_CREATED_AT_" ] && _CREATED_AT_="$(head -n 20 "$0" | \
grep '# Created:' -m1 | \
tr -d ' ' | \
cut -d ':' -f2 | \
cut -d ',' -f2 | \
cut -d '-' -f1 | \
cut -d '/' -f1 \
)"
# not found date in header comments, try filestats
[ -z "$_CREATED_AT_" ] && \
_CREATED_AT_="$(stat "$0" | \
grep Birth | \
cut -d ' ' -f3 | \
cut -d '.' -f1 | \
cut -d '-' -f1 \
)"
# still null? set as unknown, to be filed later
[ -z "$_CREATED_AT_" ] && _CREATED_AT_='<unknown>'
}
# define author of script
xauthor(){
[ -z "$_AUTHOR_" ] && _AUTHOR_=$(
head -n 20 "$0" | \
grep '# Author.:' -m1 | \
cut -d ':' -f2 |\
cut -d ',' -f1 |\
cut -c2-
)
# not found author in header comments, try get by git config
[ -z "$_AUTHOR_" ] && _AUTHOR_=$(git config --global user.name)
[ -z "$_AUTHOR_" ] && _AUTHOR_=$(git config --global user.email)
[ -z "$_AUTHOR_" ] && _AUTHOR_=$(git config --global author.name)
[ -z "$_AUTHOR_" ] && _AUTHOR_=$(git config --global author.email)
# still null? try by $USER variable
[ -z "$_AUTHOR_" ] && _AUTHOR_="$USER"
# null? set as unknown, to be filled in later
[ -z "$_AUTHOR_" ] && _AUTHOR_='<unknown>'
}