1
0
mirror of https://github.com/kmein/niveum synced 2026-03-22 04:41:07 +01:00

4 Commits

4 changed files with 94 additions and 67 deletions

View File

@@ -1,33 +1,15 @@
{
config,
pkgs,
...
}: let
ledgerDirectory = "$HOME/projects/ledger";
timeLedger = "${ledgerDirectory}/time.timeclock";
hora = pkgs.writers.writeDashBin "hora" ''
${pkgs.hledger}/bin/hledger -f "${timeLedger}" "$@"
'';
ledgerDirectory = "/home/kfm/projects/ledger";
hora = pkgs.callPackage ../packages/hora.nix { timeLedger = "${ledgerDirectory}/time.timeclock"; };
in {
environment.systemPackages = let
git = "${pkgs.git}/bin/git -C ${ledgerDirectory}";
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
(pkgs.writers.writeDashBin "hora-year" ''
${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.hledger
(pkgs.writers.writeDashBin "hledger-git" ''
if [ "$1" = entry ]; then
${pkgs.hledger}/bin/hledger balance -V > "${ledgerDirectory}/balance.txt"

View File

@@ -54,7 +54,7 @@
hash -d nixos=/etc/nixos niveum=${config.users.users.me.home}/projects/niveum
autoload -U zmv run-help
autoload -U zmv run-help edit-command-line
fpath=(${zsh-completions}/src $fpath)
'';
@@ -99,6 +99,8 @@
zle -N zle-line-init
zle -N zle-keymap-select
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
'';
};
}

80
packages/hora.nix Normal file
View 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
];
}

View File

@@ -9,7 +9,10 @@
system = "x86_64-darwin";
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 {
inherit pkgs niveumPackages lib system;
@@ -25,47 +28,7 @@
in {
home.packages =
[
(pkgs.writers.writeDashBin "hora" ''
${pkgs.hledger}/bin/hledger -f "${timeLedger}" "$@"
'')
(pkgs.writers.writeDashBin "hora-edit" ''
nvim + "${timeLedger}"
'')
(pkgs.writers.writeDashBin "hora-start" ''
[ -w "${timeLedger}" ] || {
echo "${timeLedger}" is not a writable file >/dev/stderr
exit 1
}
(${pkgs.coreutils}/bin/tail -n 1 "${timeLedger}" | ${pkgs.gnugrep}/bin/grep -q "^o") || {
echo "Last activity must be closed: $(${pkgs.coreutils}/bin/tail -n 1 "${timeLedger}")" >/dev/stderr
exit 1
}
account=$1
(${pkgs.hledger}/bin/hledger -f "${timeLedger}" 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" >> "${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
}
(${pkgs.coreutils}/bin/tail -n 1 "${timeLedger}" | ${pkgs.gnugrep}/bin/grep "^i") || {
echo "Last activity cannot be closed: $(${pkgs.coreutils}/bin/tail -n 1 "${timeLedger}")" >/dev/stderr
exit 1
}
last_activity=$(${pkgs.coreutils}/bin/tail -n 1 ${timeLedger} | ${pkgs.coreutils}/bin/cut -d' ' -f 3)
echo "o $(${pkgs.coreutils}/bin/date +"%Y-%m-%d %H:%M:%S")" >> ${timeLedger}
echo Stopped $last_activity >/dev/stderr
'')
hora
niveumPackages.vim
pkgs.ghc
pkgs.python3
@@ -95,8 +58,8 @@ in {
syntaxHighlighting.enable = true;
syntaxHighlighting.highlighters = ["main" "brackets" "pattern" "line"];
initExtra = ''
# ref https://gist.github.com/meeech/0b97a86f235d10bc4e2a1116eec38e7e
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ];
# ref https://gist.github.com/meeech/0b97a86f235d10bc4e2a1116eec38e7e
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ];
then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
@@ -137,4 +100,4 @@ in {
hora register -p weekly --depth 1 --empty
*/
*/