Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
8.1 KiB

  1. # copy this into ~/.config/fish/completions/ to enable autocomplete for the watson time tracker
  2. #
  3. function __fish_watson_needs_sub -d "provides a list of sub commands"
  4. set cmd (commandline -opc)
  5. if [ (count $cmd) -eq 1 -a $cmd[1] = 'watson' ]
  6. return 0
  7. end
  8. return 1
  9. end
  10. function __fish_watson_using_command -d "determine if watson is using the passed command"
  11. set cmd (commandline -opc)
  12. if [ (count $cmd) -ge 2 -a $cmd[1] = 'watson' ]
  13. if [ $argv[1] = $cmd[2] ]
  14. return 0
  15. end
  16. return 1
  17. end
  18. return 1
  19. end
  20. function __fish_watson_get_projects -d "return a list of projects"
  21. command watson projects
  22. end
  23. function __fish_watson_get_tags -d "return a list of tags"
  24. command watson tags
  25. end
  26. function __fish_watson_has_project -d "determine if watson is using a passed command and if it has a project"
  27. set cmd (commandline -opc)
  28. if [ (count $cmd) -gt 2 -a $cmd[1] = 'watson' ]
  29. if [ $argv[1] = $cmd[2] ]
  30. if contains "$cmd[3]" (__fish_watson_get_projects)
  31. return 0
  32. end
  33. end
  34. end
  35. return 1
  36. end
  37. function __fish_watson_has_from -d "determine if watson is using a passed command and if it is using from"
  38. set cmd (commandline -opc)
  39. if [ (count $cmd) -gt 2 -a $cmd[1] = 'watson' ]
  40. if [ $argv[1] = $cmd[2] ]
  41. if contains -- "$cmd[3]" -f --from
  42. return 0
  43. end
  44. end
  45. end
  46. return 1
  47. end
  48. function __fish_watson_get_frames -d "return a list of frames" #TODO, use watson logs to get more info
  49. command watson frames
  50. end
  51. function __fish_watson_needs_project -d "check if we need a project"
  52. set cmd (commandline -opc)
  53. if [ (count $cmd) -ge 2 -a $cmd[1] = 'watson' ]
  54. if [ $argv[1] = $cmd[2] ]
  55. for i in $cmd
  56. if contains $i (__fish_watson_get_projects)
  57. return 1 # return 1 because we alredy have a project
  58. end
  59. end
  60. return 0 # we are using $argv as our command and the command does not contain any projects
  61. end
  62. end
  63. return 1
  64. end
  65. # if a backend.url is set, use it in the command description
  66. if [ -e ~/.config/watson/config ]
  67. set url_string (command watson config backend.url 2> /dev/null)
  68. if test -n "$url_string"
  69. set url $url_string
  70. end
  71. else
  72. set url "a remote Crick server"
  73. end
  74. # ungrouped
  75. complete -f -c watson -n '__fish_watson_needs_sub' -a cancel -d "Cancel the last start command"
  76. complete -f -c watson -n '__fish_watson_needs_sub' -a stop -d " Stop monitoring time for the current project"
  77. complete -f -c watson -n '__fish_watson_needs_sub' -a frames -d "Display the list of all frame IDs"
  78. complete -f -c watson -n '__fish_watson_needs_sub' -a help -d "Display help information"
  79. complete -f -c watson -n '__fish_watson_needs_sub' -a projects -d "Display the list of projects"
  80. complete -f -c watson -n '__fish_watson_needs_sub' -a tags -d "Display the list of tags"
  81. complete -f -c watson -n '__fish_watson_needs_sub' -a sync -d "sync your work with $url"
  82. # config
  83. complete -f -c watson -n '__fish_watson_needs_sub' -a config -d "Get and set configuration options"
  84. complete -f -c watson -n '__fish_watson_using_command config' -s e -l edit -d "Edit the config with an editor"
  85. # edit
  86. complete -f -c watson -n '__fish_watson_needs_sub' -a edit -d "Edit a frame"
  87. complete -f -c watson -n '__fish_watson_using_command edit' -a "(__fish_watson_get_frames)"
  88. # log
  89. complete -f -c watson -n '__fish_watson_needs_sub' -a log -d "Display sessions during the given timespan"
  90. complete -f -c watson -n '__fish_watson_using_command log' -s c -l current -d "include the running frame"
  91. complete -f -c watson -n '__fish_watson_using_command log' -s C -l no-current -d "exclude the running frame (default)"
  92. complete -f -c watson -n '__fish_watson_using_command log' -s f -l from -d "Start date for log"
  93. complete -f -c watson -n '__fish_watson_has_from log' -s t -l to -d "end date for log"
  94. complete -f -c watson -n '__fish_watson_using_command log' -s y -l year -d "show the last year"
  95. complete -f -c watson -n '__fish_watson_using_command log' -s m -l month -d "show the last month"
  96. complete -f -c watson -n '__fish_watson_using_command log' -s w -l week -d "show week-to-day"
  97. complete -f -c watson -n '__fish_watson_using_command log' -s d -l day -d "show today"
  98. complete -f -c watson -n '__fish_watson_using_command log' -s a -l all -d "show all"
  99. complete -f -c watson -n '__fish_watson_using_command log' -s p -l project -d "restrict to project" -a "(__fish_watson_get_projects)"
  100. complete -f -c watson -n '__fish_watson_using_command log' -s T -l tag -d "restrict to tag" -a "(__fish_watson_get_tags)"
  101. complete -f -c watson -n '__fish_watson_using_command log' -s j -l json -d "output json"
  102. complete -f -c watson -n '__fish_watson_using_command log' -s g -l pager -d "view through pager"
  103. complete -f -c watson -n '__fish_watson_using_command log' -s G -l no-pager -d "don't vew through pager"
  104. # merge
  105. complete -f -c watson -n '__fish_watson_needs_sub' -a merge -d "merge existing frames with conflicting ones"
  106. complete -f -c watson -n '__fish_watson_using_command merge' -s f -l force -d "silently merge"
  107. # remove
  108. complete -f -c watson -n '__fish_watson_needs_sub' -a remove -d "Remove a frame"
  109. complete -f -c watson -n '__fish_watson_using_command remove' -a "(__fish_watson_get_frames)"
  110. complete -f -c watson -n '__fish_watson_using_command remove' -s f -l force -d "silently remove"
  111. # rename
  112. complete -f -c watson -n '__fish_watson_needs_sub' -a rename -d "Rename a project or tag"
  113. complete -f -c watson -n '__fish_watson_using_command rename' -a "(__fish_watson_get_projects) (__fish_watson_get_tags)"
  114. # report
  115. complete -f -c watson -n '__fish_watson_needs_sub' -a report -d "Display a report of time spent"
  116. complete -f -c watson -n '__fish_watson_using_command report' -s c -l current -d "include the running frame"
  117. complete -f -c watson -n '__fish_watson_using_command report' -s C -l no-current -d "exclude the running frame (default)"
  118. complete -f -c watson -n '__fish_watson_using_command report' -s f -l from -d "Start date for report"
  119. complete -f -c watson -n '__fish_watson_has_from report' -s t -l to -d "end date for report"
  120. complete -f -c watson -n '__fish_watson_using_command report' -s y -l year -d "show the last year"
  121. complete -f -c watson -n '__fish_watson_using_command report' -s m -l month -d "show the last month"
  122. complete -f -c watson -n '__fish_watson_using_command report' -s w -l week -d "show week-to-day"
  123. complete -f -c watson -n '__fish_watson_using_command report' -s d -l day -d "show today"
  124. complete -f -c watson -n '__fish_watson_using_command report' -s a -l all -d "show all"
  125. complete -f -c watson -n '__fish_watson_using_command report' -s p -l project -d "restrict to project" -a "(__fish_watson_get_projects)"
  126. complete -f -c watson -n '__fish_watson_using_command report' -s T -l tag -d "restrict to tag" -a "(__fish_watson_get_tags)"
  127. complete -f -c watson -n '__fish_watson_using_command report' -s j -l json -d "output json"
  128. complete -f -c watson -n '__fish_watson_using_command report' -s g -l pager -d "view through pager"
  129. complete -f -c watson -n '__fish_watson_using_command report' -s G -l no-pager -d "don't vew through pager"
  130. complete -f -c watson -n '__fish_watson_needs_sub' -a restart -d "Restart monitoring time for a stopped project"
  131. complete -f -c watson -n '__fish_watson_using_command restart' -s s -l stop -d "stop running project"
  132. complete -f -c watson -n '__fish_watson_using_command restart' -s S -l no-stop -d "do not stop running project"
  133. complete -f -c watson -n '__fish_watson_using_command restart' -a "(__fish_watson_get_frames)"
  134. # start
  135. complete -f -c watson -n '__fish_watson_needs_sub' -a start -d "Start monitoring time for a project"
  136. complete -f -c watson -n '__fish_watson_needs_project start' -a "(__fish_watson_get_projects)"
  137. complete -f -c watson -n '__fish_watson_has_project start' -a "+(__fish_watson_get_tags)"
  138. # status
  139. complete -f -c watson -n '__fish_watson_needs_sub' -a status -d "Display when the current project was started and time spent"
  140. complete -f -c watson -n '__fish_watson_using_command status' -s p -l project -d "only show project"
  141. complete -f -c watson -n '__fish_watson_using_command status' -s t -l tags -d "only show tags"
  142. complete -f -c watson -n '__fish_watson_using_command status' -s e -l elapsed -d "only show elapsed time"