25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

94 lines
2.4KB

  1. #!/usr/bin/fish
  2. set timer_folder ~/.timer
  3. set activity_lists_folder $timer_folder/activity.lists
  4. set activity_timeclock_file $timer_folder/activity.timeclock
  5. set activity_i3blocks_pipe $timer_folder/activity.i3blocks.fifo
  6. set activity_current_file $timer_folder/activity.current
  7. set activity_timeclock_append_log_folder $timer_folder/activity.timeclock.d
  8. set activity_timeclock_append_log_filename $activity_timeclock_append_log_folder/(date +%Y-%m-%d)-(hostname)
  9. function parse_activity_timeclock
  10. sort -k2 | uniq \
  11. |begin
  12. set state o
  13. while read -L line
  14. set io (string sub -l 1 "$line")
  15. set date (string sub -s 3 -l 10 "$line")
  16. set time (string sub -s 14 -l 8 "$line")
  17. if [ $state = 'i' ]
  18. echo "o $date $time"
  19. end
  20. if [ $io = 'i' ]
  21. set state i
  22. set rs (string sub -s 23 "$line")
  23. string match -r '^(.+?)(?: (.+?))? *(?:;.*)?$' "$rs" \
  24. |begin
  25. read -L null
  26. read -L activity
  27. read -L payee
  28. end
  29. echo "i $date $time $rs"
  30. else if [ $io = 'o' ]
  31. set state o
  32. end
  33. end
  34. end
  35. if [ $state = 'i' ]
  36. echo $activity > $activity_current_file
  37. echo "<span foreground=\"#00FF00\">★ $activity</span>" > $activity_i3blocks_pipe
  38. else
  39. rm $activity_current_file
  40. echo "<span foreground=\"#0000FF\">☆</span>" > $activity_i3blocks_pipe
  41. end
  42. end
  43. function merge_timeclock_append_log
  44. cat $activity_timeclock_append_log_folder/* | parse_activity_timeclock > $activity_timeclock_file
  45. end
  46. function get_current_timeclock_state
  47. merge_timeclock_append_log
  48. end
  49. function select_activity
  50. set next (cat $activity_lists_folder/* | rofi -dmenu -p activity)
  51. if [ ! -n "$next" ]
  52. exit 1
  53. end
  54. begin_activity "$next"
  55. end
  56. function begin_activity
  57. echo i (date '+%Y-%m-%d %H:%M:%S') $argv >> $activity_timeclock_append_log_filename
  58. echo "<span foreground=\"#00FF00\">★ $argv</span>" > $activity_i3blocks_pipe
  59. end
  60. function end_activity
  61. echo o (date '+%Y-%m-%d %H:%M:%S') >> $activity_timeclock_append_log_filename
  62. echo "<span foreground=\"#0000FF\">☆</span>" > $activity_i3blocks_pipe
  63. end
  64. set command $argv[1]
  65. switch $command
  66. case "select_activity"
  67. select_activity
  68. case "begin_activity"
  69. begin_activity $argv[2..-1]
  70. case "end_activity"
  71. end_activity
  72. case "show_activity"
  73. get_current_timeclock_state
  74. case "uniklinik"
  75. begin_activity 'Arbeit:Uniklinik Köln'
  76. end