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 <sveit...@gmail.com>
---
 src/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
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
+    set -l ext $argv[1]
+    set -l strip $argv[2]
+    set -l prefix (__fish_pass_get_prefix)
+    printf '%s\n' "$prefix"/**"$ext" | sed "s#$prefix/\(.*\)$strip#\1#"
+end
+
 function __fish_pass_print_entry_dirs
-    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
+    __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
--
2.16.1

_______________________________________________
Password-Store mailing list
Password-Store@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to