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