diff options
author | sinanmohd <sinan@firemail.cc> | 2023-08-01 11:24:03 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-08-01 13:57:23 +0530 |
commit | 996a41ae087b8104e5218a456c58b1a0b72eed95 (patch) | |
tree | a2f1a5533788ace4882c395cc376057ae183a75d /dbook | |
parent | eb685ec5d22a914cb4d46553fce16aea2ea95899 (diff) |
dbook: cleanup, remove boilerplate in save and insert
Diffstat (limited to 'dbook')
-rwxr-xr-x | dbook | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -236,30 +236,27 @@ case "$1" in esac case "$command" in -insert) +insert|save) value="${1:-$(ip_menu "value")}" || exit 1 key="${2:-$(ip_menu "key")}" || exit 1 parse_data getval "$key" > /dev/null && die "key already in use" - [ -e "$value" ] && - value="$(realpath "$value")" - printf "%s\t|\t%s\n" "$key" "$value" >> "$book_conf" - ;; -save) - value="${1:-$(ip_menu "value")}" || exit 1 - key="${2:-$(ip_menu "key")}" || exit 1 - - parse_data getval "$key" > /dev/null && - die "key already in use" - [ -d "$value" ] && - warn "${value} is a directory, will not be saved" - - if [ -f "$value" ]; then - cp "$value" "$book_data" - value="${book_data}/$(basename "$value")" - fi + case "$command" in + insert) + [ -e "$value" ] && + value="$(realpath "$value")" + ;; + save) + [ -d "$value" ] && + warn "${value} is a directory, will not be saved" + if [ -f "$value" ]; then + cp "$value" "$book_data" + value="${book_data}/$(basename "$value")" + fi + ;; + esac printf "%s\t|\t%s\n" "$key" "$value" >> "$book_conf" ;; |