diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-12-14 17:48:52 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-12-14 17:48:52 +1300 |
commit | 06f5ca98018fd4ba357b0e70b1e710b682b6cdb5 (patch) | |
tree | 76bc12131c82c87852e4183969d6969d9eeabf7f /bash/bashrc.d/man.bash | |
parent | Fix some English (diff) | |
download | dotfiles-06f5ca98018fd4ba357b0e70b1e710b682b6cdb5.tar.gz dotfiles-06f5ca98018fd4ba357b0e70b1e710b682b6cdb5.zip |
Switch to a faster method of array appending
Does away with the nasty hack around man page discovery, and still
compatible with Bash 2.05a
Diffstat (limited to 'bash/bashrc.d/man.bash')
-rw-r--r-- | bash/bashrc.d/man.bash | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/bash/bashrc.d/man.bash b/bash/bashrc.d/man.bash index d982a166..be3dc830 100644 --- a/bash/bashrc.d/man.bash +++ b/bash/bashrc.d/man.bash @@ -15,9 +15,11 @@ _man() { section='man'${COMP_WORDS[COMP_CWORD-1]} fi - # Read slash-separated output from a subshell into the COMPREPLY array; use - # read -a rather than adding each element individually, as it's much faster - IFS=/ read -a COMPREPLY -d '' -r < <( + # Read completion results from a subshell and add them to the COMPREPLY + # array individually + while IFS= read -d '' -r page ; do + COMPREPLY[${#COMPREPLY[@]}]=$page + done < <( # Do not return dotfiles, give us extended globbing, and expand empty # globs to just nothing @@ -33,7 +35,9 @@ _man() { # Iterate through the manual page paths and add every manual page we find for manpath in "${manpaths[@]}" ; do [[ $manpath ]] || continue - pages=("${pages[@]}" "$manpath"/"$section"*/"$word"*.[0-9]*) + for page in "$manpath"/"$section"*/"$word"*.[0-9]* ; do + pages[${#pages[@]}]=$page + done done # Strip paths, .gz suffixes, and finally .<section> suffixes @@ -45,8 +49,8 @@ _man() { # printing ((${#pages[@]})) || exit 1 - # Print the pages array to stdout, slash-separated, null-terminated - (IFS=/ ; printf '%q\0' "${pages[*]}") + # Print the pages array to stdout, quoted and null-delimited + printf '%q\0' "${pages[@]}" ) } complete -F _man -o default man |