mirror of
https://github.com/kmein/niveum
synced 2026-03-18 19:11:08 +01:00
feat(hledger): hora standalone
This commit is contained in:
@@ -1,33 +1,15 @@
|
|||||||
{
|
{
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
ledgerDirectory = "$HOME/projects/ledger";
|
ledgerDirectory = "/home/kfm/projects/ledger";
|
||||||
timeLedger = "${ledgerDirectory}/time.timeclock";
|
hora = pkgs.callPackage ../packages/hora.nix { timeLedger = "${ledgerDirectory}/time.timeclock"; };
|
||||||
hora = pkgs.writers.writeDashBin "hora" ''
|
|
||||||
${pkgs.hledger}/bin/hledger -f "${timeLedger}" "$@"
|
|
||||||
'';
|
|
||||||
in {
|
in {
|
||||||
environment.systemPackages = let
|
environment.systemPackages = let
|
||||||
git = "${pkgs.git}/bin/git -C ${ledgerDirectory}";
|
git = "${pkgs.git}/bin/git -C ${ledgerDirectory}";
|
||||||
in [
|
in [
|
||||||
pkgs.hledger
|
|
||||||
(pkgs.writers.writeDashBin "hora-edit" ''
|
|
||||||
$EDITOR + "${timeLedger}" && ${pkgs.git}/bin/git -C "$(${pkgs.coreutils}/bin/dirname ${timeLedger})" commit --all --message "$(${pkgs.coreutils}/bin/date -Im)"
|
|
||||||
'')
|
|
||||||
hora
|
hora
|
||||||
(pkgs.writers.writeDashBin "hora-year" ''
|
pkgs.hledger
|
||||||
${hora}/bin/hora bal --tree --monthly --begin $(date +%Y) --depth 1
|
|
||||||
'')
|
|
||||||
(pkgs.writers.writeDashBin "hora-filli" ''
|
|
||||||
${pkgs.hledger}/bin/hledger -f "${timeLedger}" register fillidefilla -O csv \
|
|
||||||
-b "$(date -d "$(date +%Y-%m)-01 last month" +%Y-%m-%d)" \
|
|
||||||
-e "$(date -d "$(date +%Y-%m)-01" +%Y-%m-%d)" \
|
|
||||||
| sed 's/(fillidefilla:\(.*\))/\1/g' \
|
|
||||||
| xsv select date,amount,total,account,description
|
|
||||||
'')
|
|
||||||
|
|
||||||
(pkgs.writers.writeDashBin "hledger-git" ''
|
(pkgs.writers.writeDashBin "hledger-git" ''
|
||||||
if [ "$1" = entry ]; then
|
if [ "$1" = entry ]; then
|
||||||
${pkgs.hledger}/bin/hledger balance -V > "${ledgerDirectory}/balance.txt"
|
${pkgs.hledger}/bin/hledger balance -V > "${ledgerDirectory}/balance.txt"
|
||||||
|
|||||||
80
packages/hora.nix
Normal file
80
packages/hora.nix
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
{ symlinkJoin
|
||||||
|
, hledger
|
||||||
|
, writers
|
||||||
|
, lib
|
||||||
|
, git
|
||||||
|
, coreutils
|
||||||
|
, gnugrep
|
||||||
|
, timeLedger
|
||||||
|
, ...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
date = "${coreutils}/bin/date +'%Y-%m-%d %H:%M:%S'";
|
||||||
|
|
||||||
|
hora = writers.writeDashBin "hora" "${hledger}/bin/hledger -f ${lib.escapeShellArg timeLedger} \"$@\"";
|
||||||
|
hora-edit = writers.writeDashBin "hora-edit" "$EDITOR ${lib.escapeShellArg timeLedger}";
|
||||||
|
hora-status = writers.writeDashBin "hora-status" "${coreutils}/bin/tac ${lib.escapeShellArg timeLedger} | ${gnugrep}/bin/grep -m 1 .";
|
||||||
|
|
||||||
|
hora-start = writers.writeDashBin "hora-start" ''
|
||||||
|
last_nonempty_line=$(${hora-status}/bin/hora-status)
|
||||||
|
(echo $last_nonempty_line | ${gnugrep}/bin/grep -q "^o") || {
|
||||||
|
echo "Last activity must be closed: $last_nonempty_line" >/dev/stderr
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
account=$1
|
||||||
|
(${hora}/bin/hora accounts | ${gnugrep}/bin/grep -q "^$account\$") || {
|
||||||
|
echo "The account '$account' is not known. Please add manually."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
message=$2
|
||||||
|
date=$(${date})
|
||||||
|
echo "i $date $account $message\n" >> "${timeLedger}"
|
||||||
|
echo "Started $account at $date" >/dev/stderr
|
||||||
|
'';
|
||||||
|
|
||||||
|
hora-stop = writers.writeDashBin "hora-stop" ''
|
||||||
|
last_nonempty_line=$(${hora-status}/bin/hora-status)
|
||||||
|
|
||||||
|
(echo $last_nonempty_line | ${gnugrep}/bin/grep "^i") || {
|
||||||
|
echo "Last activity cannot be closed: $last_nonempty_line" >/dev/stderr
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
last_activity=$(echo "$last_nonempty_line" | ${coreutils}/bin/cut -d' ' -f 4)
|
||||||
|
date=$(${date})
|
||||||
|
|
||||||
|
echo "o $date\n" >> ${timeLedger}
|
||||||
|
echo "Stopped $last_activity at $date" >/dev/stderr
|
||||||
|
'';
|
||||||
|
|
||||||
|
hora-year = writers.writeDashBin "hora-year" ''
|
||||||
|
${hora}/bin/hora balance --tree --monthly --begin $(${coreutils}/bin/date +%Y) --depth 1
|
||||||
|
'';
|
||||||
|
hora-git = writers.writeDashBin "hora-git" ''
|
||||||
|
directory=$(${coreutils}/bin/dirname ${lib.escapeShellArg timeLedger})
|
||||||
|
if [ $# -gt 0 ]
|
||||||
|
then
|
||||||
|
${git}/bin/git -C "$directory" --all --message=$(${date})
|
||||||
|
else
|
||||||
|
${git}/bin/git -C "$directory" "$@"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
hora-weekly = writers.writeDashBin "hora-weekly" ''
|
||||||
|
${hora}/bin/hora register -p weekly --depth 1 --empty
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
symlinkJoin {
|
||||||
|
name = "hora";
|
||||||
|
paths = [
|
||||||
|
hora
|
||||||
|
hora-edit
|
||||||
|
hora-start
|
||||||
|
hora-status
|
||||||
|
hora-stop
|
||||||
|
hora-year
|
||||||
|
hora-git
|
||||||
|
hora-weekly
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -9,7 +9,10 @@
|
|||||||
system = "x86_64-darwin";
|
system = "x86_64-darwin";
|
||||||
|
|
||||||
nextcloud = "${config.home.homeDirectory}/Nextcloud/ZODIAC";
|
nextcloud = "${config.home.homeDirectory}/Nextcloud/ZODIAC";
|
||||||
timeLedger = "${nextcloud}/hora.timeclock";
|
|
||||||
|
hora = pkgs.callPackage ../../packages/hora.nix {
|
||||||
|
timeLedger = "${nextcloud}/hora.timeclock";
|
||||||
|
};
|
||||||
|
|
||||||
adminEssentials = import ../../configs/admin-essentials.nix {
|
adminEssentials = import ../../configs/admin-essentials.nix {
|
||||||
inherit pkgs niveumPackages lib system;
|
inherit pkgs niveumPackages lib system;
|
||||||
@@ -25,53 +28,7 @@
|
|||||||
in {
|
in {
|
||||||
home.packages =
|
home.packages =
|
||||||
[
|
[
|
||||||
(pkgs.writers.writeDashBin "hora" ''
|
hora
|
||||||
${pkgs.hledger}/bin/hledger -f "${timeLedger}" "$@"
|
|
||||||
'')
|
|
||||||
(pkgs.writers.writeDashBin "hora-edit" ''
|
|
||||||
nvim + "${timeLedger}"
|
|
||||||
'')
|
|
||||||
(pkgs.writers.writeDashBin "hora-status" ''
|
|
||||||
${pkgs.coreutils}/bin/tac "${timeLedger}" | ${pkgs.gnugrep}/bin/grep -m 1 .
|
|
||||||
'')
|
|
||||||
(pkgs.writers.writeDashBin "hora-start" ''
|
|
||||||
[ -w "${timeLedger}" ] || {
|
|
||||||
echo "${timeLedger}" is not a writable file >/dev/stderr
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
last_nonempty_line=$(hora-status)
|
|
||||||
(echo $last_nonempty_line | ${pkgs.gnugrep}/bin/grep -q "^o") || {
|
|
||||||
echo "Last activity must be closed: $last_nonempty_line" >/dev/stderr
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
account=$1
|
|
||||||
(hora accounts | ${pkgs.gnugrep}/bin/grep -q "^$account\$") || {
|
|
||||||
echo "The account '$account' is not known. Please add manually."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
message=$2
|
|
||||||
date=$(${pkgs.coreutils}/bin/date +"%Y-%m-%d %H:%M:%S")
|
|
||||||
echo "i $date $account $message\n" >> "${timeLedger}"
|
|
||||||
echo Started $account at $date >/dev/stderr
|
|
||||||
'')
|
|
||||||
(pkgs.writers.writeDashBin "hora-stop" ''
|
|
||||||
[ -w "${timeLedger}" ] || {
|
|
||||||
echo "${timeLedger}" is not a writable file >/dev/stderr
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
last_nonempty_line=$(hora-status)
|
|
||||||
(echo $last_nonempty_line | ${pkgs.gnugrep}/bin/grep "^i") || {
|
|
||||||
echo "Last activity cannot be closed: $last_nonempty_line" >/dev/stderr
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
last_activity=$(${pkgs.coreutils}/bin/tail -n 1 ${timeLedger} | ${pkgs.coreutils}/bin/cut -d' ' -f 4)
|
|
||||||
date=$(${pkgs.coreutils}/bin/date +"%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
echo "o $date\n" >> ${timeLedger}
|
|
||||||
echo Stopped $last_activity at $date >/dev/stderr
|
|
||||||
'')
|
|
||||||
niveumPackages.vim
|
niveumPackages.vim
|
||||||
pkgs.ghc
|
pkgs.ghc
|
||||||
pkgs.python3
|
pkgs.python3
|
||||||
|
|||||||
Reference in New Issue
Block a user