|
@@ -35,17 +35,17 @@ SHELLFU_EMBEDDED=${SHELLFU_EMBEDDED:-false}
|
35
|
35
|
SHELLFU_GIT_HASH=__MKIT_PROJ_GIT_LASTHASH__
|
36
|
36
|
|
37
|
37
|
#
|
38
|
|
-# Includes folder prefix
|
|
38
|
+# Module folder prefix
|
39
|
39
|
#
|
40
|
|
-# Modules are searched for in path formed by this prefix, plus
|
41
|
|
-# 'sh', plus run-time value of SHELLFU_COMPAT, and if set, in
|
42
|
|
-# directories listed in SHELLFU_PATH
|
|
40
|
+# See shellfu() documentation for details about module loading.
|
43
|
41
|
#
|
44
|
42
|
SHELLFU_INCLUDE=${SHELLFU_INCLUDE:-$SHELLFU_DIR/include}
|
45
|
43
|
|
46
|
44
|
#
|
47
|
45
|
# Colon separated list of additional paths to search modules
|
48
|
46
|
#
|
|
47
|
+# See shellfu() documentation for details about module loading.
|
|
48
|
+#
|
49
|
49
|
SHELLFU_PATH=${SHELLFU_PATH:-}
|
50
|
50
|
|
51
|
51
|
#
|
|
@@ -59,6 +59,59 @@ SHELLFU_VERSION=__MKIT_PROJ_VERSION__
|
59
|
59
|
__SHELLFU_IMPORTED=${__SHELLFU_IMPORTED:-}
|
60
|
60
|
|
61
|
61
|
shellfu() {
|
|
62
|
+ #
|
|
63
|
+ # Shellfu init function
|
|
64
|
+ #
|
|
65
|
+ # Usage:
|
|
66
|
+ #
|
|
67
|
+ # shellfu ACTION MODULE
|
|
68
|
+ #
|
|
69
|
+ # MODULE is selected and acted upon, depending on ACTION:
|
|
70
|
+ #
|
|
71
|
+ # * `import` will source the module using shell built-in dot command.
|
|
72
|
+ #
|
|
73
|
+ # * `try_import` will try to import the module in a separate environment
|
|
74
|
+ # and exit with zero on success (it will not modity the current
|
|
75
|
+ # environment).
|
|
76
|
+ #
|
|
77
|
+ # * `version` will look for directive `#shellfu module-version: VER`
|
|
78
|
+ # and print the VER part.
|
|
79
|
+ #
|
|
80
|
+ # The module lookup algorithm triest to find file MODULE.sh in following
|
|
81
|
+ # directories:
|
|
82
|
+ #
|
|
83
|
+ # 1. Any directories in colon-separated list SHELLFU_PATH,
|
|
84
|
+ #
|
|
85
|
+ # 2. directory formed by joining SHELLFU_INCLUDE and SHELLFU_COMPAT
|
|
86
|
+ # with dingle dash,
|
|
87
|
+ #
|
|
88
|
+ # 3. directory formed by joining 'sh' and SHELLFU_COMPAT with single
|
|
89
|
+ # dash.
|
|
90
|
+ #
|
|
91
|
+ # for example, following code:
|
|
92
|
+ #
|
|
93
|
+ # #!/bin/bash
|
|
94
|
+ #
|
|
95
|
+ # . $(sfpath)
|
|
96
|
+ #
|
|
97
|
+ # SHELLFU_INCLUDE=/shellfu/include
|
|
98
|
+ # SHELLFU_PATH=/shellfu/addon1:/shellfu/addon2
|
|
99
|
+ #
|
|
100
|
+ # shellfu import foo
|
|
101
|
+ #
|
|
102
|
+ # will import first existing file of these:
|
|
103
|
+ #
|
|
104
|
+ # /shellfu/addon1/foo.sh
|
|
105
|
+ # /shellfu/addon2/foo.sh
|
|
106
|
+ # /shellfu/include-bash/foo.sh
|
|
107
|
+ # /shellfu/include-sh/foo.sh
|
|
108
|
+ #
|
|
109
|
+ # Note that SHELLFU_COMPAT should be auto-detected by shellfu and should
|
|
110
|
+ # contain name of current shell binary being executed. This means that
|
|
111
|
+ # modules can exist in multiple versions for each supported shell, and
|
|
112
|
+ # when loading, shellfu prefers the shell-specific implementation.
|
|
113
|
+ #
|
|
114
|
+
|
62
|
115
|
local cmd=$1; shift
|
63
|
116
|
local msg
|
64
|
117
|
|