From 804780df8b6ac3bfb45307aa400b731c585b4ea7 Mon Sep 17 00:00:00 2001 From: zawz Date: Fri, 18 Feb 2022 17:25:32 +0100 Subject: [PATCH] perf(completion): optimize remote to use cache --- Makefile | 2 +- completion/zpass.bash | 2 ++ src/remote.sh | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 82dd758..5b05aa4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -var_exclude = ZPASS_.* XDG_.* REMOTE_.* DISPLAY CONFIGFILE TMPDIR DEBUG +var_exclude = _ZPASS_.* ZPASS_.* XDG_.* REMOTE_.* DISPLAY CONFIGFILE TMPDIR DEBUG fct_exclude = _stop sftp_cmd ftps_cmd upload download list delete create zpass: src/* diff --git a/completion/zpass.bash b/completion/zpass.bash index abe76f6..3cc2a72 100644 --- a/completion/zpass.bash +++ b/completion/zpass.bash @@ -29,6 +29,8 @@ _zpass_completion() local cur=$2 COMPREPLY=() + export _ZPASS_USE_CACHE=true + if { [ "$COMP_CWORD" -eq "2" ] && echo "$_cw1_val1" | grep -qw -- "${COMP_WORDS[1]}" ; } || { [ "$COMP_CWORD" -gt "1" ] && echo "$_cw1_val_all" | grep -qw -- "${COMP_WORDS[1]}"; } ; then diff --git a/src/remote.sh b/src/remote.sh index 6de48a1..8f5cd07 100644 --- a/src/remote.sh +++ b/src/remote.sh @@ -47,6 +47,11 @@ EOF # $1 = protocol, $2 = remote file , $3 = local file download() { + if [ "$_ZPASS_USE_CACHE" = true ] && [ -f "$(get_filecache)" ] ; then + cp "$(get_filecache)" "$3" + return $? + fi + case $1 in scp) scp_cmd "${remote_user+${remote_user}@}$remote_host:$2" "$3" ;; webdav) webdav_cmd "$2" > "$3" ;;