Merge pull request #2 from catseye/develop-0.3
Develop 0.3
Chris Pressey authored 7 years ago
GitHub committed 7 years ago
0 | 0 | shelf |
1 | 1 | ===== |
2 | 2 | |
3 | *Version 0.2. Subject to change in backwards-incompatible ways.* | |
3 | *Version 0.3. Subject to change in backwards-incompatible ways.* | |
4 | 4 | |
5 | 5 | Cat's Eye Technologies' **shelf** is "a package installer which |
6 | 6 | neither packages nor installs". It aims to be a replacement for |
32 | 32 | |
33 | 33 | `SHELF_PATH` should be a colon-separated list of directories where you |
34 | 34 | will be keeping the source directories you wish to manage using shelf. |
35 | ||
36 | If you are using `bash`, you can also configure some nicer tab-completion | |
37 | by sourcing `shelf_tabcomplete.sh`, i.e. you can also add | |
38 | ||
39 | . $HOME/.shelf/shelf_tabcomplete.sh | |
40 | ||
41 | to your startup script. | |
35 | 42 | |
36 | 43 | Usage |
37 | 44 | ----- |
90 | 97 | Pushes changes from the project in *DIR* to the project of the same basename |
91 | 98 | in *DEST*. Currently only supports git repos. Always pushes the changes to |
92 | 99 | a branch in *DEST* whose name is the name of the current branch in *DIR; if |
93 | there is no such branch configured in *DEST*, an error occurs. *DEST* should | |
94 | be a directory on the `SHELF_PATH`. | |
100 | there is no such branch configured in *DEST*, it will be fetched first. | |
101 | *DEST* should be a directory on the `SHELF_PATH`. | |
95 | 102 | |
96 | * `shelf_fanout` *DIR* | |
103 | * `shelf_fanout` *DIR* [*DIR* ...] | |
97 | 104 | |
98 | 105 | Executes a `shelf_push` to every directory on the `SHELF_PATH` that contains |
99 | 106 | a project directory that has the same basename as *DIR*. |
151 | 158 | functions will not make significant changes to the state of the |
152 | 159 | filesystem (for example, running commands like `ln` and `rm`) and instead |
153 | 160 | will only report that such changes would be made. |
161 | ||
162 | ### TODO | |
163 | ||
164 | * Make a `shelf_pull` to complement `shelf_push`. | |
165 | * Make a `shelf_fanin` to complement `shelf_fanout`. | |
166 | * Make a `shelf_populate_from_shelf` (`shelf_replicate`?) | |
167 | * Would a `shelf_pwd_all` be helpful? It's in my notes, but I don't know why. | |
168 | ||
169 | ### History | |
170 | ||
171 | #### 0.3 | |
172 | ||
173 | * Added tab completion for bash. | |
174 | * Made `shelf_push` and `shelf_fanout` fetch the branch first, so new branches | |
175 | can be pushed to repositories that don't have them yet. | |
176 | * `shelf_fanout` is able to process multiple project directories. | |
177 | ||
178 | #### 0.2 | |
179 | ||
180 | * Added `shelf_test`, `shelf_dockgh`, `shelf_push`, `shelf_fanout`, | |
181 | `shelf_populate_from_distfiles`, `shelf_populate_from_git`, `shelf_cast`, | |
182 | `shelf_pin`, and `shelf_unpin`. | |
183 | * `shelf_build` is able to process multiple sources. | |
184 | * Fixed bug where `shelf_build` exited immediately on the first error. | |
185 | ||
186 | #### 0.1 | |
187 | ||
188 | * Initial version. |
252 | 252 | fi |
253 | 253 | } |
254 | 254 | |
255 | _shelf_pull_from_dest() { | |
256 | # utility function only used internally by _shelf_push() | |
257 | src=$1 | |
258 | branch=$2 | |
259 | origin=`git remote get-url origin` | |
260 | if [ "X$origin" != "X$src" ]; then | |
261 | echo "Resetting origin to $src" | |
262 | git remote remove origin | |
263 | git remote add origin $src | |
264 | fi | |
265 | git fetch && git checkout $branch && git pull origin $branch | |
266 | } | |
267 | ||
255 | 268 | _shelf_push() { |
256 | 269 | src=$1 |
257 | 270 | dest=$2 |
268 | 281 | echo "Couldn't determine branch" |
269 | 282 | return 1 |
270 | 283 | fi |
271 | (cd $dest && git checkout $branch && git pull $src $branch) | |
284 | (cd $dest && _shelf_pull_from_dest $src $branch) | |
272 | 285 | } |
273 | 286 | |
274 | 287 | shelf_push() { |
309 | 322 | shelf_fanout() { |
310 | 323 | path=`echo "$SHELF_PATH" | sed -e 's/:/ /g'` |
311 | 324 | |
312 | project=$1 | |
313 | dir=`_shelf_abspath_dir "$dir"` | |
314 | base=`basename "$dir"` | |
315 | ||
316 | for shelf in $path; do | |
317 | if [ "$dir" = "$shelf/$base" ]; then | |
318 | continue | |
319 | fi | |
320 | if [ -d "$shelf/$base" ]; then | |
321 | echo "--> $shelf/$base" | |
322 | _shelf_push $dir "$shelf/$base" | |
323 | fi | |
325 | for dir in $*; do | |
326 | dir=`_shelf_abspath_dir "$dir"` | |
327 | base=`basename "$dir"` | |
328 | ||
329 | for shelf in $path; do | |
330 | if [ "$dir" = "$shelf/$base" ]; then | |
331 | continue | |
332 | fi | |
333 | if [ -d "$shelf/$base" ]; then | |
334 | echo "--> $shelf/$base" | |
335 | _shelf_push $dir "$shelf/$base" | |
336 | fi | |
337 | done | |
324 | 338 | done |
325 | 339 | } |
326 | 340 |
0 | # tab-completion setup for shelf in bash | |
1 | # source this file after shelf has been loaded. | |
2 | # note, I do not claim to entirely know what I'm doing here. | |
3 | ||
4 | function _shelf_cd_tabcomplete_() | |
5 | { | |
6 | local cmd="${1##*/}" | |
7 | local word=${COMP_WORDS[COMP_CWORD]} | |
8 | local line=${COMP_LINE} | |
9 | ||
10 | local path=`echo "$SHELF_PATH" | sed -e 's/:/ /g'` | |
11 | local subdirs='' | |
12 | for d in $path; do | |
13 | if [ -d $d ]; then | |
14 | these=`ls $d` | |
15 | subdirs="$subdirs $these" | |
16 | fi | |
17 | done | |
18 | ||
19 | COMPREPLY=($(compgen -W "${subdirs}" "${word}")) | |
20 | } | |
21 | ||
22 | complete -F _shelf_cd_tabcomplete_ shelf_cd | |
23 | ||
24 | ||
25 | function _shelf_which_tabcomplete_() | |
26 | { | |
27 | local cmd="${1##*/}" | |
28 | local word=${COMP_WORDS[COMP_CWORD]} | |
29 | local line=${COMP_LINE} | |
30 | ||
31 | local path=`echo "$SHELF_PATH" | sed -e 's/:/ /g'` | |
32 | local files=`ls $SHELF_FARMBASE/bin` | |
33 | ||
34 | COMPREPLY=($(compgen -W "${files}" "${word}")) | |
35 | } | |
36 | ||
37 | complete -F _shelf_which_tabcomplete_ shelf_which |