From 6a20f179af3047397a5c2d4728b6fd30aa9cf129 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 22 Jan 2026 21:17:24 -0700 Subject: [PATCH] make the program installable --- .gitignore | 1 + Makefile | 18 ++++++++++++++++++ gen.sh | 23 ++++++++++------------- ident | 8 ++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 Makefile create mode 100644 ident diff --git a/.gitignore b/.gitignore index 289730e..72e2f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.bak *.pdf last_invoice_number +*.csv diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d2f0cf0 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +support_files := ${XDG_DATA_HOME}/bill-generator/ +config_files:= ${XDG_CONFIG_HOME}/bill-generator/ +install_loc := ~/.local/bin/ +install: + mkdir -p $(support_files) + mkdir -p $(config_files) + mkdir -p $(install_loc) + cp *.mm $(support_files) + # Copy the ident file but don't overwrite one that is already there. + cp --update=none ident $(config_files) + cp gen.sh $(install_loc)/bill-gen + printf "\nInstalled!\nUpdate your identity at $(config_files)ident\n\n" + +remove: + # Remove everything except the config files + rm -r $(support_files) + rm $(install_loc)bill-gen + diff --git a/gen.sh b/gen.sh index dfcd918..40e69d0 100755 --- a/gen.sh +++ b/gen.sh @@ -1,16 +1,14 @@ #!/bin/bash -# What you charge an hour -export RATE=50 -export COMPANY_NAME="Cookies Unlimited, LLC" -export ADDR_LN_1="123 Sesasme St" -export ADDR_LN_2="Dumpster 1" -export ADDR_LN_3="12345, Nicevile, FL" -export PHONE="(123) 456-7890" -export EMAIL="cookie@exapmle.com" +DATA_HOME="$XDG_DATA_HOME/bill-generator" +source "$XDG_CONFIG_HOME/bill-generator/ident" +# Need to be set to the installed location +TEMPLATE_1COL="$DATA_HOME/1col.template.mm" +TEMPLATE_2COL="$DATA_HOME/2col.template.mm" +INV_FILE="$DATA_HOME/last_invoice_number" print_help() { - echo "$0 -1 [output file]" - echo "$0 -2 [output file]" + echo "$(basename $0) -1 [output file]" + echo "$(basename $0) -2 [output file]" echo "" echo "CSV files should be ,." echo "CSV files should have no empty line at the end." @@ -19,7 +17,6 @@ print_help() { } get_invoice_num() { # Increment a global invoice number - INV_FILE="last_invoice_number" INV_NUM=0 if [[ -f $INV_FILE ]]; then INV_NUM=$(expr $(cat $INV_FILE) + 1) @@ -58,7 +55,7 @@ if [[ $1 = "-1" ]]; then OUTPUT=$4 fi export COMPANY=$3 - envsubst < 1col.template.mm | groff -t -mm -T pdf > $OUTPUT + envsubst < $TEMPLATE_1COL | groff -t -mm -T pdf > $OUTPUT elif [[ $1 = "-2" ]]; then if [[ ! -z $5 ]]; then OUTPUT=$5 @@ -70,7 +67,7 @@ elif [[ $1 = "-2" ]]; then export ITEM_BODY=$(cat $CONSUME_TMP | head -n -1) export TOTAL=$(A=$HRS_COST B=$ITEM_TOTAL awk 'BEGIN{ print ENVIRON["A"] + ENVIRON["B"] }') export COMPANY=$4 - envsubst < 2col.template.mm | groff -t -mm -T pdf > $OUTPUT + envsubst < $TEMPLATE_2COL | groff -t -mm -T pdf > $OUTPUT else echo First arg should be either -1 or -2 fi diff --git a/ident b/ident new file mode 100644 index 0000000..7033ba4 --- /dev/null +++ b/ident @@ -0,0 +1,8 @@ +#!/bin/bash +export RATE=50 +export COMPANY_NAME="Cookies Unlimited, LLC" +export ADDR_LN_1="123 Sesasme St" +export ADDR_LN_2="Dumpster 1" +export ADDR_LN_3="12345, Nicevile, FL" +export PHONE="(123) 456-7890" +export EMAIL="cookie@exapmle.com"