Browse Source

dependency on stronny/nails :)

Signed-off-by: fbt <fbt@fleshless.org>
master
Jack L. Frost 5 years ago
parent
commit
1e757b7168
1 changed files with 51 additions and 60 deletions
  1. +51
    -60
      jspass

+ 51
- 60
jspass View File

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

Loading…
Cancel
Save