diff --git a/extras/zeit-sketchybar.sh b/extras/zeit-sketchybar.sh new file mode 100755 index 0000000..50c8a44 --- /dev/null +++ b/extras/zeit-sketchybar.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +## Skeytchybar configuration: +# sketchybar --add item zeit e \ +# --set zeit icon=󱏁 \ +# script="$HOME/bin/zeit-sketchybar.sh" \ +# update_freq=15 + + +ZEIT_BIN=$HOME/bin/zeit +SKETCHY_BIN=/opt/homebrew/bin/sketchybar + +line_identifier='^ ▶ tracking' + +tracking=$($ZEIT_BIN tracking --no-colors | grep "$line_identifier" | sed -e "s/$line_identifier//") + +echo $tracking +$SKETCHY_BIN --set zeit label="$tracking" diff --git a/z/resumeCmd.go b/z/resumeCmd.go new file mode 100644 index 0000000..89d3f2a --- /dev/null +++ b/z/resumeCmd.go @@ -0,0 +1,21 @@ +package z + +import ( + "github.com/spf13/cobra" +) + +var resumeCmd = &cobra.Command{ + Use: "resume", + Short: "Resume last task", + Long: "Track new activity with all parameters of the last task (based on begin time)", + Run: func(cmd *cobra.Command, args []string) { + resumeTask(1) + }, +} + +func init() { + rootCmd.AddCommand(resumeCmd) + + resumeCmd.Flags().StringVarP(&begin, "begin", "b", "", "Time the activity should begin at\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).") + resumeCmd.Flags().StringVarP(&finish, "finish", "s", "", "Time the activity should finish at\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).\nMust be after --begin time.") +} diff --git a/z/rootCmd.go b/z/rootCmd.go index ed30570..2ad2398 100644 --- a/z/rootCmd.go +++ b/z/rootCmd.go @@ -12,6 +12,7 @@ var database *Database var begin string var finish string +var switchString string var project string var task string var notes string diff --git a/z/switchBackCmd.go b/z/switchBackCmd.go new file mode 100644 index 0000000..b6d31ba --- /dev/null +++ b/z/switchBackCmd.go @@ -0,0 +1,26 @@ +package z + +import ( + "github.com/spf13/cobra" +) + +var switchBackCmd = &cobra.Command{ + Use: "switchback", + Short: "switchback to the task before the last one", + Long: "End running activity and resume the task which was before, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.", + Run: func(cmd *cobra.Command, args []string) { + + finish = switchString + finishTask(FinishOnlyTime) + + finish = "" + begin = switchString + resumeTask(2) + }, +} + +func init() { + rootCmd.AddCommand(switchBackCmd) + + switchBackCmd.Flags().StringVarP(&switchString, "begin", "b", "", "Time the new activity should begin at and the old one ends\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).") +} diff --git a/z/switchCmd.go b/z/switchCmd.go new file mode 100644 index 0000000..044b6ee --- /dev/null +++ b/z/switchCmd.go @@ -0,0 +1,38 @@ +package z + +import ( + "github.com/spf13/cobra" +) + +var switchCmd = &cobra.Command{ + Use: "switch", + Short: "switch to another task", + Long: "End running activity and track new activity, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.", + Run: func(cmd *cobra.Command, args []string) { + + finish = switchString + finishTask(FinishOnlyTime) + + finish = "" + begin = switchString + trackTask() + }, +} + +func init() { + rootCmd.AddCommand(switchCmd) + + switchCmd.Flags().StringVarP(&switchString, "begin", "b", "", "Time the new activity should begin at and the old one ends\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).") + switchCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be assigned") + switchCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned") + switchCmd.Flags().StringVarP(¬es, "notes", "n", "", "Activity notes") + + flagName := "task" + switchCmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + user := GetCurrentUser() + entries, _ := database.ListEntries(user) + _, tasks := listProjectsAndTasks(entries) + return tasks, cobra.ShellCompDirectiveDefault + }) +} + diff --git a/z/task.go b/z/task.go index d2994fa..450bd33 100644 --- a/z/task.go +++ b/z/task.go @@ -226,3 +226,47 @@ func taskGit(task *Task, runningEntry *Entry) { } } +func resumeTask(index int) { + user := GetCurrentUser() + + entries, err := database.ListEntries(user) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + lastEntry := entries[len(entries)-index] + + runningEntryId, err := database.GetRunningEntryId(user) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + if runningEntryId != "" { + fmt.Printf("%s a task is already running\n", CharTrack) + os.Exit(1) + } + + project = lastEntry.Project + task = lastEntry.Task + + newEntry, err := NewEntry("", begin, finish, project, task, user) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + if lastEntry.Notes != "" { + newEntry.Notes = lastEntry.Notes + } + + isRunning := newEntry.Finish.IsZero() + + _, err = database.AddEntry(user, newEntry, isRunning) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + fmt.Print(newEntry.GetOutputForTrack(isRunning, false)) +}