nixos-config/modules/workspace/i3blocks/scripts/youtrack-wage.nix

27 lines
1.1 KiB
Nix

{ bash, yt-utilities, libqalculate, config, lib, ... }:
let ec = config.home-manager.users.balsoft.programs.emacs.finalPackage;
in
''
#!${bash}/bin/bash
set -euo pipefail
export PATH="$PATH:${yt-utilities}/bin:${ec}/bin:${libqalculate}/bin"
WAGE=$(cat ${config.secrets.wage.decrypted})
HOURS_MONTH=$(yt org local --since $(date +'%Y-%m-01') | tail -1)
MONEY_MONTH=$(qalc -t "($HOURS_MONTH) * $WAGE")
'' + (if config.deviceSpecific.bigScreen then ''
HOURS_DAY=$(yt org local --since $(date +'%Y-%m-%d') | tail -1)
HOURS_YEAR=$(yt org local --since $(date +'%Y-01-01') | tail -1)
MONEY_DAY=$(qalc -t "($HOURS_DAY) * $WAGE")
MONEY_YEAR=$(qalc -t "($HOURS_YEAR) * $WAGE")
TASK=$(emacsclient --eval "org-mode-line-string" 2>/dev/null || echo -n none)
if ! [[ "$TASK" == "none" ]]; then
HOURS_TASK=$(echo "$TASK" | head -1 | cut -d\" -f 2 | cut -d\[ -f2 | cut -d\] -f1)h
MONEY_TASK=$(qalc -t -e "$HOURS_TASK * $WAGE" )
echo "$MONEY_TASK/$MONEY_DAY($HOURS_DAY)/$MONEY_MONTH($HOURS_MONTH)/$MONEY_YEAR"
else
echo "$MONEY_DAY($HOURS_DAY)/$MONEY_MONTH($HOURS_MONTH)/$MONEY_YEAR"
fi
'' else ''
echo "$MONEY_MONTH($HOURS_MONTH)"
'')