perf(completion): optimize remote to use cache

This commit is contained in:
zawz 2022-02-18 17:25:32 +01:00
parent 1eb7a078aa
commit 804780df8b
3 changed files with 8 additions and 1 deletions

View file

@ -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/*

View file

@ -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

View file

@ -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" ;;