Skip to content

Instantly share code, notes, and snippets.

@godDLL
Last active December 24, 2023 16:02
Show Gist options
  • Save godDLL/b4a43505b0dac4f12dcd73046efae5ee to your computer and use it in GitHub Desktop.
Save godDLL/b4a43505b0dac4f12dcd73046efae5ee to your computer and use it in GitHub Desktop.
Interactive time-logging calculator on console. Kinda like pomodoro with soulver/numi inside, but in your terminal.

Time Log Fish

A utility to log time on the terminal. It's like a task list that can be saved.

Marks current time automatically, has some editing features.

:calc demo
calc demo

Plays nice with terminal themes.

Integrates with user (meaning Your's) status-line scripts.

CHANGELOG

+ TITLE env variable for custom command hooks
+ setting STATUS command, and ovrerriding it with ARGV
+ deleting and replacing lines interactively
+ adding lines interactively
+ refreshing TIME in prompt with Enter, runs STATUS below
+ adding STATUS as a line with just +
+ adding empty lines with +SPACE
+ writing ANSI file with !w (use cat to view)
+ tagging a line
+ back-dating HH:MM. lines
+ calculate math with :5/13
+ exit with Ctrl-C or Ctrl-D

License MIT, free to do whatever. Yours to fuck up.
USAGE demo

TODO

- calculate using last calc result with .
- calc time passed for lines ending in /
- FIXME: lines deleted after ? are not in the plog, don't delete older lines
#!/usr/bin/env fish
# v0.1 gist.github.com/godDLL/b4a43505b0dac4f12dcd73046efae5ee
if set -q TITLE
set -- TITLE (fish -c "$TITLE")
else
set -- TITLE (date +'%d %m-%Y')
end
set TITLE_len (math -s0 '1+ '(string length -- "$TITLE"))
set -l PLOG
set -a -- PLOG (echo -e -- '\e[A\e['$COLUMNS'G\e['$TITLE_len'D\e[37;40m '$TITLE' \e[m')
echo -- $PLOG[-1]
set -l -- S (date +%H:%M.)
set -l -- ST
if test -n "$STATUS"
if test -n "$argv"
set -- ST "$argv"
else
set -- ST (fish -c "$STATUS")
if test -z "$ST"
set -- ST "$S"
end
end
else
if test -n "$argv"
set -- ST "$argv"
if test -z "$ST"
set -- ST "$S"
set -- STATUS 'date +%A\ %H:%M.'
end
else
set -- ST "$S"
set -- STATUS 'date +%A\ %H:%M.'
end
end
set -a -- PLOG (echo -e -- ' '(date +%A) "$ST")
echo -- $PLOG[-1]
#clear
set -l cl '\e[K'
set -l upcl '\e[A'$cl
set -l do_upcl ""
set -l R
set -l ANS 0
set -l TIME_fmt +\e\[1m'%H:%M'\e\[2m'.%S'\e\[m
set -l T (date $TIME_fmt)
while read -P (echo -e -- "$R$T"' ') -l N
if test -z "$N"
# don't advance line
set R '\e[A'
# do refresh clock
set T (date $TIME_fmt)
# where am i?
echo -ne -- '\e[K'(fish -c "$STATUS")
else
set R ''
set T (date $TIME_fmt)
if test '/-/' = "/$N/"
set N ''
echo -ne -- '\e[B\e[K\e[2A\e[K\e[A'
set PLOG $PLOG[1..-2]
# deleted lines are not logged
else if test '/+/' = "/$N/"
set N ''
set -a PLOG (echo -e -- '\e[2m' (date +%A) (fish -c "$STATUS")'\e[m')
echo -e -- '\e[B\e[K\e[2A\e[K'$PLOG[-1]
else if string match --quiet -- ':*' "$N"
set N (string sub -s 2 "$N")
set -- ANS ' '(math -s2 "$N")
set -l -- ANS_len (string length -- " =$ANS")
set -a PLOG (echo -e -- ' '$N'\e['$COLUMNS'G\e['$ANS_len'D\e[1;46m ='$ANS' \e[m')
echo -e -- $upcl$PLOG[-1]
else if string match --quiet -- '*:*.*' "$N"
set -l M (string split --max 1 -- ' ' "$N")
set -a PLOG (echo -e -- "\e[m\e[4m$M[1]\e[m $M[2]")
echo -e -- $upcl$PLOG[-1]
else if string match --quiet -- '*:*' "$N"
set -l M (string split --max 1 -- ':' "$N")
set M[2] (string trim --left -- "$M[2]")
set M[1] (string upper -- "$M[1]")
set -l TT (date $TIME_fmt |cut -d. -f1)
if test 7 -le (string length -- "$M[1]")
set -a PLOG (echo -e -- "\e[8m$TT.\e[m\e[2m$M[1]\e[m\e[8m:\e[m\t$M[2]")
else
set -a PLOG (echo -e -- "\e[8m$TT.\e[m\e[2m$M[1]\e[m\e[8m:\e[m\t\t$M[2]")
end
echo -e -- $upcl$PLOG[-1]
else
if string match --quiet -- '+*' "$N"
set -l M (string sub -s 2 -- "$N")
set -a PLOG (echo -e -- " $M")
echo -e -- $upcl$PLOG[-1]
# added lines are logged
else if string match --quiet -- '-*' "$N"
set -l M (string sub -s 2 -- "$N")
set PLOG[-1] " $M"
echo -e -- $upcl$upcl" $M"
# overwritten lines are overwritten in log
else
if test '/?/' = "/$N/" -o '/!/' = "/$N/"
echo -ne '\e[3m'
echo -e -- ' mark the TIME & add a note (default)'
echo -e -- ' + add a NOTE (defualt: note current status)'
echo -e -- ' - replace last note (default: delete last note)'
echo -e -- ' : calculate and note the result'
echo -e -- ' tag: note\n mark:specific.time\n mark time passed/'
echo -e -- ' !w (over)write to file (default: DATE HH:MM.plog)'
echo -ne '\e[m'
# interactive prompts are not logged
else if test '/!w/' = "/$N/"
set -l FILE (date +%Y-%m\ %d\ %H-%M).plog
if touch "$FILE"
string join -- \n $PLOG >"$FILE"
echo -e -- $upcl"\e[3m$FILE now saved\e[m"
else
echo -e -- ' \e[1;31mErr\e[m: write to file '$FILE
end
else
set -a PLOG (echo -e -- "$T $N")
end
end
end
end
end
@godDLL
Copy link
Author

godDLL commented Nov 5, 2021

License MIT, free to do whatever. Yours to fuck up.
asciinema.org/a/447537

@godDLL
Copy link
Author

godDLL commented Nov 5, 2021

Version 0.1 screenshots:

Screen Shot 2021-11-05 at 09 53 29 copy
Screen Shot 2021-11-05 at 09 53 11 copy

@godDLL
Copy link
Author

godDLL commented Nov 5, 2021

v0.1 bug fixes watch cast

+ calculate math with :
* full weekday name in STATUS
* slow default STATUS line now faster

@godDLL
Copy link
Author

godDLL commented Nov 5, 2021

v0.2 bug fixes

+ calculate using last result with .
* zero out last result with just :

calc

@kseistrup
Copy link

Fish's set_color command will output relevant escape sequences for changing colours and other attributes (and resetting them). Use set_color -c to see the colours it recognizes.

@godDLL
Copy link
Author

godDLL commented Nov 6, 2021

@kseistrup Correct.
It is also dog-slow for what I'd be using it for.

And I don't need the help in manipulating my terminal as to the modes, colors, pages etc.
Which it can't do anyway.
So no, not doing that.
👎

EDIT: eh, I did not mean to come over so stern.
There is nothing wrong with set_color except for how slow it is, really.
I don't even use it in my PROMPTs.

@kseistrup
Copy link

That's fine, I never expected you to — just thought I'd mention it.

Personally, I would never call set_color every time I needed it. Rather, I would e.g. set GREEN (setcolor green) in the beginning of the script and then refer to $GREEN everywhere else. Has the potential of making the code more legible.

I use set_color in some of my own fish scripts, and I disagree with the “dog slowness”.

@godDLL
Copy link
Author

godDLL commented Nov 7, 2021

Oh, it is so good to actually meet someone you could comfortably disagree with. I exactly started doing what you describe, than ran that 10K times, and had to get coffee. Then it happened again, in a different script I wrote. So, how was that saying, three times makes an idiot of me, or whatever to that effect.
I am of the opinion that FISH itself is way slow. If only it wasn't so convenient I'd switch away to, eh, I dunno, I'd whip something up.
❤️

UPDATE: looking for iffy sections I found exactly 5 lines to comment where it's all ANSI escapes, should be very readable now. Thanks.
UPDATE: removed one. But he's not starring this gist no more, so whatever.

@godDLL
Copy link
Author

godDLL commented Nov 7, 2021

v0.3 refinements to the UI, bug fixes

new CALC demo
new EDITING demo
new USAGE demo

* calculator changed to use = instead of :
+ see the time difference with just /
* status adding changed from just + to ++
* a + adds an empty line
+ added facility to strip ANSI colors (keeps motions tho)
+ previous line can now be time-stamped with -+
+ previous line can now be edited with --

(Yes, I know that the maths on main screenshot don't make sense, I'll be doing something about taht.)

@godDLL
Copy link
Author

godDLL commented Nov 8, 2021

Added a WIKI file, now that the feature-set and scope of this script has stabilized enough for that.

I might just not be adding any more features, it all feels well-rounded right now. Quite.

@godDLL
Copy link
Author

godDLL commented Nov 14, 2021

v0.4 added menu for your autofill

new MENU demo will appear with imminent v0.5 as part of documentation effort

* general formatting improvements
+ added MENU to call custom script with ! or `
- faster, less subshell usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment