diff options
author | Mathis Antony <sveitser@gmail.com> | 2018-02-19 23:01:31 +0800 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-19 16:06:47 +0100 |
commit | fab65bda88ea979dbbc49f3d856a1d14ee4f1296 (patch) | |
tree | 293f655f87f6e863c92b85bf41c08ddd7fecf3b7 /src/completion | |
parent | ffef92ee0ed10551b20521f2d6e5637c8f9da798 (diff) |
fish: reduce completion runtimes
Fish completion spends most of the time in calls to `sed` in for loops over
entries and directories. This patch removes the repeated calls to `sed`.
Signed-off-by: Mathis Antony <sveitser@gmail.com>
Diffstat (limited to 'src/completion')
-rw-r--r-- | src/completion/pass.fish-completion | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/completion/pass.fish-completion b/src/completion/pass.fish-completion index c32a42c..8637874 100644 --- a/src/completion/pass.fish-completion +++ b/src/completion/pass.fish-completion @@ -20,6 +20,7 @@ function __fish_pass_needs_command end return 1 end + function __fish_pass_uses_command set cmd (commandline -opc) if [ (count $cmd) -gt 1 ] @@ -33,24 +34,22 @@ end function __fish_pass_print_gpg_keys gpg2 --list-keys | grep uid | sed 's/.*<\(.*\)>/\1/' end -function __fish_pass_print_entry_dirs + +function __fish_pass_print + set -l ext $argv[1] + set -l strip $argv[2] set -l prefix (__fish_pass_get_prefix) - set -l dirs - eval "set dirs "$prefix"/**/" - for dir in $dirs - set entry (echo "$dir" | sed "s#$prefix/\(.*\)#\1#") - echo "$entry" - end + printf '%s\n' "$prefix"/**"$ext" | sed "s#$prefix/\(.*\)$strip#\1#" end + +function __fish_pass_print_entry_dirs + __fish_pass_print "/" +end + function __fish_pass_print_entries - set -l prefix (__fish_pass_get_prefix) - set -l files - eval "set files "$prefix"/**.gpg" - for file in $files - set file (echo "$file" | sed "s#$prefix/\(.*\)\.gpg#\1#") - echo "$file" - end + __fish_pass_print ".gpg" ".gpg" end + function __fish_pass_print_entries_and_dirs __fish_pass_print_entry_dirs __fish_pass_print_entries |