From 996a41ae087b8104e5218a456c58b1a0b72eed95 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Tue, 1 Aug 2023 11:24:03 +0530 Subject: dbook: cleanup, remove boilerplate in save and insert --- dbook | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'dbook') diff --git a/dbook b/dbook index 5cc604b..dc71f1d 100755 --- a/dbook +++ b/dbook @@ -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" ;; -- cgit v1.2.3