Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (45 sloc) 1.463 kb
5f60ad1 @rtomayko pgem-list shows installed packages
authored
1 #!/bin/sh
04fbd78 @rtomayko docco everywhere
authored
2 # The `rpg-list` program walks over the installed package database and
3 # writes a line with the `<package> <version>` to `stdout` for each installed
4 # package.
5f60ad1 @rtomayko pgem-list shows installed packages
authored
5 set -e
4b1ed8b @rtomayko s/pgem/rpg/g on entire project
authored
6 . rpg-sh-setup
9abeb5c @rtomayko usage and logging cleanup across the board
authored
7
8 ARGV="$@"
9 USAGE '${PROGNAME} [-x] [<glob>...]
4b1ed8b @rtomayko s/pgem/rpg/g on entire project
authored
10 List rpg installed packages.
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
11
12 Options
9abeb5c @rtomayko usage and logging cleanup across the board
authored
13 -x Include non-matching globs in output.
5f60ad1 @rtomayko pgem-list shows installed packages
authored
14
9abeb5c @rtomayko usage and logging cleanup across the board
authored
15 Only list packages matching <glob> when provided. With multiple <glob>s,
16 list packages matching any one of them.'
5f60ad1 @rtomayko pgem-list shows installed packages
authored
17
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
18 shownonmatch=false
19 test "$1" = '-x' && {
20 shownonmatch=true
21 shift
22 }
23
04fbd78 @rtomayko docco everywhere
authored
24 # With no `<globs>`, list everything.
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
25 [ "$*" ] || set -- '*'
26
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
27 # Switch into package database dir or bail out if it doesn't exist.
4b1ed8b @rtomayko s/pgem/rpg/g on entire project
authored
28 test -d "$RPGDB" &&
29 cd "$RPGDB" || exit 0
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
30
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
31 # Run over globs gives on the command line and locate matching
04fbd78 @rtomayko docco everywhere
authored
32 # installed packages. By default, nothing is written for glob patterns
33 # that don't match an installed package. The `-x` option changes this
34 # behavior so that a single line is output with the package version '-'.
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
35 for glob in "$@"
5f60ad1 @rtomayko pgem-list shows installed packages
authored
36 do
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
37 matched=false
38 for path in $(ls -1 $glob/active 2>/dev/null)
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
39 do
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
40 matched=true
41 package=${path%/active}
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
42 vers=$(readlink $path)
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
43 printf "%-30s %s\n" $package $vers
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
44 done
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
45
46 if $shownonmatch && ! $matched
99e01e0 @rtomayko pgem-status is the most amazing thing you've ever seen
authored
47 then printf "%-30s %s\n" "$glob" "-"
9e45ee6 @rtomayko pgem-list -x writes lines for non-matching globs
authored
48 fi
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
49 done |
50
04fbd78 @rtomayko docco everywhere
authored
51 # It's possible for multiple globs to match the same package. Run the
52 # stream text through `sort -u` to sort the list and prevent dupes from
53 # showing up.
3d1a81e @rtomayko pgem-list takes multiple glob patterns to match
authored
54 sort -u
Something went wrong with that request. Please try again.