aboutsummaryrefslogtreecommitdiff
path: root/dbook
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-08-01 11:24:03 +0530
committersinanmohd <sinan@firemail.cc>2023-08-01 13:57:23 +0530
commit996a41ae087b8104e5218a456c58b1a0b72eed95 (patch)
treea2f1a5533788ace4882c395cc376057ae183a75d /dbook
parenteb685ec5d22a914cb4d46553fce16aea2ea95899 (diff)
dbook: cleanup, remove boilerplate in save and insert
Diffstat (limited to 'dbook')
-rwxr-xr-xdbook33
1 files changed, 15 insertions, 18 deletions
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"
;;