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.

208 lines
9.5 KiB

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