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