X-Git-Url: https://git.defcon.no/?a=blobdiff_plain;ds=sidebyside;f=trk;h=6629a7c0c9ee4cf6199e9f38de384dd7b784a0ca;hb=HEAD;hp=710e9ad8b5e5c1fe9d0528c53bbad543c4a3c19c;hpb=24e69710100f0e151f66ef9e0d7deef8c012cc87;p=trk diff --git a/trk b/trk index 710e9ad..6629a7c 100755 --- a/trk +++ b/trk @@ -369,6 +369,8 @@ sub report ($$;$) my $name = get_track_name( $current, $trk_id ); printf("# Report for '%s':\n\n", $name) unless $silent; + my $check = get_current_id( $trk_id ); + open (TRACK, "<" . $wrk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!"); while ( ) { @@ -385,8 +387,21 @@ sub report ($$;$) } $total += $delta; + } close ( TRACK ); + + if ( $check eq $current ) + { + my $t; + if ( $t = current_starttime( $trk_id ) ) + { + my $delta = time - $t; + printf(" %s to NOW (active) => %s\n", time2str( $t ), delta2str( $delta ) ) if not $silent; + $total += $delta; + } + } + return $total; } @@ -400,13 +415,15 @@ sub current_starttime (;$) my $line = undef; my $current = get_current_id( $trk_id ); + return 0 if not $current; + open (TRACK, "<" . $wrk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!"); while ( ) { $line = $_; } close ( TRACK ); - return 0 if not $line =~ m/\[(\d\d\d\d-\d\d-\d\d \d\d:\d\d)\]/; + return 0 if not $line =~ m/^\[(\d\d\d\d-\d\d-\d\d \d\d:\d\d)\]$/; return str2time($1); } @@ -554,6 +571,7 @@ elsif ( $command eq "main" ) printf("Stopped tracking of '%s' at %s\n\n", $title, scalar localtime $stop_time); } } +#### Mark elsif ( ( $command eq "projects" ) || ( $command eq "list" ) ) { # Todo/future extensions: @@ -567,7 +585,54 @@ elsif ( ( $command eq "projects" ) || ( $command eq "list" ) ) #foreach my $id ( keys %$tracks ) foreach my $id ( sort { $tracks->{$a} cmp $tracks->{$b} || $a cmp $b } keys %$tracks ) { - printf(" %s %s\n", ($id eq $current ? ">" : " " ),$tracks->{$id} ); + + if (( $#ARGV >= 1) && ( $ARGV[1] eq "verbose" )) + { + printf(" %s %s %s\n", ($id eq $current ? ">" : " " ), $id , $tracks->{$id}); + } + else + { + printf(" %s %s\n", ($id eq $current ? ">" : " " ),$tracks->{$id} ); + } + } + print("\n"); +} +#### Mark +elsif ( ( $command eq "activities" ) || ( $command eq "tasks" ) ) +{ + # Todo/future extensions: + # TODO: Sort list of names alphabetically + # TODO: Get total-hours for projects + # TODO: + + + my $trk_id = get_current_id(); + if ( not $trk_id ) + { + printf("Starting a task/activity requires an active main track.\n"); + exit(1); + } + + my $verbose = (( $#ARGV >= 1) && ( $ARGV[1] eq "verbose" )); + + my $tracks = get_tracks( $trk_id ); + printf("Current track is '%s'\n", get_track_name( $trk_id )); + printf("Track ID for for current track is %s\n", $trk_id) if $verbose; + printf("Currently tracked activities/tasks for track '%s':\n\n", get_track_name( $trk_id )); + my $current = get_current_id( $trk_id ); + + #foreach my $id ( keys %$tracks ) + foreach my $id ( sort { $tracks->{$a} cmp $tracks->{$b} || $a cmp $b } keys %$tracks ) + { + + if ( $verbose ) + { + printf(" %s %s %s\n", ($id eq $current ? ">" : " " ), $id , $tracks->{$id}); + } + else + { + printf(" %s %s\n", ($id eq $current ? ">" : " " ),$tracks->{$id} ); + } } print("\n"); }