make the program installable
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
*.bak
|
*.bak
|
||||||
*.pdf
|
*.pdf
|
||||||
last_invoice_number
|
last_invoice_number
|
||||||
|
*.csv
|
||||||
|
|||||||
18
Makefile
Normal file
18
Makefile
Normal file
@@ -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
|
||||||
|
|
||||||
23
gen.sh
23
gen.sh
@@ -1,16 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# What you charge an hour
|
DATA_HOME="$XDG_DATA_HOME/bill-generator"
|
||||||
export RATE=50
|
source "$XDG_CONFIG_HOME/bill-generator/ident"
|
||||||
export COMPANY_NAME="Cookies Unlimited, LLC"
|
# Need to be set to the installed location
|
||||||
export ADDR_LN_1="123 Sesasme St"
|
TEMPLATE_1COL="$DATA_HOME/1col.template.mm"
|
||||||
export ADDR_LN_2="Dumpster 1"
|
TEMPLATE_2COL="$DATA_HOME/2col.template.mm"
|
||||||
export ADDR_LN_3="12345, Nicevile, FL"
|
INV_FILE="$DATA_HOME/last_invoice_number"
|
||||||
export PHONE="(123) 456-7890"
|
|
||||||
export EMAIL="cookie@exapmle.com"
|
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
echo "$0 -1 <hrs.csv> <Paying Company Name> [output file]"
|
echo "$(basename $0) -1 <hrs.csv> <Paying Company Name> [output file]"
|
||||||
echo "$0 -2 <hrs.csv> <items.csv> <Paying Company Name> [output file]"
|
echo "$(basename $0) -2 <hrs.csv> <items.csv> <Paying Company Name> [output file]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "CSV files should be <name>,<value>."
|
echo "CSV files should be <name>,<value>."
|
||||||
echo "CSV files should have no empty line at the end."
|
echo "CSV files should have no empty line at the end."
|
||||||
@@ -19,7 +17,6 @@ print_help() {
|
|||||||
}
|
}
|
||||||
get_invoice_num() {
|
get_invoice_num() {
|
||||||
# Increment a global invoice number
|
# Increment a global invoice number
|
||||||
INV_FILE="last_invoice_number"
|
|
||||||
INV_NUM=0
|
INV_NUM=0
|
||||||
if [[ -f $INV_FILE ]]; then
|
if [[ -f $INV_FILE ]]; then
|
||||||
INV_NUM=$(expr $(cat $INV_FILE) + 1)
|
INV_NUM=$(expr $(cat $INV_FILE) + 1)
|
||||||
@@ -58,7 +55,7 @@ if [[ $1 = "-1" ]]; then
|
|||||||
OUTPUT=$4
|
OUTPUT=$4
|
||||||
fi
|
fi
|
||||||
export COMPANY=$3
|
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
|
elif [[ $1 = "-2" ]]; then
|
||||||
if [[ ! -z $5 ]]; then
|
if [[ ! -z $5 ]]; then
|
||||||
OUTPUT=$5
|
OUTPUT=$5
|
||||||
@@ -70,7 +67,7 @@ elif [[ $1 = "-2" ]]; then
|
|||||||
export ITEM_BODY=$(cat $CONSUME_TMP | head -n -1)
|
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 TOTAL=$(A=$HRS_COST B=$ITEM_TOTAL awk 'BEGIN{ print ENVIRON["A"] + ENVIRON["B"] }')
|
||||||
export COMPANY=$4
|
export COMPANY=$4
|
||||||
envsubst < 2col.template.mm | groff -t -mm -T pdf > $OUTPUT
|
envsubst < $TEMPLATE_2COL | groff -t -mm -T pdf > $OUTPUT
|
||||||
else
|
else
|
||||||
echo First arg should be either -1 or -2
|
echo First arg should be either -1 or -2
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user