From e50f4b62cb288fee437f5e4968e0b5a27c0ac439 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 8 Aug 2024 18:01:53 -0700 Subject: [PATCH 1/5] client: Dockerfiles: add timew package --- client/Dockerfiles/finance/Dockerfile.archlinux.in | 1 + client/Dockerfiles/finance/Dockerfile.ubuntu.in | 1 + 2 files changed, 2 insertions(+) diff --git a/client/Dockerfiles/finance/Dockerfile.archlinux.in b/client/Dockerfiles/finance/Dockerfile.archlinux.in index 1e93fe7..4dd04cd 100644 --- a/client/Dockerfiles/finance/Dockerfile.archlinux.in +++ b/client/Dockerfiles/finance/Dockerfile.archlinux.in @@ -43,6 +43,7 @@ RUN pacman -Syu \ hledger-ui \ hledger-web \ python-pipx \ + timew \ vim \ visidata \ xsv \ diff --git a/client/Dockerfiles/finance/Dockerfile.ubuntu.in b/client/Dockerfiles/finance/Dockerfile.ubuntu.in index 15d619c..e1bbede 100644 --- a/client/Dockerfiles/finance/Dockerfile.ubuntu.in +++ b/client/Dockerfiles/finance/Dockerfile.ubuntu.in @@ -49,6 +49,7 @@ RUN apt-get install -y \ hledger-ui \ hledger-web \ pipx \ + timewarrior \ vim \ visidata \ zlib1g-dev From 6da9b71030bb7751c254ad3cf4296e6e9fb49b75 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 8 Aug 2024 18:06:01 -0700 Subject: [PATCH 2/5] client: manifest: add timew package --- client/docker-finance.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/docker-finance.yaml b/client/docker-finance.yaml index 642dde4..e0c4497 100644 --- a/client/docker-finance.yaml +++ b/client/docker-finance.yaml @@ -38,12 +38,13 @@ container: packages: - "bc" - "git" + - "hledger" - "hledger-iadd" - "hledger-ui" - "hledger-web" - - "hledger" - "python-pipx" - "stack" + - "timew" - "vim" - "visidata" - "xsv" @@ -89,6 +90,7 @@ container: - "hledger-ui" - "hledger-web" - "pipx" + - "timewarrior" - "vim" - "visidata" - "zlib1g-dev" From 923a9eee248582e9cf0db589c3c4350e4d23ae6c Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 8 Aug 2024 18:25:03 -0700 Subject: [PATCH 3/5] client: lib_gen: generate 'times' - Sets a location for: * timew database * Anything time-related (among all profiles) --- client/src/docker/lib/internal/lib_gen.bash | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/src/docker/lib/internal/lib_gen.bash b/client/src/docker/lib/internal/lib_gen.bash index cbb07c5..0c849c3 100644 --- a/client/src/docker/lib/internal/lib_gen.bash +++ b/client/src/docker/lib/internal/lib_gen.bash @@ -436,10 +436,31 @@ function lib_gen::__gen_container() mkdir -p "$DOCKER_FINANCE_CLIENT_FLOW" || lib_utils::die_fatal fi + lib_gen::__gen_times lib_gen::__gen_plugins lib_gen::__gen_profile } +# +# Generate flow: times +# +# - Provides a place for: +# * timew database +# * Anything time-related (among all profiles) +# + +function lib_gen::__gen_times() +{ + lib_utils::print_debug "Generating times" + + local -r _times="${DOCKER_FINANCE_CLIENT_FLOW}/times" + if [ ! -d "$_times" ]; then + mkdir -p "$_times" || lib_utils::die_fatal + fi + + # NOTE: timew database will be created upon first call +} + # # Generate flow: plugins # From 5eac855acf8e12b5af253159b2526d0dd691cc05 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 8 Aug 2024 18:43:34 -0700 Subject: [PATCH 4/5] container: bash: add `times` / lib_times --- container/src/finance/finance.bash | 4 + .../src/finance/lib/internal/lib_times.bash | 116 ++++++++++++++++++ container/src/finance/lib/lib_finance.bash | 7 ++ 3 files changed, 127 insertions(+) create mode 100644 container/src/finance/lib/internal/lib_times.bash diff --git a/container/src/finance/finance.bash b/container/src/finance/finance.bash index 324a413..9be6215 100755 --- a/container/src/finance/finance.bash +++ b/container/src/finance/finance.bash @@ -62,6 +62,7 @@ function main() reports \e[34;3mGenerate balance sheet, income statement, etc.\e[0m root \e[34;3mRun ROOT.cern instance for docker-finance analysis\e[0m taxes \e[34;3mGenerate tax reports\e[0m + times \e[34;3mAccount for time\e[0m \e[32mOptional:\e[0m @@ -135,6 +136,9 @@ function main() taxes) lib_finance::taxes "${@:3}" ;; + time | times) + lib_finance::times "${@:3}" + ;; *) lib_utils::die_usage "$_usage" ;; diff --git a/container/src/finance/lib/internal/lib_times.bash b/container/src/finance/lib/internal/lib_times.bash new file mode 100644 index 0000000..a78bb3e --- /dev/null +++ b/container/src/finance/lib/internal/lib_times.bash @@ -0,0 +1,116 @@ +#!/usr/bin/env bash + +# docker-finance | modern accounting for the power-user +# +# Copyright (C) 2024 Aaron Fiore (Founder, Evergreen Crypto LLC) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation either version 3 of the License or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not see . + +# +# "Libraries" +# + +[ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && exit 1 +source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_utils.bash" || exit 1 + +# +# Facade +# + +function lib_times::times() +{ + lib_times::__parse_args "$@" + lib_times::__times "$@" + lib_utils::catch $? +} + +# +# Implementation +# + +function lib_times::__parse_args() +{ + [ -z "$global_usage" ] && lib_utils::die_fatal + [ -z "$global_arg_delim_1" ] && lib_utils::die_fatal + [ -z "$global_child_profile" ] && lib_utils::die_fatal + [ -z "$global_parent_profile" ] && lib_utils::die_fatal + + local -r _usage=" +\e[32mDescription:\e[0m + + Keep track of time on a per-subprofile basis + +\e[32mUsage:\e[0m + + $ $global_usage [args] + +\e[32mExamples:\e[0m + + \e[37;2m# Start the timer for '${global_parent_profile}${global_arg_delim_1}${global_child_profile}' with description 'Task 1' of type 'consulting' and comment 'My long comment'\e[0m + $ $global_usage start desc='Task 1' comment='My long comment' tag:type=consulting + + \e[37;2m# Stop the timer for '${global_parent_profile}${global_arg_delim_1}${global_child_profile}'\e[0m + $ $global_usage stop + + \e[37;2m# Print summary for '${global_parent_profile}${global_arg_delim_1}${global_child_profile}' of all times related to tag:type=consulting\e[0m + $ $global_usage summary tag:type=consulting + + \e[37;2m# Export all times and all tags for '${global_parent_profile}${global_arg_delim_1}${global_child_profile}'\e[0m + $ $global_usage export + + \e[37;2m# List all available commands\e[0m + $ $global_usage help +" + + if [ "$#" -eq 0 ]; then + lib_utils::die_usage "$_usage" + fi +} + +function lib_times::__times() +{ + [ -z "$DOCKER_FINANCE_CONTAINER_FLOW" ] && lib_utils::die_fatal + + # NOTE: + # - Currently a wrapper to `timew` + # + # - Automatically tags profile/subprofile + # * keeps time organized on a per-subprofile basis + # + # - All time-related data is stored in '${_path}' + # * `timew` database is stored in '${_timewdb}' + + local -r _path="${DOCKER_FINANCE_CONTAINER_FLOW}/times" + local -r _timewdb="${_path}/timew" + + local _command=("timew") + local -r _tag="${global_parent_profile}${global_arg_delim_1}${global_child_profile}" + + case "$1" in + help) + _command+=("$@") + ;; + *) + _command+=("$@") + _command+=("profile=${_tag}") + ;; + esac + + lib_utils::print_debug "TIMEWARRIORDB=${_timewdb}" + TIMEWARRIORDB="${_timewdb}" "${_command[@]}" + + return $? +} + +# vim: sw=2 sts=2 si ai et diff --git a/container/src/finance/lib/lib_finance.bash b/container/src/finance/lib/lib_finance.bash index 3ffb83a..3e0386b 100644 --- a/container/src/finance/lib/lib_finance.bash +++ b/container/src/finance/lib/lib_finance.bash @@ -90,6 +90,7 @@ function lib_finance::finance() source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_plugins.bash" || exit 1 source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_reports.bash" || exit 1 source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_taxes.bash" || exit 1 + source "${DOCKER_FINANCE_CONTAINER_REPO}/src/finance/lib/internal/lib_times.bash" || exit 1 } # @@ -226,6 +227,12 @@ function lib_finance::taxes() lib_utils::catch $? } +function lib_finance::times() +{ + lib_times::times "$@" + lib_utils::catch $? +} + function lib_finance::edit() { lib_edit::edit "$@" From 5ef5d24f3b66e47cffd57b80642bdff5dffc73a3 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 8 Aug 2024 19:24:18 -0700 Subject: [PATCH 5/5] container: bash: completion: add `times` --- container/src/finance/completion.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/container/src/finance/completion.bash b/container/src/finance/completion.bash index 34d1106..6c7bc16 100644 --- a/container/src/finance/completion.bash +++ b/container/src/finance/completion.bash @@ -28,7 +28,7 @@ function docker-finance::completion() mapfile -t _profiles < <(pushd "${DOCKER_FINANCE_CONTAINER_FLOW}"/profiles &>/dev/null && ls -d */*) declare -r _profiles - local -r _commands=("all" "edit" "fetch" "import" "ledger" "ledger-ui" "ledger-web" "meta" "plugins" "reports" "root" "taxes") + local -r _commands=("all" "edit" "fetch" "import" "ledger" "ledger-ui" "ledger-web" "meta" "plugins" "reports" "root" "taxes" "times") local _reply @@ -91,6 +91,9 @@ function docker-finance::completion() taxes) mapfile -t _reply < <(compgen -W "help all${global_arg_delim_2} tag${global_arg_delim_2} account${global_arg_delim_2} year${global_arg_delim_2} write${global_arg_delim_2}" -- "$_cur") ;; + times) + mapfile -t _reply < <(compgen -W "help" -- "$_cur") + ;; esac declare -r _reply COMPREPLY=("${_reply[@]}")