Skip to content

Commit

Permalink
Bashcomp: improve performance
Browse files Browse the repository at this point in the history
Calling `cargo --list` on every completion is too slow.
Call it once on bash start and cache the output.
  • Loading branch information
gentoo90 committed Jul 26, 2015
1 parent cb4d3d8 commit 3f49c79
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ _cargo()

cmd=${words[1]}

local commands=$(cargo --list | tail -n +2)
local vcs='git hg none'

local opt_help='-h --help'
Expand Down Expand Up @@ -49,7 +48,7 @@ _cargo()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "${opt___nocmd}" -- "$cur" ) )
else
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) )
fi
elif [[ $cword -ge 2 ]]; then
case "${prev}" in
Expand All @@ -63,7 +62,7 @@ _cargo()
COMPREPLY=( $( compgen -W "$(_get_examples)" -- "$cur" ) )
;;
help)
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) )
;;
*)
local opt_var=opt__${cmd//-/_}
Expand All @@ -78,6 +77,8 @@ _cargo()
} &&
complete -F _cargo cargo

__cargo_commands=$(cargo --list | tail -n +2)

_locate_manifest(){
local manifest=`cargo locate-project 2>/dev/null`
# regexp-replace manifest '\{"root":"|"\}' ''
Expand Down

0 comments on commit 3f49c79

Please sign in to comment.