source: trunk/bundle/bundle.bash @ 56

Last change on this file since 56 was 56, checked in by g7moreau, 12 years ago
  • Small doc
  • Rename folder bundle.d to source.d
File size: 3.0 KB
Line 
1function 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      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
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      *)
77         echo "Usage: bundle list|avail|load|unload|status|source|help"
78         ;;
79   esac
80   }
81
82typeset -fx bundle
83
84return
85
86################################################################
87# Documentation in POD format (like Perl)
88################################################################
89
90=head1 NAME
91
92bundle - load specific environment in current shell
93
94=head1 SYNOPSIS
95
96=head1 SYNOPSIS
97
98 bundle avail
99
100 bundle load bundle-file
101 bundle unload
102 bundle list
103
104 bundle source
105
106 bundle status
107
108 bundle help
109
110=head1 DESCRIPTION
111
112C<bundle> can load a new environment in current shell
113or load it in a sub-shell.
114
115
116=head1 SEE ALSO
117
118sysprofile, module
119
120
121=head1 AUTHORS
122
123Written by Gabriel Moreau, Grenoble - France
124
125
126=head1 LICENSE AND COPYRIGHT
127
128GPL version 2 or later
129
130Copyright (C) 2011 Gabriel Moreau / LEGI - CNRS UMR 5519 - France
Note: See TracBrowser for help on using the repository browser.