doing 1.0.80 → 1.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83c61397f2a1827dbe04f16255c1739c8d6a194b636afa4b1181437ffaca2ee8
4
- data.tar.gz: b5da9fcae50fb7c90ba70a4b3d28948f551945c92170559f8bb693cda921894b
3
+ metadata.gz: 860b1b1c3f8f1ffd33fc344cabb37a7a060cdcb80d54f65a8f3598450b4c22cf
4
+ data.tar.gz: 83767946e503d9bd2515aa99a7e11de87c2910f48a1b2c6e5a745c9e7dada0be
5
5
  SHA512:
6
- metadata.gz: 181eb1fa0f18e0f4c7678e48b2ae8daf07a85e88842accdf3de7c522dbc022c175067e0226d9faa21e493a654175c80595df1853d97027d6708884cbe24f82e6
7
- data.tar.gz: a472b2013051b3525af41577ea0020b5f43e720e2b5d8598eb07b229555310dadd7a1b2cc0a106763def82f2b1920a9acf41f9ac07d077f35543b0b90ed2a631
6
+ metadata.gz: d78baf84b0bef668b7c877e908b6f1ee4ea05ce3914735f8d2e069abed215dfe5c9fc1fc3a9eb0dc5e4f5e251420d2454fb14a1b7465a5df8cf688e4b16b24ef
7
+ data.tar.gz: b38cf4b873baeb35ecab15ef10b3c1b8be4a7d2e28f9b34511d30f50def0b47ef127829bc5755bb0b2ba424183959dd009a222958df03ee8e54680e2ce267ab6
data/bin/doing CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby -W1
2
2
  # frozen_string_literal: true
3
3
 
4
4
  $LOAD_PATH.unshift File.join(__dir__, '..', 'lib')
@@ -301,6 +301,9 @@ command :select do |c|
301
301
  c.desc 'Add flag to selected item(s)'
302
302
  c.switch %i[flag], negatable: false, default_value: false
303
303
 
304
+ c.desc 'Perform action without confirmation'
305
+ c.switch %i[force], negatable: false, default_value: false
306
+
304
307
  c.desc 'Save selected entries to file using --output format'
305
308
  c.arg_name 'FILE'
306
309
  c.flag %i[save_to]
@@ -1306,7 +1309,8 @@ desc 'Select a section to display from a menu'
1306
1309
  command :choose do |c|
1307
1310
  c.action do |_global_options, _options, _args|
1308
1311
  section = wwid.choose_section
1309
- puts wwid.list_section({ section: section.cap_first, count: 0 })
1312
+
1313
+ puts wwid.list_section({ section: section.cap_first, count: 0 }) if section
1310
1314
  end
1311
1315
  end
1312
1316
 
data/lib/doing/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Doing
2
- VERSION = '1.0.80'
2
+ VERSION = '1.0.81'
3
3
  end
data/lib/doing/wwid.rb CHANGED
@@ -757,7 +757,7 @@ class WWID
757
757
  all_items.concat(@content[section]['items'].dup) if @content.key?(section)
758
758
  end
759
759
 
760
- if opt[:tag] && opt[:tag].length.positive?
760
+ if opt[:tag]&.length
761
761
  all_items.select! { |item| item.has_tags?(opt[:tag], opt[:tag_bool]) }
762
762
  elsif opt[:search]&.length
763
763
  all_items.select! { |item| item.matches_search?(opt[:search]) }
@@ -771,9 +771,14 @@ class WWID
771
771
  ##
772
772
  ## @return (String) The selected option
773
773
  ##
774
- def choose_from(options, prompt)
774
+ def choose_from(options, prompt: 'Make a selection: ', multiple: false, fzf_args: [])
775
775
  fzf = File.join(File.dirname(__FILE__), '../helpers/fuzzyfilefinder')
776
- res = `echo #{Shellwords.escape(options.join("\n"))}|#{fzf} --prompt "#{prompt}"`
776
+ fzf_args << '-1'
777
+ fzf_args << %(--prompt "#{prompt}")
778
+ fzf_args << '--multi' if multiple
779
+ header = "esc: cancel,#{multiple ? ' tab: multi-select, ctrl-a: select all,' : ''} return: confirm"
780
+ fzf_args << %(--header "#{header}")
781
+ res = `echo #{Shellwords.escape(options.join("\n"))}|#{fzf} #{fzf_args.join(' ')}`
777
782
  return false if res.strip.size.zero?
