Track time via the Linux terminal
Keeping track of the time you spend on a project may seem like a Herculean task in itself. Thankfully, Shashank Sharma has a quick and easy solution.
Unless you’re very, very organised, you’re unlikely to be able to accurately describe the amount of time you spend on any given task performed over any given period. Keeping careful track of the amount of time spent on a task becomes a priority if you plan to bill clients on an hourly basis.
A time-tracking app can be used to help make sense of how you spend the hours at work. This data can help you identify areas where you need to increase your productivity. You might realise you’re taking rather long lunches or spending too much time on research, and not enough responding to emails (although, of course, we all know that some emails can be safely ignored [Carefulnow...—Ed] or better still, deleted immediately).
Watson is a command-line utility written in Python and released under the MIT License. It enables you to easily track the time spent on projects and assignments. It can then generate reports on the collected data and reveal how you spent the work hours on any given day, week, month or even an year.
ELEMENTARY, DEAR READER
The project is hosted on GitHub and you can easily clone the repository and install Watson. For most distributions, an easier installation option is to use the pip package manager. If you don’t already have it installed, you can run the sudo apt install pip or su -c ‘dnf install pip’ command on your Ubuntu and Fedora machines. Most other distributions also provide pip in their repositories and you can install it without hassles. You can then install Watson with sudo pip install td-watson . This will automatically fetch and install the tool in the ‘~/.local/ bin’ directory. Because this directory isn’t described in $PATH, you can’t use Watson just yet. Run the echo ‘export PATH=”$ HOME/.local/ bin:$ PATH”’ >> ~/.bashrc
command, which adds this path to your .bashrc file. You must now reload the .bashrc file with the source
.bashrc command. One of the best features of Bash is its tab-completion and you can configure Watson for tab-completion by downloading the watson. completion file from the GitHub repository and placing it in the ‘/etc/ bash. completion.d/’ directory. When you restart the shell terminal, you’ll be able to use tab-completion with Watson. To begin, type watson [tab] [tab] in the terminal for a list of all available commands.
For each task you wish to record with Watson, you must specify a project name and you can have several different tasks within each project. For instance, a project named Leisure can be used to track the amount of time you spend on non-work activities. Here, reading and video games are tasks within the project. These tasks within a project are referred to as tags. You can use the same tags across different projects. Every time you run the watson
start command, the project records all the relevant data such as the name of the project, the relevant tags and the start time and stores it in what the project refers to as frames.
When you run the watson stop command, the project stops recording and prints out the frame id for the last recorded session. You can get a list of all the recorded frames by running the watson frames command. The name of the frame itself doesn’t reveal any information about the data it contains, such as the project name or the start and stop times.
Before you can begin generating reports of how you spend your work hours, you must first identify the different projects and tasks you wish to record with Watson. Then you can start recording a session with the watson start projectname +tags . Each start command supports the use of several tags:
$ watson start Leisure +reading
Starting project Leisure [reading] at 19:53
The first command tells Watson to record a project named Leisure. The use of +tags is optional, but we’ve used it here to identify the type of leisure activity. Watson will provide the name of the frame for the most recently recorded activity when you run the stop command: $ watson stop Stopping project Leisure [reading], started 12 minutes ago. (id: c382b06)
Watson uses a new frame for every new start command, even if you restart an already existing project. You can use multiple tags with the start command, or use different tags for the same project at a later time, like using the +Coffee and +Lunch tags at different time to record the Breaks you take during the day: $ watson start Break +lunch Starting project Break [lunch] at 13:15 $ watson stop Stopping project Break [lunch], started 30 minutes ago. (id: 0d8583d)
$ watson start Break +”evening tea”
Starting project Break [evening tea] at 19:25
As you can see, we’ve used the Break project but with different tags each time. You can run the watson
frames and the watson projects commands to respectively fetch a list of all the frames and projects. Don’t worry about several frames existing for the same project and tags. When generating reports, Watson will automatically add the amount of time spent on any project or task across different frames.
REPORTING FOR DUTY
You can use Watson to generate daily, weekly or monthly reports. If you want reports for a specific project only, or for a specific period, like say 50 days, you can do that as well. The watson report command will display all the project’s details: $ watson report Thu 15 February 2018 -> Thu 22 February 2018 Break - 2h 23m 34s [evening tea 2h 23m 34s] Doctor’s-Visit - 2h 21m 11s APC452 - 30h 04m 08s [Roundup 17h 01m 37s] [Tutorial 13h 02m 31s] Leisure - 1h 04m 11s [comics 02m 32s] [reading 1h 04m 11s] Lunch - 1h 20m 48s [break 1h 20m 48s] Total: 36h 22m 38s
If looking at the above data makes you question our evening tea habits, don’t! By default, Watson provides the data for the past seven days. The block here is for the period between 15 and 22 February. As you can see, it shows a lunch of only one hour 20 minutes, which means we forgot to record the lunch on more than one occasion during the week.
Should you wish to edit a frame, such as when you continued working on a project after stopping Watson, you can run the watson edit frameid command, which opens the relevant frame in the configured text editor, and you can then change the stop/start times. You can also rename a project or tag with the watson rename command.
You can run the watson report -m command for a list of all the projects you worked on in the current month. You can similarly generate reports for a specific tag or project using the -T or the -p options with reports:
$ watson report -T Roundup -m
Thu 01 February 2018 -> Thu 22 February 2018 APC453 - 17h 01m 37s [Roundup 17h 01m 37s] APC454 - 9h 51m 36s [Roundup 9h 51m 36s] Total: 26h 53m 13s Here, we’ve combined switches to generate reports on a tag for the current month. Since we used the same tag across different projects, Watson automatically reports the data for both projects.
Watson doesn’t identify frames using the project name, so you must run the
watson log command for a list of all the Watson commands you’ve run. This will provide you a date list of all the frames (latest first), and the corresponding project/tag name, etc.
It’s easy to see the appeal for a project like Watson, even if you’re not required to keep time sheets. You might even be surprised at what it has to report at the end of the working week. Now, about those emails...
Some commands have many options and Watson provides specific options for each with the --help switch: watson report --help.
You can use tab-completion for the name of the commands such as start and report and also for the names of the projects and tags.