[racket-dev] Bash Completion Broken?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jul 9 12:52:18 EDT 2013

At Tue, 09 Jul 2013 12:23:56 -0400, Vincent St-Amour wrote:
> Bash completion for raco setup (in
> pkgs/plt-services/meta/contrib/completion/racket-completion.bash)
> is currently broken. It only completes collects that are in the core.
> I haven't tried it, but I suspect that zsh completion is similarly
> broken.
> To find collects to complete, the script looks for subdirectories of the
> directories listed in `current-library-collection-paths'. On my current
> install, these directories are:
>     /home/stamourv/src/plt/add-on/5.3.900.5/collects
>     /home/stamourv/src/plt/racket/lib/collects
> which doesn't include package-installed collects. The first directory
> also doesn't exist.
> Is this a bug in `current-library-collection-paths', or should the
> completion script use something else now?

The completion script will need to check links, too. (That was
technically true before, but you didn't have enough links for it to

The example below shows how to get all top-level collection names, but
I'm not sure that's what you want. 

To get the directories for links, use the `#:with-path?' argument to
`links', but you'll also have to sort out what to do with root links
versus single-collection links.


#lang racket/base
(require setup/dirs

(define (add-directory-collections c s)
  (if (directory-exists? c)
      (for/fold ([s s]) ([p (in-list (directory-list c))]
                         #:when (directory-exists? (build-path c p))
                         #:when (regexp-match? #rx#"^[a-zA-Z_%+-]*$" p))
        (hash-set s (path-element->string p) #t))

(define (links* m root?)
  (case m
    [(user) (links #:user? #t #:root? root?)]
    [(shared) (links #:shared? #t #:root? root?)]
    [else (links #:file m #:root? root?)]))

(define (get-all-top-level-collections)
  (define link-modes (list* 'user 'shared (get-links-search-files)))

  (let* ([s (hash)]
         [s (for/fold ([s s]) ([c (in-list
              (add-directory-collections c s))]
         [s (for*/fold ([s s]) ([m (in-list link-modes)]
                                [l (in-list (links* m #f))])
              (hash-set s l #t))]
         [s (for*/fold ([s s]) ([m (in-list link-modes)]
                                [c (in-list (links* m #t))])
              (add-directory-collections c s))])
    (hash-keys s)))


Posted on the dev mailing list.