778
783
 
779
784
  res
@@ -807,7 +812,7 @@ class WWID
807
812
  ') ',
808
813
  item['date'],
809
814
  ' | ',
810
- item['title'],
815
+ item['title']
811
816
  ]
812
817
  if opt[:section] =~ /^all/i
813
818
  out.concat([
@@ -818,8 +823,15 @@ class WWID
818
823
  end
819
824
  out.join('')
820
825
  end
821
-
822
- res = `echo #{Shellwords.escape(options.join("\n"))}|#{fzf} --header="Arrows to navigate, tab to mark for selection, enter to perform action" --prompt="Select entries to act on> " -m --bind ctrl-a:select-all -q "#{opt[:query]}"`
826
+ fzf_args = [
827
+ %(--header="Arrows: navigate, tab: mark for selection, ctrl-a: select all, enter: commit"),
828
+ %(--prompt="Select entries to act on > "),
829
+ '-1',
830
+ '-m',
831
+ '--bind ctrl-a:select-all',
832
+ %(-q "#{opt[:query]}")
833
+ ]
834
+ res = `echo #{Shellwords.escape(options.join("\n"))}|#{fzf} #{fzf_args.join(' ')}`
823
835
  selected = []
824
836
  res.split(/\n/).each do |item|
825
837
  idx = item.match(/^(\d+)\)/)[1].to_i
@@ -841,62 +853,71 @@ class WWID
841
853
  end
842
854
 
843
855
  unless has_action
844
- action = choose_from(
845
- [
846
- 'add tag',
847
- 'remove tag',
848
- 'archive',
849
- 'cancel',
850
- 'delete',
851
- 'edit',
852
- 'finish',
853
- 'flag',
854
- 'move',
855
- 'output format'
856
- ],
857
- 'What do you want to do with the selected items? > ')
858
- case action
859
- when /(add|remove) tag/
860
- print 'Enter tag: '
861
- tag = STDIN.gets
862
- return if tag =~ /^ *$/
863
- opt[:tag] = tag.strip
864
- opt[:remove] = true if action =~ /remove tag/
865
- when /output format/
866
- output_format = choose_from(%w[doing taskpaper json timeline html csv], 'Which output format? > ')
867
- return if tag =~ /^ *$/
868
- opt[:output] = output_format.strip
869
- res = yn('Save to file?', default_response: 'n')
870
- if res
871
- print 'File path/name: '
872
- filename = STDIN.gets.strip
873
- return if filename.empty?
874
- opt[:save_to] = filename
856
+ choice = choose_from([
857
+ 'add tag',
858
+ 'remove tag',
859
+ 'cancel',
860
+ 'delete',
861
+ 'finish',
862
+ 'flag',
863
+ 'archive',
864
+ 'move',
865
+ 'edit',
866
+ 'output formatted'
867
+ ],
868
+ prompt: 'What do you want to do with the selected items? > ',
869
+ multiple: true,
870
+ fzf_args: ['--height=60%', '--tac', '--no-sort'])
871
+ return unless choice
872
+
873
+ to_do = choice.strip.split(/\n/)
874
+ to_do.each do |action|
875
+ case action
876
+ when /(add|remove) tag/
877
+ type = action =~ /^add/ ? 'add' : 'remove'
878
+ if opt[:tag]
879
+ warn "'add tag' and 'remove tag' can not be used together"
880
+ Process.exit 1
881
+ end
882
+ print "#{colors['yellow']}Tag to #{type}: #{colors['reset']}"
883
+ tag = STDIN.gets
884
+ return if tag =~ /^ *$/
885
+ opt[:tag] = tag.strip.sub(/^@/, '')
886
+ opt[:remove] = true if type == 'remove'
887
+ when /output formatted/
888
+ output_format = choose_from(%w[doing taskpaper json timeline html csv].sort, prompt: 'Which output format? > ', fzf_args: ['--height=60%', '--tac', '--no-sort'])
889
+ return if tag =~ /^ *$/
890
+ opt[:output] = output_format.strip
891
+ res = opt[:force] ? false : yn('Save to file?', default_response: 'n')
892
+ if res
893
+ print "#{colors['yellow']}File path/name: #{colors['reset']}"
894
+ filename = STDIN.gets.strip
895
+ return if filename.empty?
896
+ opt[:save_to] = filename
897
+ end
898
+ when /archive/
899
+ opt[:archive] = true
900
+ when /delete/
901
+ opt[:delete] = true
902
+ when /edit/
903
+ opt[:editor] = true
904
+ when /finish/
905
+ opt[:finish] = true
906
+ when /cancel/
907
+ opt[:cancel] = true
908
+ when /move/
909
+ section = choose_section.strip
910
+ opt[:move] = section.strip unless section =~ /^ *$/
911
+ when /flag/
912
+ opt[:flag] = true
875
913
  end
876
- when /archive/
877
- opt[:archive] = true
878
- when /delete/
879
- opt[:delete] = true
880
- when /edit/
881
- opt[:editor] = true
882
- when /finish/
883
- opt[:finish] = true
884
- when /cancel/
885
- opt[:cancel] = true
886
- when /move/
887
- section = choose_section.strip
888
- return if section =~ /^ *$/
889
- opt[:move] = section.strip
890
- when /flag/
891
- opt[:flag] = true
892
914
  end
893
915
  end
894
916
 
895
-
896
917
  if opt[:delete]
897
- res = yn("Delete #{selected.size} items?", default_response: 'y')
918
+ res = opt[:force] ? true : yn("Delete #{selected.size} items?", default_response: 'y')
898
919
  if res
899
- selected.each {|item| delete_item(item) }
920
+ selected.each { |item| delete_item(item) }
900
921
  write(@doing_file)
901
922
  end
902
923
  return
@@ -990,13 +1011,16 @@ class WWID
990
1011
  item
991
1012
  end
992
1013
 
993
- @content = {'Export' => {'original' => 'Export:', 'items' => selected}}
994
- options = {section: 'Export'}
1014
+ @content = { 'Export' => { 'original' => 'Export:', 'items' => selected } }
1015
+ options = { section: 'Export' }
995
1016
 
996
- if opt[:output] !~ /(doing|taskpaper)/
997
- options[:output] = opt[:output]
998
- else
1017
+ case opt[:output]
1018
+ when /doing/
999
1019
  options[:template] = '- %date | %title%note'
1020
+ when /taskpaper/
1021
+ options[:template] = '- %title @date(%date)%note'
1022
+ else
1023
+ options[:output] = opt[:output]
1000
1024
  end
1001
1025
 
1002
1026
  output = list_section(options)
@@ -1078,7 +1102,6 @@ class WWID
1078
1102
  count = (opt[:count]).zero? ? items.length : opt[:count]
1079
1103
  items.map! do |item|
1080
1104
  break if idx == count
1081
-
1082
1105
  finished = opt[:unfinished] && item.has_tags?('done', :and)
1083
1106
  tag_match = opt[:tag].nil? || opt[:tag].empty? ? true : item.has_tags?(opt[:tag], opt[:tag_bool])
1084
1107
  search_match = opt[:search].nil? || opt[:search].empty? ? true : item.matches_search?(opt[:search])
@@ -1503,7 +1526,8 @@ class WWID
1503
1526
  ## @return (String) The selected section name
1504
1527
  ##
1505
1528
  def choose_section
1506
- choose_from(sections, 'Choose a section > ').strip
1529
+ choice = choose_from(sections.sort, prompt: 'Choose a section > ', fzf_args: ['--height=60%'])
1530
+ choice ? choice.strip : choice
1507
1531
  end
1508
1532
 
1509
1533
  ##
@@ -1521,7 +1545,8 @@ class WWID
1521
1545
  ## @return (String) The selected view name
1522
1546
  ##
1523
1547
  def choose_view
1524
- choose_from(views, 'Choose a view > ').strip
1548
+ choice = choose_from(views.sort, prompt: 'Choose a view > ', fzf_args: ['--height=60%'])
1549
+ choice ? choice.strip : choice
1525
1550
  end
1526
1551
 
1527
1552
  ##
data/lib/doing.rb CHANGED
@@ -8,5 +8,6 @@ require 'tempfile'
8
8
  require 'chronic'
9
9
  require 'haml'
10
10
  require 'json'
11
- require 'doing/helpers.rb'
12
- require 'doing/wwid.rb'
11
+ require 'doing/helpers'
12
+ require 'doing/wwid'
13
+ require 'doing/markdown_document_listener'
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.80
4
+ version: 1.0.81
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-09-25 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake