1 | function bundle { |
---|
2 | local ext=$(basename ${SHELL}) |
---|
3 | local folder="${HOME}/.config/bundle/source.d /etc/bundle/source.d" |
---|
4 | |
---|
5 | case "$1" in |
---|
6 | avail) |
---|
7 | for d in ${folder} |
---|
8 | do |
---|
9 | if [ -d "$d" ] |
---|
10 | then |
---|
11 | echo " --- folder $d" |
---|
12 | ( cd "$d" ; find . -type f -a -name "*.${ext}" | sed -e "s/.\///; s/\.${ext}\$//" ) |
---|
13 | fi |
---|
14 | done |
---|
15 | ;; |
---|
16 | |
---|
17 | load) |
---|
18 | pack=$(find ${folder} -type f -a -name "*.${ext}" -print0 2> /dev/null | grep -FzZ "/$2.${ext}" | head -n 1 ) |
---|
19 | if [ -f "${pack}" ] |
---|
20 | then |
---|
21 | export _bundle_name="$2" |
---|
22 | let _bundle_level++ |
---|
23 | export _bundle_level |
---|
24 | export _bundle_status="${_bundle_status}:$2" |
---|
25 | $VERBOSE && echo "Begin bundle: ${_bundle_name}" |
---|
26 | ${SHELL} --rcfile ${pack} |
---|
27 | $VERBOSE && echo "End bundle: ${_bundle_name}" |
---|
28 | unset _bundle_name |
---|
29 | let _bundle_level-- |
---|
30 | [ ${_bundle_level} -eq 0 ] && unset _bundle_level |
---|
31 | export _bundle_status=$(echo "${_bundle_status}" | sed 's/:[^:]*$//') |
---|
32 | [ "${_bundle_status}" == "" ] && unset _bundle_status |
---|
33 | else |
---|
34 | echo "unable to load bundle file: $2" |
---|
35 | echo "Usage: bundle load bundle-file" |
---|
36 | fi |
---|
37 | ;; |
---|
38 | |
---|
39 | unload) |
---|
40 | if [ ${_bundle_level} > 0 ] |
---|
41 | then |
---|
42 | exit |
---|
43 | else |
---|
44 | echo "Error: not a bundle environment!" |
---|
45 | fi |
---|
46 | ;; |
---|
47 | |
---|
48 | show) |
---|
49 | pack=$(find ${folder} -type f -a -name "*.${ext}" -print0 2> /dev/null | grep -FzZ "/$2.${ext}" | head -n 1 ) |
---|
50 | if [ -f "${pack}" ] |
---|
51 | then |
---|
52 | pod2text ${pack} |
---|
53 | else |
---|
54 | echo "unable to find bundle file: $2" |
---|
55 | echo "Usage: bundle show bundle-file" |
---|
56 | fi |
---|
57 | ;; |
---|
58 | |
---|
59 | list) |
---|
60 | if [ ${_bundle_level} > 0 ] |
---|
61 | then |
---|
62 | echo "${_bundle_status}" | sed 's/^://' |
---|
63 | else |
---|
64 | echo "Error: not a bundle environment!" |
---|
65 | fi |
---|
66 | ;; |
---|
67 | |
---|
68 | status) |
---|
69 | if [ ${_bundle_level} > 0 ] |
---|
70 | then |
---|
71 | echo "bundle environment active" |
---|
72 | else |
---|
73 | echo "not a bundle environment" |
---|
74 | fi |
---|
75 | ;; |
---|
76 | |
---|
77 | source) |
---|
78 | pack=$(find ${folder} -type f -a -name "*.${ext}" -print0 2> /dev/null | grep -FzZ "/$2.${ext}" | head -n 1 ) |
---|
79 | if [ -f "${pack}" ] |
---|
80 | then |
---|
81 | . ${pack} |
---|
82 | else |
---|
83 | echo "Usage: bundle source bundle-file" |
---|
84 | fi |
---|
85 | ;; |
---|
86 | |
---|
87 | *) |
---|
88 | echo "Usage: bundle list|avail|load|unload|show|status|source|help" |
---|
89 | ;; |
---|
90 | esac |
---|
91 | } |
---|
92 | |
---|
93 | typeset -fx bundle |
---|
94 | |
---|
95 | return |
---|
96 | |
---|
97 | ################################################################ |
---|
98 | # Documentation in POD format (like Perl) |
---|
99 | ################################################################ |
---|
100 | |
---|
101 | =head1 NAME |
---|
102 | |
---|
103 | bundle - load specific environment in current shell |
---|
104 | |
---|
105 | =head1 SYNOPSIS |
---|
106 | |
---|
107 | bundle avail |
---|
108 | bundle show bundle-file |
---|
109 | |
---|
110 | bundle load bundle-file |
---|
111 | bundle unload |
---|
112 | bundle list |
---|
113 | |
---|
114 | bundle source |
---|
115 | |
---|
116 | bundle status |
---|
117 | |
---|
118 | bundle help |
---|
119 | |
---|
120 | =head1 DESCRIPTION |
---|
121 | |
---|
122 | C<bundle> can load a new environment in current shell |
---|
123 | or load it in a sub-shell. |
---|
124 | |
---|
125 | |
---|
126 | =head1 SEE ALSO |
---|
127 | |
---|
128 | sysprofile, module |
---|
129 | |
---|
130 | |
---|
131 | =head1 AUTHORS |
---|
132 | |
---|
133 | Written by Gabriel Moreau, Grenoble - France |
---|
134 | |
---|
135 | |
---|
136 | =head1 LICENSE AND COPYRIGHT |
---|
137 | |
---|
138 | GPL version 2 or later |
---|
139 | |
---|
140 | Copyright (C) 2011 Gabriel Moreau / LEGI - CNRS UMR 5519 - France |
---|