File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ [* ]
2+ indent_size = 4
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ #
3+ # gen a source guard code snippet for a shell lib file.
4+ #
5+ set -eEuo pipefail
6+
7+ p_uuid_gen () {
8+ if command -v uuidgen & > /dev/null; then
9+ uuidgen
10+ else
11+ python3 -c ' import uuid; print(str(uuid.uuid4()).upper())'
12+ fi
13+ }
14+
15+ new_source_guard_var_name () {
16+ local uuid
17+ uuid=$( p_uuid_gen)
18+ uuid=${uuid// -/ _}
19+
20+ echo " __source_guard_$uuid "
21+ }
22+
23+ new_source_guard () {
24+ local source_guard_var_name
25+ source_guard_var_name=" $( new_source_guard_var_name) "
26+
27+ cat << EOF
28+ #_ source guard start _#
29+ [ -z "\$ {$source_guard_var_name :+dummy}" ] || return 0
30+ $source_guard_var_name ="\$ (dirname "\$ (readlink -f "\$ {BASH_SOURCE[0]}")")"
31+ readonly $source_guard_var_name
32+ #_ source guard end _#
33+ EOF
34+ }
35+
36+ new_source_guard
You can’t perform that action at this time.
0 commit comments