diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-02 14:48:29 +0200 |
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2026-08-02 14:48:29 +0200 |
| commit | e43eb1177872f52e949fb5f0f93396ed94b0d093 (patch) | |
| tree | 78b73af6a989fa2996d71b112e161b70d35081ef /home/dot_local/share/bin/executable_timefmt | |
| parent | 2f14a896e4b897bd747c24d7ad8e9e7bb3237d03 (diff) | |
move to chezmoi
Diffstat (limited to 'home/dot_local/share/bin/executable_timefmt')
| -rw-r--r-- | home/dot_local/share/bin/executable_timefmt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/home/dot_local/share/bin/executable_timefmt b/home/dot_local/share/bin/executable_timefmt new file mode 100644 index 0000000..c78fb95 --- /dev/null +++ b/home/dot_local/share/bin/executable_timefmt @@ -0,0 +1,24 @@ +#!/bin/sh +[ $# -eq 0 ] && sum="$(cat)" || sum="$1" +sum="$(echo "$sum" | tr -dc '[:digit:]')" +if [ -z "$sum" ] ; then + echo "error: no input number" + exit 1 +fi + +fmt() { + # printf '%d:%02d:%02d\n' $@ | sed -e 's/^0\{2,\}//' + printf '%02dh%02dm%02ds\n' $@ | sed -e 's/00s$//' -e 's/^\(00.\)\+//' -e 's/^0\+//' +} + +fmt $(bc <<EOF +sum = $sum +seconds = sum % 60 +sum = (sum - seconds) / 60 +minutes = sum % 60 +sum = (sum - minutes) / 60 +hours = sum +print hours," ",minutes," ",seconds +EOF +) + |