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