source: trunk/bundle/bundle.bash @ 54

Last change on this file since 54 was 54, checked in by g7moreau, 9 years ago
  • Rename list -> avail (like module)
  • Add command list -> load bundle
  • Add command status
File size: 3.0 KB
Line 
1function bundle {
2   local ext=$(basename ${SHELL})
3   local folder="/etc/bundle/bundle.d ${HOME}/.config/loadenv"
4
5   case "$1" in
6      avail)
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            export _bundle_status="${_bundle_status}:$2"
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
25            export _bundle_status=$(echo "${_bundle_status}" | sed 's/:[^:]*$//')
26            [ "${_bundle_status}" == "" ] && unset _bundle_status
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
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
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      *)
71         echo "Usage: bundle list|avail|load|unload|status|source|help"
72         ;;
73   esac
74   }
75
76typeset -fx bundle
77
78return
79
80################################################################
81# Documentation in POD format (like Perl)
82################################################################
83
84=head1 NAME
85
86bundle - 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
103C<bundle> can load a new environment in current shell
104or laod it in a sub-shell.
105
106
107=head1 SEE ALSO
108
109sysprofile, module
110
111
112=head1 AUTHORS
113
114Written by Gabriel Moreau, Grenoble - France
115
116
117=head1 LICENSE AND COPYRIGHT
118
119GPL version 2 or later
120
121Copyright (C) 2011 Gabriel Moreau / LEGI - CNRS UMR 5519 - France
Note: See TracBrowser for help on using the repository browser.