aboutsummaryrefslogtreecommitdiff
path: root/quickLedger.sh
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2022-09-22 13:53:30 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2022-09-22 13:53:30 +0200
commitd455768923f94c63f005a8c7046d431c7f8a99d5 (patch)
tree7a8739887ceb348bce441b7a0df27ca02c6c199d /quickLedger.sh
parent4eb1e2255765e02bc1eeaef5bbfaa1b567c9665c (diff)
downloadscripts-d455768923f94c63f005a8c7046d431c7f8a99d5.tar.gz
scripts-d455768923f94c63f005a8c7046d431c7f8a99d5.zip
quickLedger.sh now allows new info and not just select existing info.
Diffstat (limited to 'quickLedger.sh')
-rwxr-xr-xquickLedger.sh38
1 files changed, 25 insertions, 13 deletions
diff --git a/quickLedger.sh b/quickLedger.sh
index 88f410f..b0b9879 100755
--- a/quickLedger.sh
+++ b/quickLedger.sh
@@ -14,7 +14,7 @@ debug=''
# $1: message
# $2: exit code
fatalError() {
- printf "Error: $1" 1>&2
+ printf 'Error: %s' "$1" 1>&2
exit "$2"
}
@@ -23,22 +23,33 @@ organizeLines() {
}
getPayee() {
- grep '^\w' "$ledgerFile" | cut -d' ' -f2- | organizeLines | fzf --prompt 'Payee: '
+ grep '^\w' "$ledgerFile" |
+ cut -d' ' -f2- |
+ organizeLines |
+ fzf --prompt 'Payee: ' --print-query --height 10 |
+ tail -1
}
# $1: fzf prompt
getAccount() {
- grep '^\s' "$ledgerFile" | awk '{print $1}' | organizeLines | fzf --prompt "$1" --no-clear
+ grep '^\s' "$ledgerFile" |
+ awk '{print $1}' |
+ organizeLines |
+ fzf --prompt "$1" --print-query --height 10 |
+ tail -1
}
getComment() {
- grep -o ';.*$' "$ledgerFile" | organizeLines | fzf --prompt "Comment: "
+ grep -o ';.*$' "$ledgerFile" |
+ organizeLines |
+ fzf --prompt "Comment: " --print-query --height 10 |
+ tail -1
}
getAmount() {
- read amount
+ read -r amount
while ! echo "$amount" | grep -Eq '[0-9]+(\.[0-9][0-9])?'; do
- read amount
+ read -r amount
done
echo "$amount" | grep -Fq '.' || amount="${amount}.00"
amount="${amount}${currencySymbol}"
@@ -66,27 +77,28 @@ while getopts ':tf:r:c:' opt; do
currencySymbol="$OPTARG" ;;
'?' )
- printf "${usageMessage}\n"
+ printf '%s\n' "$usageMessage"
exit 1
esac
done
-shift $(($OPTIND - 1))
+shift $((OPTIND - 1))
[ -z "$ledgerFile" ] &&
- fatalError 'No ledger file. Set ledger file as $LEDGER_FILE or with -f option.\n' 2
+ fatalError 'No ledger file. Set ledger file as LEDGER_FILE variable or with -f option.\n' 2
[ ! -f "$ledgerFile" ] && fatalError "No file [${ledgerFile}] found to use as ledger.\n" 3
targetAccount="$(getAccount 'Target account: ')"
-[ -z "$targetAccount" ] && tput rmcup && exit 0
+[ -z "$targetAccount" ] && exit 0
originAccount="$(getAccount 'Origin account: ')"
-[ -z "$originAccount" ] && tput rmcup && exit 0
+[ -z "$originAccount" ] && exit 0
payee="$(getPayee)"
printf 'Amount: '
amount="$(getAmount)"
[ -z "$amount" ] && exit 0
+printf '\n'
comment="$(getComment)"
@@ -95,11 +107,11 @@ date="$(date '+%Y/%m/%d')"
getTransaction
printf 'Correct? [Yn]: '
-read correct
+read -r correct
[ "$correct" = "n" ] && exit 0
[ -n "$debug" ] && exit 0
-echo >> "$ledgerFile"
+printf '\n' >> "$ledgerFile"
getTransaction >> "$ledgerFile"
rsync -t "$ledgerFile" "$remoteLedgerFile" || fatalError 'rsync failed.' 4