dependency on stronny/nails :)
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
45e20f28a8
commit
1e757b7168
101
jspass
101
jspass
@ -1,15 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash-hammer
|
||||||
|
|
||||||
|
require /toolbox/system
|
||||||
|
require /args
|
||||||
|
|
||||||
|
# Alias some stuff
|
||||||
|
die() { Toolbox::System.die "$@"; }
|
||||||
|
err() { Toolbox::System.err "$@"; }
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
err() { printf '%s\n' "$*" >&2; }
|
|
||||||
die() {
|
|
||||||
[[ "$1" ]] || { exit 113; }
|
|
||||||
[[ "$2" ]] && err "$2"
|
|
||||||
exit "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
vault_is_json() { pass "$1" | jshon -Q &>/dev/null; }
|
vault_is_json() { pass "$1" | jshon -Q &>/dev/null; }
|
||||||
vault_exists() [[ -f "${opts[store]}/$1.gpg" ]]
|
vault_exists() [[ -f "${Opts[store]}/$1.gpg" ]]
|
||||||
|
|
||||||
check_argn() {
|
check_argn() {
|
||||||
# Check for the number of args the dumb way.
|
# Check for the number of args the dumb way.
|
||||||
@ -28,70 +28,63 @@ check_argn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Our options
|
# Our options
|
||||||
declare -A opts flags
|
declare -A Opts Flags
|
||||||
|
|
||||||
# Default opts
|
# Default Opts
|
||||||
opts[pw_len]=16
|
Opts[pw_len]=16
|
||||||
opts[login]='fbt@fleshless.org'
|
Opts[login]='fbt@fleshless.org'
|
||||||
opts[selection]="${X_SELECTION:-clipboard}"
|
Opts[selection]="${X_SELECTION:-clipboard}"
|
||||||
opts[store]="$HOME/.password-store"
|
Opts[store]="$HOME/.password-store"
|
||||||
opts[tmp_dir]='/tmp'
|
Opts[tmp_dir]='/tmp'
|
||||||
|
|
||||||
# Default flags
|
# Default flags
|
||||||
flags[clip]=0
|
Flags[clip]=0
|
||||||
|
Flags[edit]=0
|
||||||
|
|
||||||
# Show must go on
|
Args "$@" -- error argv \
|
||||||
while (( $# )); do
|
-l,p,"Opts[pw_len]" \
|
||||||
case $1 in
|
-u,p,"Opts[login]" \
|
||||||
# Options
|
-s,p,"Opts[selection]" \
|
||||||
(-l) opts[pw_len]=$2; shift;;
|
-c,f,"Flags[clip]" \
|
||||||
(-u) opts[login]=$2; shift;;
|
-e,f,"Flags[edit]" \
|
||||||
(-s) opts[selection]=$2; shift;;
|
|| { die 1 "$error"; }
|
||||||
|
|
||||||
# Flags
|
set -- "${argv[@]}"
|
||||||
(-c) flags[clip]=1;;
|
|
||||||
|
|
||||||
# Non-numeric flags
|
case "$1" in
|
||||||
(-n) opts[action]='new';;
|
(new|insert|show|add)
|
||||||
(-g) opts[action]='get';;
|
Opts[action]=$1
|
||||||
(-a) opts[action]='add';;
|
shift
|
||||||
(-e)
|
;;
|
||||||
if [[ "${opts[action]}" ]]; then
|
|
||||||
flags[edit]=1
|
|
||||||
else
|
|
||||||
opts[action]='edit'
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Misc
|
(cp|edit|git|grep|help|init|insert|ls|mv|rm) exec pass "$@";;
|
||||||
(--) shift; break;;
|
esac
|
||||||
(-*) die 13 "Unknown key: $1";;
|
|
||||||
(*) break;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
case "${opts[action]:-get}" in
|
case "${Opts[action]:-show}" in
|
||||||
(new) check_argn "${#@}" 1 1;
|
(new) check_argn "${#@}" 1 1;
|
||||||
vault="$1"
|
vault="$1"
|
||||||
|
|
||||||
# Check if the damn thing already exists
|
# Check if the damn thing already exists
|
||||||
vault_exists "$vault" && die 1 "Vault '$vault' already exists"
|
vault_exists "$vault" && die 1 "Vault '$vault' already exists"
|
||||||
|
|
||||||
new_pass=$(pwgen "${opts[pw_len]}" 1)
|
new_pass=$(pwgen "${Opts[pw_len]}" 1)
|
||||||
|
|
||||||
pass insert -m "$vault" < <(
|
pass insert -m "$vault" < <(
|
||||||
jshon -Q -n {} \
|
jshon -Q -n {} \
|
||||||
-s "$new_pass" -i "password" \
|
-s "$new_pass" -i "password" \
|
||||||
-s "${opts[login]}" -i "login"
|
-s "${Opts[login]}" -i "login"
|
||||||
)
|
)
|
||||||
|
|
||||||
(( "${flags[clip]}" )) && {
|
(( "${Flags[edit]}" )) && {
|
||||||
printf '%s' "$new_pass" | xclip -selection "${opts[selection]}"
|
pass edit "$vault"
|
||||||
|
}
|
||||||
|
|
||||||
|
(( "${Flags[clip]}" )) && {
|
||||||
|
printf '%s' "$new_pass" | xclip -selection "${Opts[selection]}"
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(get) check_argn "${#@}" 1 2;
|
(show) check_argn "${#@}" 1 2;
|
||||||
vault=$1
|
vault=$1
|
||||||
field=${2:-password}
|
field=${2:-password}
|
||||||
|
|
||||||
@ -105,8 +98,8 @@ case "${opts[action]:-get}" in
|
|||||||
pass=$(pass "$vault")
|
pass=$(pass "$vault")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( "${flags[clip]}" )); then
|
if (( "${Flags[clip]}" )); then
|
||||||
printf '%s' "$pass" | xclip -selection "${opts[selection]}"
|
printf '%s' "$pass" | xclip -selection "${Opts[selection]}"
|
||||||
else
|
else
|
||||||
printf '%s\n' "$pass"
|
printf '%s\n' "$pass"
|
||||||
fi
|
fi
|
||||||
@ -122,7 +115,5 @@ case "${opts[action]:-get}" in
|
|||||||
jshon -s "$data" -i "$field" <<< "$json" | pass insert -m "$vault"
|
jshon -s "$data" -i "$field" <<< "$json" | pass insert -m "$vault"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(edit) pass edit "$1";;
|
(*) pass "$action" "$@";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
(( "${flags[edit]}" )) && "$0" -e "$1"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user