add file operation + fixes

This commit is contained in:
zawz 2021-04-06 14:56:16 +02:00
parent 5d51b6a00b
commit d437da40fe
5 changed files with 33 additions and 11 deletions

View file

@ -3,7 +3,7 @@ var_exclude = ZPASS_.* XDG_.* REMOTE_.* DISPLAY CONFIGFILE TMPDIR
fct_exclude = _tty_on
zpass: src/*
lxsh -o zpass -m --minimize-var --exclude-var "$(var_exclude)" --minimize-fct --exclude-fct "$(fct_exclude)" --remove-unused src/main.sh
lxsh -o zpass -m --minify-quotes --minify-var --exclude-var "$(var_exclude)" --minify-fct --exclude-fct "$(fct_exclude)" --remove-unused src/main.sh
debug: src/*
lxsh -o zpass src/main.sh

View file

@ -15,7 +15,8 @@ usage()
create Create a file or change key
get <path...> Get values of targets
copy <path> Copy the target value to clipboard. Shortcut 'x'
set <path> <value> Set the value of target
set <path> <value> Set directly the value of target
file <path> <file> Set the targetted value from file content
add <path...> Prompt for input value on paths
new <path...> Generate a random password at target
rm <path...> Delete targets

View file

@ -20,15 +20,16 @@ case $arg in
ch|cached) get_key_cached >/dev/null 2>&1 ;;
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;
c|create) create ;;
t|tree) _tree "$@" ;;
s|set) _set "$@" ;;
a|add) add "$@" ;;
n|new) new "$@" ;;
g|get) get "$@" ;;
x|copy) copy "$1" ;;
e|exec) archive_exec "$@" ;;
t|tree) sanitize_paths "$@" && _tree "$@" ;;
s|set) sanitize_paths "$1" && _set "$@" ;;
f|file) sanitize_paths "$1" && fileset "$@" ;;
a|add) sanitize_paths "$@" && add "$@" ;;
n|new) sanitize_paths "$@" && new "$@" ;;
g|get) sanitize_paths "$@" && get "$@" ;;
x|copy) sanitize_paths "$1" && copy "$1" ;;
l|ls|list) sanitize_paths "$@" && __NOPACK=y archive_exec ls -Apw1 -- "$@" ;;
r|rm) sanitize_paths "$@" && archive_exec rm -rf -- "$@" ;;
m|mv) sanitize_paths "$@" && archive_exec mv -f -- "$@" ;;
m|mv) sanitize_paths "$@" && move "$@" ;;
e|exec) archive_exec "$@" ;;
*) [ -n "$ZPASS_UNK_OP_CALL" ] && "$0" $ZPASS_UNK_OP_CALL "$arg" "$@" ;;
esac

View file

@ -73,3 +73,23 @@ add()
_set "$N" "$val" || return $?
done
}
fileset()
{
contents=$(cat "$2") || return $?
_set "$1" "$2"
}
move()
{
[ $# -lt 1 ] && return 1
archive_exec sh -c 'set -e
for last ; do true ; done
if [ "$#" -gt 2 ] ; then
mkdir -p "$last"
else
mkdir -p "$(dirname "$last")"
fi
mv -f -- "$@"
' sh "$@"
}

View file

@ -23,7 +23,7 @@ sanitize_paths()
for N
do
echo "$N" | grep -q "^/" && echo "Path cannot start with /" >&2 && return 1
echo "$N" | grep -qw ".." && echo "Path cannot contain .." >&2 && return 1
echo "$N" | grep -Fqw ".." && echo "Path cannot contain .." >&2 && return 1
done
return 0
}