commit 121f5a4511651db403540fb9779a7541d76583ce Author: Justin Lin Date: Fri Jul 25 00:49:33 2025 +1000 template with sh func diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6490ed9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/lancatlin/mdsh-go + +go 1.24.5 diff --git a/main.go b/main.go new file mode 100644 index 0000000..abe8be3 --- /dev/null +++ b/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" + "text/template" +) + +var tmpl = ` +Hello this is the text: +{{ sh "hledger bal assets" }} +` + +func sh(command string) string { + args := strings.Split(command, " ") + out, err := exec.Command(args[0], args[1:]...).Output() + if err != nil { + return fmt.Sprintf("> Failed to execute the command:\n> %s\n", err.Error()) + } + return fmt.Sprintf("\n```\n%s\n```\n", string(out)) +} + +func main() { + funcMap := template.FuncMap{ + "sh": sh, + } + t, err := template.New("foo").Funcs(funcMap).Parse(tmpl) + if err != nil { + panic(err) + } + t.Execute(os.Stdout, "hledger is awesome") +} diff --git a/monthly.md b/monthly.md new file mode 100644 index 0000000..1b926b4 --- /dev/null +++ b/monthly.md @@ -0,0 +1,32 @@ +--- +name: "reports/${from}.md" +params: + from: + required: true + to: + required: true + file: + default: ~/.hledger.journal +--- + +# Finance Report from {from} to {to} + +## Previous status: + +{{hledger -f $file balancesheet -e $from }} + +## Expenses: + +### Expense Summary by Category + +{{hledger -f $file bal expenses -b $from -e $to --depth 3 --sort amount}} + +{{hledger -f $file bal expenses -b $from -e $to --depth 2 --sort amount}} + +## Net Income: + +{{hledger -f $file income -b $from -e $to --monthly}} + +## Ending balance: + +{{hledger -f $file balancesheet -e $to}}