add file operation + fixes
This commit is contained in:
parent
5d51b6a00b
commit
d437da40fe
5 changed files with 33 additions and 11 deletions
2
Makefile
2
Makefile
|
|
@ -3,7 +3,7 @@ var_exclude = ZPASS_.* XDG_.* REMOTE_.* DISPLAY CONFIGFILE TMPDIR
|
||||||
fct_exclude = _tty_on
|
fct_exclude = _tty_on
|
||||||
|
|
||||||
zpass: src/*
|
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/*
|
debug: src/*
|
||||||
lxsh -o zpass src/main.sh
|
lxsh -o zpass src/main.sh
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ usage()
|
||||||
create Create a file or change key
|
create Create a file or change key
|
||||||
get <path...> Get values of targets
|
get <path...> Get values of targets
|
||||||
copy <path> Copy the target value to clipboard. Shortcut 'x'
|
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
|
add <path...> Prompt for input value on paths
|
||||||
new <path...> Generate a random password at target
|
new <path...> Generate a random password at target
|
||||||
rm <path...> Delete targets
|
rm <path...> Delete targets
|
||||||
|
|
|
||||||
17
src/main.sh
17
src/main.sh
|
|
@ -20,15 +20,16 @@ case $arg in
|
||||||
ch|cached) get_key_cached >/dev/null 2>&1 ;;
|
ch|cached) get_key_cached >/dev/null 2>&1 ;;
|
||||||
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;
|
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;
|
||||||
c|create) create ;;
|
c|create) create ;;
|
||||||
t|tree) _tree "$@" ;;
|
t|tree) sanitize_paths "$@" && _tree "$@" ;;
|
||||||
s|set) _set "$@" ;;
|
s|set) sanitize_paths "$1" && _set "$@" ;;
|
||||||
a|add) add "$@" ;;
|
f|file) sanitize_paths "$1" && fileset "$@" ;;
|
||||||
n|new) new "$@" ;;
|
a|add) sanitize_paths "$@" && add "$@" ;;
|
||||||
g|get) get "$@" ;;
|
n|new) sanitize_paths "$@" && new "$@" ;;
|
||||||
x|copy) copy "$1" ;;
|
g|get) sanitize_paths "$@" && get "$@" ;;
|
||||||
e|exec) archive_exec "$@" ;;
|
x|copy) sanitize_paths "$1" && copy "$1" ;;
|
||||||
l|ls|list) sanitize_paths "$@" && __NOPACK=y archive_exec ls -Apw1 -- "$@" ;;
|
l|ls|list) sanitize_paths "$@" && __NOPACK=y archive_exec ls -Apw1 -- "$@" ;;
|
||||||
r|rm) sanitize_paths "$@" && archive_exec rm -rf -- "$@" ;;
|
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" "$@" ;;
|
*) [ -n "$ZPASS_UNK_OP_CALL" ] && "$0" $ZPASS_UNK_OP_CALL "$arg" "$@" ;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -73,3 +73,23 @@ add()
|
||||||
_set "$N" "$val" || return $?
|
_set "$N" "$val" || return $?
|
||||||
done
|
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 "$@"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ sanitize_paths()
|
||||||
for N
|
for N
|
||||||
do
|
do
|
||||||
echo "$N" | grep -q "^/" && echo "Path cannot start with /" >&2 && return 1
|
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
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue