doing 1.0.61 → 1.0.65

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 406fa23f47c83c1b9b3c8fa1cd0e193761c0b13e7ec31f75fdf43b1375769d18
4
- data.tar.gz: 2c7f30f6acfac0fb33266dd62ce204099c0358cef88e19de8f26c9e9a4f866f2
3
+ metadata.gz: a774718572df78395293b6294bcfa4bac94cfe2cde0ffec43e8bbea60b874534
4
+ data.tar.gz: fba4b65439084eae5b291bd65f5a1d14d49e5b5c4c8b70abd5e8f73fa39b3545
5
5
  SHA512:
6
- metadata.gz: 547c64a9fbfdb026a0ecaf1b4b0ae203306907ddbdc7cff76062b82312293e36eb170b8874f3aa643e19a8f2d3310aea472f23b12128b7b9eeb300956210ca68
7
- data.tar.gz: 37d3819348c3167b6c77a34f8e7e2311015c3975e8595303e04c1d89cb28d7d8a83d7dfea810440b846621d90fd8e7bd1538dd9e3f607a2002284d1405474de8
6
+ metadata.gz: 01bf52dbc6e7077e6ff2a67ab22504dda4be927f31da8be7e5383136b5cac500cd7920203b7383ebe302af5ddce375e0ee7389273a275edfde27971de8ae87bb
7
+ data.tar.gz: 79e7b8dcf00223118a0e3f5bb648ed33e920dc915909f62d1c21f2a19332f3d35336d3e5ca85a31632416b9fb9364d58db2fb6a4f90e7a200bc7cb706f76e14b
data/README.md CHANGED
@@ -29,7 +29,7 @@ _Side note:_ I actually use the library behind this utility as part of another s
29
29
 
30
30
  ## Installation
31
31
 
32
- The current version of `doing` is <!--VER-->1.0.60<!--END VER-->.
32
+ The current version of `doing` is <!--VER-->1.0.64<!--END VER-->.
33
33
 
34
34
  $ [sudo] gem install doing
35
35
 
@@ -167,7 +167,7 @@ The config also contains templates for various command outputs. Include placehol
167
167
  - there are some random special combo colors. Use `doing colors` to see the list
168
168
  - `%interval`: when used with the `-t` switch on the `show` command, it will display the time between a timestamp or _@start(date)_ tag and the _@done(date)_ tag, if it exists. Otherwise, it will remain empty.
169
169
 
170
- Date formats are based on Ruby [`strftime`](http://www.ruby-doc.org/stdlib-2.1.1/libdoc/date/rdoc/Date.html#method-i-strftime) formatting.
170
+ Date formats are based on Ruby [`strftime`](http://www.ruby-doc.org/stdlib-2.1.1/libdoc/date/rdoc/Date.html#method-i-strftime) formatting. You can try it out [here](http://strftime.net).
171
171
 
172
172
  My normal template for the `recent` command looks like this:
173
173
 
@@ -394,24 +394,41 @@ Note that you can include a tag with synonyms in the whitelist as well to tag it
394
394
 
395
395
  #### Adding entries:
396
396
 
397
- now, did - Add an entry
397
+ now, next - Add an entry
398
398
  later - Add an item to the Later section
399
- done - Add a completed item with @done(date). No argument finishes last entry.
399
+ done, did - Add a completed item with @done(date). No argument finishes last entry.
400
400
  meanwhile - Finish any @meanwhile tasks and optionally create a new one
401
401
  again, resume - Duplicate the last entry as new entry (without @done tag)
402
402
 
403
- The `doing now` command can accept `-s section_name` to send the new entry straight to a non-default section. It also accepts `--back=AMOUNT` to let you specify a start date in the past using "natural language." For example, `doing now --back=25m ENTRY` or `doing now --back="yesterday 3:30pm" ENTRY`.
403
+ ##### now
404
404
 
405
- If you want to use `--back` with `doing done` but want the end time to be different than the start time, you can either use `--took` in addition, or just use `--took` on its own as it will backdate the start time such that the end time is now and the duration is equal to the value of the `--took` argument.
405
+ The `doing now` command adds an entry to the "Currently" section by default. It accepts `-s section_name` to send the new entry straight to a non-default section. It also accepts `--back=AMOUNT` to let you specify a start date in the past using "natural language." For example, `doing now --back=25m ENTRY` or `doing now --back="yesterday 3:30pm" ENTRY`.
406
406
 
407
407
  You can finish the last unfinished task when starting a new one using `doing now` with the `-f` switch. It will look for the last task not marked _@done_ and add the _@done_ tag with the start time of the new task (either the current time or what you specified with `--back`).
408
408
 
409
- `doing done` is used to add an entry that you've already completed. Like `now`, you can specify a section with `-s section_name`. You can also skip straight to Archive with `-a`.
409
+ > __Examples:__
410
+ >
411
+ > - `doing now Working on project X` --- Add a new entry at the current time
412
+ > - `doing now --section=Projects Working on @projectX` --- Add a new entry to a section titled "Projects"
413
+ > - `doing now --back 30m` --- Add a new entry with a backdated start time, indicating you've been working on it for 30 minutes already
414
+ > - `doing now --back 8am` --- Backdate a new entry to a specific time
415
+ > - `doing now -f Starting the next thing` --- Add a new entry at the current time, and add a @done tag to the previous item with the current time as its completion date
416
+ > - `doing now -f --back 30m Working on something new` --- Add a new entry and complete the last entry, but use a timestamp from 30 minutes ago for both.
410
417
 
411
- `doing done` can also backdate entries using natural language with `--back 15m` or `--back "3/15 3pm"`. That will modify the starting timestamp of the entry. You can also use `--took 1h20m` or `--took 1:20` to set the finish date based on a "natural language" time interval. If `--took` is used without `--back`, then the start date is adjusted (`--took` interval is subtracted) so that the completion date is the current time.
418
+ ##### done/finish
419
+
420
+ `doing done` is used to add an entry that you've already completed. Like `now`, you can specify a section with `-s section_name`. You can also skip straight to the Archive with `-a`.
421
+
422
+ `doing done` can also backdate entries using natural language with `--back 15m` or `--back "3/15 3pm"`. That will modify the starting timestamp of the entry. Used on its own, it will set the start date, and the finish date will be the current time. You can also use `--took 1h20m` or `--took 1:20` to set the finish date based on a "natural language" time interval. If `--took` is used without `--back`, then the start date is adjusted (`--took` interval is subtracted) so that the completion date is the current time.
412
423
 
413
424
  When used with `doing done`, `--back` and `--took` allow time intervals to be accurately counted when entering items after the fact. `--took` is also available for the `doing finish` command, but cannot be used in conjunction with `--back`. (In `finish` they both set the end date, and neither has priority. `--back` allows specific days/times, `--took` uses time intervals.)
414
425
 
426
+ > __Examples:__
427
+ >
428
+ > - `doing done --back 1h The thing I just did` --- Add an entry for a completed task that you started an hour ago and just finished
429
+ > - `doing done --back 1h --took 20m The thing I just finished` --- Record an entry you started an hour ago and finished 20 minutes later
430
+ > - `doing done --took 20m` --- Finish the last task but change the finish date so that the total elapsed time is only 20 minutes (if the finish date would be in the future, start date will be adjusted accordingly)
431
+
415
432
  All of these commands accept a `-e` argument. This opens your command line editor (as defined in the environment variable `$EDITOR`). Add your entry, save the temp file, and close it. The new entry is added. Anything after the first line is included as a note on the entry.
416
433
 
417
434
  `doing again` (or `doing resume`) will duplicate the last @done entry (most recently completed) with a new start date (and without the @done tag). To resume the last entry matching specific tags, use `--tag=TAG`. You can specify multiple tags by separating with a comma. Multiple tags are combined with 'AND' by default (all tags must exist on the entry to match), but you can use `--bool=` to set it to 'OR' or 'NOT'. By default the new entry will be added to the same section as the matching entry, but you can specify a section with `--in=SECTION`.
@@ -429,7 +446,7 @@ See `doing help meanwhile` for more options.
429
446
 
430
447
  ##### Finishing
431
448
 
432
- `doing finish` by itself is the same as `doing done` by itself. It adds _@done(timestamp)_ to the last entry. It also accepts a numeric argument to complete X number of tasks back in history. Add `-a` to also archive the affected entries.
449
+ `doing finish` by itself is the same as `doing done` by itself. It adds _@done(timestamp)_ to the last entry. It also accepts a numeric argument to complete X number of tasks back in history (0 affects all entries). Add `-a` to also archive the affected entries.
433
450
 
434
451
  `doing finish` also provides an `--auto` flag, which you can use to set the end time of any entry to 1 minute before the start time of the next. Running a command such as `doing finish --auto 10` will go through the last 10 entries and sequentially update any without a _@done_ tag with one set to the time just before the next entry in the list.
435
452
 
@@ -445,6 +462,8 @@ You can change the boolean using `--bool=OR` (last entry containing any of the s
445
462
 
446
463
  You can also include a `--no-date` switch to add `@done` without a finish date, meaning no time is tracked for the task. `doing cancel` is an alias for this. Like `finish`, `cancel` accepts a count to act on the last X entries, as well as `--archive` and `--section` options. `cancel` also accepts the `--tag` and `--bool` flags for tag filtering.
447
464
 
465
+ By default `doing finish` works on a single entry, the last entry or the most recent entry matching a `--tag` or `--search` query. Specifying `doing finish 10` would finish any unfinished entries within the last 10 entries. In the case of `--tag` or `--search` queries, the count serves as the maximum number of matches doing will act on, sorted in reverse date order (most recent first). A count of 0 will disable the limit entirely, acting on all matching entries.
466
+
448
467
 
449
468
  ##### Tagging and Autotagging
450
469
 
@@ -576,6 +595,29 @@ Example: Archive all Currently items for _@client_ that are marked _@done_
576
595
 
577
596
  doing archive @client @done
578
597
 
598
+ ##### Importing
599
+
600
+ Doing can currently only import tasks from Timing.app reports. If you want to sync up your Doing file with Timing's tracking:
601
+
602
+ 1. Open Timing and go to Reports
603
+ 2. Set the date span you want to import into doing
604
+ 3. Group by Project, Then by None
605
+ 4. Include Tasks with Title, (not as subgroup), Timespan, and Notes
606
+ 5. Uncheck App Usage
607
+ 6. Set File Format to JSON and Duration format to "XX:YY:ZZ"
608
+ 7. Include short entries if desired
609
+ 8. Export the report to a new file
610
+
611
+ Now you can run `doing import --type timing -s SECTION PATH`, where SECTION is the name of the section you want to import the entries to (defauts to Currently), and PATH is the path to the JSON file. You can also add a tag (or tags) to all entries, or a custom prefix.
612
+
613
+ (`--type timing` is the only option right now, so it doesn't need to be included)
614
+
615
+ # Import entries to Projects section and add @timing to all new entries
616
+ doing import -s Projects --tag=timing "~/Desktop/All Activities.json"
617
+
618
+ # Import to default section (Currently) and prefix entries with '[Imported]'
619
+ doing import --prefix="[Imported]" "~/Desktop/All Activities.json"
620
+
579
621
  ---
580
622
 
581
623
  ## Extras
data/bin/doing CHANGED
@@ -310,7 +310,7 @@ end
310
310
 
311
311
  desc 'Add a completed item with @done(date). No argument finishes last entry.'
312
312
  arg_name 'ENTRY'
313
- command [:done, :did] do |c|
313
+ command %i[done did] do |c|
314
314
  c.desc 'Remove @done tag'
315
315
  c.switch %i[r remove], negatable: false, default_value: false
316
316
 
@@ -367,15 +367,18 @@ command [:done, :did] do |c|
367
367
 
368
368
  date = options[:took] ? finish_date - took : finish_date
369
369
  elsif options[:took]
370
- finish_date = date + took
370
+ finish_date = options[:back] ? date + took : nil
371
371
  elsif options[:back]
372
372
  finish_date = date
373
373
  else
374
374
  finish_date = Time.now
375
375
  end
376
376
 
377
+ if finish_date
378
+ donedate = options[:date] ? "(#{finish_date.strftime('%F %R')})" : ''
379
+ end
380
+
377
381
  section = wwid.guess_section(options[:s]) || options[:s].cap_first
378
- donedate = options[:date] ? "(#{finish_date.strftime('%F %R')})" : ''
379
382
 
380
383
  if options[:e]
381
384
  raise 'No EDITOR variable defined in environment' if ENV['EDITOR'].nil?
@@ -394,8 +397,15 @@ command [:done, :did] do |c|
394
397
  if options[:r]
395
398
  wwid.tag_last({ tags: ['done'], count: 1, section: section, remove: true })
396
399
  else
397
- wwid.tag_last({ tags: ['done'], count: 1, section: section, archive: options[:a], back: finish_date,
398
- date: options[:date] })
400
+ options = { tags: ['done'],
401
+ archive: options[:a],
402
+ back: finish_date,
403
+ count: 1,
404
+ date: options[:date],
405
+ section: section,
406
+ took: took == 0 ? nil : took
407
+ }
408
+ wwid.tag_last(options)
399
409
  end
400
410
  elsif !args.empty?
401
411
  title, note = wwid.format_input(args.join(' '))
@@ -1381,6 +1391,44 @@ command :undo do |c|
1381
1391
  end
1382
1392
  end
1383
1393
 
1394
+ desc 'Import entries from an external source'
1395
+ long_desc 'Imports entries from other sources. Currently only handles JSON reports exported from Timing.app.'
1396
+ arg_name 'PATH'
1397
+ command :import do |c|
1398
+ c.desc 'Import type'
1399
+ c.arg_name 'TYPE'
1400
+ c.flag :type, default_value: 'timing'
1401
+
1402
+ c.desc 'Target section'
1403
+ c.arg_name 'NAME'
1404
+ c.flag %i[s section], default_value: wwid.current_section
1405
+
1406
+ c.desc 'Tag all imported entries'
1407
+ c.arg_name 'TAGS'
1408
+ c.flag :tag
1409
+
1410
+ c.desc 'Prefix entries with'
1411
+ c.arg_name 'PREFIX'
1412
+ c.flag :prefix
1413
+
1414
+ c.desc 'Allow entries that overlap existing times'
1415
+ c.switch [:overlap], negatable: true
1416
+
1417
+ c.action do |_global_options, options, args|
1418
+
1419
+ section = wwid.guess_section(options[:s]) || options[:s].cap_first
1420
+
1421
+ if options[:type] =~ /^tim/i
1422
+ args.each do |path|
1423
+ wwid.import_timing(path, { section: section, tag: options[:tag], prefix: options[:prefix], no_overlap: !options[:overlap] })
1424
+ wwid.write(wwid.doing_file)
1425
+ end
1426
+ else
1427
+ raise 'Invalid import type'
1428
+ end
1429
+ end
1430
+ end
1431
+
1384
1432
  pre do |global, _command, _options, _args|
1385
1433
  if global[:config_file] && global[:config_file] != wwid.config_file
1386
1434
  wwid.config_file = global[:config_file]
data/lib/doing/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Doing
2
- VERSION = '1.0.61'
2
+ VERSION = '1.0.65'
3
3
  end
data/lib/doing/wwid.rb CHANGED
@@ -7,7 +7,7 @@ require 'pp'
7
7
  ##
8
8
  ## @brief Hash helpers
9
9
  ##
10
- class Hash
10
+ class ::Hash
11
11
  def has_tags?(tags, bool = 'AND')
12
12
  tags = tags.split(/ *, */) if tags.is_a? String
13
13
  item = self
@@ -310,7 +310,7 @@ class WWID
310
310
  else
311
311
  @content[section]['items'][current - 1]['note'] = [] unless @content[section]['items'][current - 1].key? 'note'
312
312
 
313
- @content[section]['items'][current - 1]['note'].push(line.gsub(/ *$/, ''))
313
+ @content[section]['items'][current - 1]['note'].push(line.chomp)
314
314
  # end
315
315
  end
316
316
  end
@@ -667,6 +667,96 @@ class WWID
667
667
  @results.push(%(Added "#{entry['title']}" to #{section}))
668
668
  end
669
669
 
670
+ def same_time?(item_a, item_b)
671
+ item_a['date'] == item_b['date'] ? get_interval(item_a, false) == get_interval(item_b, false) : false
672
+ end
673
+
674
+ def overlapping_time?(item_a, item_b)
675
+ return true if same_time?(item_a, item_b)
676
+
677
+ start_a = item_a['date']
678
+ interval = get_interval(item_a, false)
679
+ end_a = interval ? start_a + interval.to_i : start_a
680
+ start_b = item_b['date']
681
+ interval = get_interval(item_b, false)
682
+ end_b = interval ? start_b + interval.to_i : start_b
683
+ (start_a >= start_b && start_a <= end_b) || (end_a >= start_b && end_a <= end_b) || (start_a < start_b && end_a > end_b)
684
+ end
685
+
686
+ def dedup(items, no_overlap = false)
687
+
688
+ combined = []
689
+ @content.each do |_k, v|
690
+ combined += v['items']
691
+ end
692
+
693
+ items.delete_if do |item|
694
+ duped = false
695
+ combined.each do |comp|
696
+ duped = no_overlap ? overlapping_time?(item, comp) : same_time?(item, comp)
697
+ break if duped
698
+ end
699
+ # warn "Skipping overlapping entry: #{item['title']}" if duped
700
+ duped
701
+ end
702
+ end
703
+
704
+ ##
705
+ ## @brief Imports a Timing report
706
+ ##
707
+ ## @param path (String) Path to JSON report file
708
+ ## @param section (String) The section to add to
709
+ ## @param opt (Hash) Additional Options
710
+ ##
711
+ def import_timing(path, opt = {})
712
+ section = opt[:section] || @current_section
713
+ opt[:no_overlap] ||= false
714
+
715
+ add_section(section) unless @content.has_key?(section)
716
+
717
+ add_tags = opt[:tag] ? opt[:tag].split(/[ ,]+/).map { |t| t.sub(/^@?/, '@') }.join(' ') : ''
718
+ prefix = opt[:prefix] ? opt[:prefix] : '[Timing.app]'
719
+ raise "File not found" unless File.exist?(File.expand_path(path))
720
+
721
+ data = JSON.parse(IO.read(File.expand_path(path)))
722
+ new_items = []
723
+ data.each do |entry|
724
+ # Only process task entries
725
+ next if entry.key?('activityType') && entry['activityType'] != 'Task'
726
+ # Only process entries with a start and end date
727
+ next unless entry.key?('startDate') && entry.key?('endDate')
728
+
729
+ # Round down seconds and convert UTC to local time
730
+ start_time = Time.parse(entry['startDate'].sub(/:\d\dZ$/, ':00Z')).getlocal
731
+ end_time = Time.parse(entry['endDate'].sub(/:\d\dZ$/, ':00Z')).getlocal
732
+ next unless start_time && end_time
733
+
734
+ tags = entry['project'].split(/ ▸ /).map {|proj| proj.gsub(/[^a-z0-9]+/i, '').downcase }
735
+ title = "#{prefix} "
736
+ title += entry.key?('activityTitle') && entry['activityTitle'] != '(Untitled Task)' ? entry['activityTitle'] : 'Working on'
737
+ tags.each do |tag|
738
+ if title =~ /\b#{tag}\b/i
739
+ title.sub!(/\b#{tag}\b/i, "@#{tag}")
740
+ else
741
+ title += " @#{tag}"
742
+ end
743
+ end
744
+ title = autotag(title) if @auto_tag
745
+ title += " @done(#{end_time.strftime('%Y-%m-%d %H:%M')})"
746
+ title.gsub!(/ +/, ' ')
747
+ title.strip!
748
+ new_entry = { 'title' => title, 'date' => start_time, 'section' => section }
749
+ new_entry['note'] = entry['notes'].split(/\n/).map(&:chomp) if entry.key?('notes')
750
+ new_items.push(new_entry)
751
+ end
752
+ total = new_items.count
753
+ new_items = dedup(new_items, opt[:no_overlap])
754
+ dups = total - new_items.count
755
+ @results.push(%(Skipped #{dups} items with overlapping times)) if dups > 0
756
+ @content[section]['items'].concat(new_items)
757
+ @results.push(%(Imported #{new_items.count} items to #{section}))
758
+ end
759
+
670
760
  ##
671
761
  ## @brief Return the content of the last note for a given section
672
762
  ##
@@ -776,6 +866,7 @@ class WWID
776
866
  opt[:remove] ||= false
777
867
  opt[:autotag] ||= false
778
868
  opt[:back] ||= false
869
+ opt[:took] ||= nil
779
870
 
780
871
  sec_arr = []
781
872
 
@@ -833,6 +924,13 @@ class WWID
833
924
  else
834
925
  done_date = item['date'] + (opt[:back] - item['date'])
835
926
  end
927
+ elsif opt[:took]
928
+ if item['date'] + opt[:took] > Time.now
929
+ item['date'] = Time.now - opt[:took]
930
+ done_date = Time.now
931
+ else
932
+ done_date = item['date'] + opt[:took]
933
+ end
836
934
  else
837
935
  done_date = Time.now
838
936
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.61
4
+ version: 1.0.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2021-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake