password-store

Simple password manager using gpg and ordinary unix directories
git clone https://git.zx2c4.com/password-store
Log | Files | Refs | README | LICENSE

commit fab65bda88ea979dbbc49f3d856a1d14ee4f1296
parent ffef92ee0ed10551b20521f2d6e5637c8f9da798
Author: Mathis Antony <sveitser@gmail.com>
Date:   Mon, 19 Feb 2018 23:01:31 +0800

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:
Msrc/completion/pass.fish-completion | 27+++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git 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