Fix zsh auto-completion
The bash and zsh scripts expect different data from Racket: zsh expects a list of collect roots and other parent directories of collections, while bash expects a list of collection names
This commit is contained in:
parent
7b172ac6d7
commit
f175490639
|
@ -1,15 +1,18 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require racket/string setup/dirs setup/link)
|
|
||||||
|
(provide get-top-level-collection-paths)
|
||||||
|
|
||||||
|
(require racket/string racket/list racket/path setup/dirs setup/link)
|
||||||
|
|
||||||
(define (add-directory-collections c s)
|
(define (add-directory-collections c s)
|
||||||
(if (directory-exists? c)
|
(if (directory-exists? c)
|
||||||
(for/fold ([s s]) ([p (in-list (directory-list c))]
|
(for/fold ([s s]) ([p (in-list (directory-list c))]
|
||||||
#:when (directory-exists? (build-path c p))
|
#:when (directory-exists? (build-path c p))
|
||||||
#:when (regexp-match? #rx#"^[a-zA-Z_%+-]*$" p))
|
#:when (regexp-match? #rx#"^[a-zA-Z_%+-]*$" p))
|
||||||
(hash-set s (path-element->string p) #t))
|
(hash-set s (build-path c (path-element->string p)) #t))
|
||||||
s))
|
s))
|
||||||
|
|
||||||
(define (get-all-top-level-collections)
|
(define (get-top-level-collection-paths)
|
||||||
(hash-keys
|
(hash-keys
|
||||||
(for/fold ([s (hash)]) ([l (in-list
|
(for/fold ([s (hash)]) ([l (in-list
|
||||||
(current-library-collection-links))])
|
(current-library-collection-links))])
|
||||||
|
@ -19,12 +22,23 @@
|
||||||
(current-library-collection-paths))])
|
(current-library-collection-paths))])
|
||||||
(add-directory-collections c s))]
|
(add-directory-collections c s))]
|
||||||
[(path? l)
|
[(path? l)
|
||||||
(let ([s (for*/fold ([s s]) ([c (in-list (links #:file l #:root? #f))])
|
(let ([s (for*/fold ([s s]) ([c (in-list (links #:file l #:root? #f #:with-path? #t))])
|
||||||
(hash-set s c #t))])
|
(hash-set s (cdr c) #t))])
|
||||||
(for*/fold ([s s]) ([c (in-list (links #:file l #:root? #t))])
|
(for*/fold ([s s]) ([c (in-list (links #:file l #:root? #t))])
|
||||||
(add-directory-collections c s)))]
|
(add-directory-collections c s)))]
|
||||||
[else (error 'get-all-top-level-collections
|
[else (error 'get-top-level-collection-paths
|
||||||
"unexpected value in `current-library-collection-links': ~e"
|
"unexpected value in `current-library-collection-links': ~e"
|
||||||
l)]))))
|
l)]))))
|
||||||
|
|
||||||
(for-each displayln (get-all-top-level-collections))
|
(module+ main
|
||||||
|
(define var "RACKET_COMPLETION_CLIENT")
|
||||||
|
(define shell (getenv var))
|
||||||
|
(cond [(equal? shell "bash")
|
||||||
|
(for ([p (get-top-level-collection-paths)])
|
||||||
|
(define-values [base name dir?] (split-path p))
|
||||||
|
(displayln name))]
|
||||||
|
[(equal? shell "zsh")
|
||||||
|
(for-each displayln
|
||||||
|
(remove-duplicates
|
||||||
|
(map path-only (get-top-level-collection-paths))))]
|
||||||
|
[else (error 'list-collects "unknown shell (missing ~a envvar)" var)]))
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
# will need to make sure that you have bash completions enabled, usually
|
# will need to make sure that you have bash completions enabled, usually
|
||||||
# with "source /etc/bash_completion".
|
# with "source /etc/bash_completion".
|
||||||
|
|
||||||
|
# Identify bash as the completion client
|
||||||
|
export RACKET_COMPLETION_CLIENT=bash
|
||||||
|
|
||||||
# This completes only *.{rkt,ss,scm,scrbl} files unless there are none,
|
# This completes only *.{rkt,ss,scm,scrbl} files unless there are none,
|
||||||
# in which case it completes other things.
|
# in which case it completes other things.
|
||||||
_racket_filedir() {
|
_racket_filedir() {
|
||||||
|
@ -116,7 +119,7 @@ _complete_collects() {
|
||||||
local cur="$1"
|
local cur="$1"
|
||||||
if [[ "${#_racket_collects[@]}" -eq 0 ]]; then
|
if [[ "${#_racket_collects[@]}" -eq 0 ]]; then
|
||||||
_racket_collects=(
|
_racket_collects=(
|
||||||
$( $_racket_cmd -e '(require shell-completion/list-collects)' )
|
$( $_racket_cmd -e '(require (submod shell-completion/list-collects main))' )
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
local wordlist=""
|
local wordlist=""
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
# the function since it's loaded on first use.)
|
# the function since it's loaded on first use.)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Identify zsh as the completion client
|
||||||
|
export RACKET_COMPLETION_CLIENT=zsh
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
_racket_file_expander() {
|
_racket_file_expander() {
|
||||||
|
@ -60,8 +63,7 @@ _racket_call() {
|
||||||
_racket_read_libfile_or_collect() {
|
_racket_read_libfile_or_collect() {
|
||||||
local -a dirs
|
local -a dirs
|
||||||
dirs=(
|
dirs=(
|
||||||
"${(f)$(_racket_call directories '
|
"${(f)$(_racket_call directories '(require (submod shell-completion/list-collects main))')}"
|
||||||
(for-each displayln (current-library-collection-paths))')}"
|
|
||||||
)
|
)
|
||||||
local -a ignored
|
local -a ignored
|
||||||
ignored=('*.dep' '*.zo' 'compiled' '*/compiled')
|
ignored=('*.dep' '*.zo' 'compiled' '*/compiled')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user