aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: 1708f13047314923378116d97ef0cd461f22a673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
open Cmdliner

let tag_arg =
  let doc = "Search entries for a given tag." in
  Arg.(value & opt string "" & info [ "t"; "tag" ] ~docv:"TAG" ~doc)


let headlines_t = Term.(const Stitch.start $ tag_arg $ const ())

let envs =
  let docs = Cmdliner.Manpage.s_environment in
  [ Cmd.Env.info
      ~docs
      ~doc:
        "Directory where Stitch should search for notes. Needs to be set in order for \
         the program to work. Must be absolute path, I.E /home/bob/notes"
      "STITCH_DIRECTORY"
  ; Cmd.Env.info
      ~docs
      ~doc:
        "Grep command to use (defaults to \"grep\"). Stitch also works well with ugrep, \
         which greatly speeds up the program."
      "STITCH_GREP_CMD"
  ; Cmd.Env.info
      ~docs
      ~doc:"Pattern to use for headlines. (Default \"* \")"
      "STITCH_HEADLINE_PATTERN"
  ; Cmd.Env.info
      ~docs
      ~doc:
        "Pattern to use by grep to fetch headlines. Needs to be double escaped for \
         OCaml. (Default \"^\\\\* \")"
      "STITCH_HEADLINE_PATTERN_REGEXP"
  ; Cmd.Env.info
      ~docs
      ~doc:"Pattern used by grep to find tags. (Default \":[a-z-]+:\", matches :a-tag:"
      "STITCH_TAG_PATTERN"
  ; Cmd.Env.info
      ~docs
      ~doc:"Pattern for TODOS. Used for substitution. (Default \"* TODO\")"
      "STITCH_TODO"
  ; Cmd.Env.info
      ~docs
      ~doc:
        "Regexp used by grep to find TODO items. Needs to be double escaped for OCaml. \
         (Default \"^\\\\* TODO\")"
      "STITCH_TODO_REGEXP"
  ; Cmd.Env.info
      ~docs
      ~doc:"Pattern for DONE items. Used for substitution. (Default \"* DONE\")"
      "STITCH_DONE"
  ; Cmd.Env.info
      ~docs
      ~doc:
        "Regexp used by grep to find DONE items. Needs to be double escaped for OCaml. \
         (Default \"^\\\\* DONE\")"
      "STITCH_DONE_REGEXP"
  ]


let headlines_cmd =
  let doc = "write notes seperately and compose" in
  let author = [ `S Manpage.s_authors; `P "Marc Coquand (mccd.space)" ] in
  let bugs = [ `S Manpage.s_bugs; `P "Email bug reports to marc@mccd.space" ] in
  let description =
    [ `S Manpage.s_description
    ; `P
        "Stitch is a minimal note and todo composing tool inspired by Howm for Emacs. It \
         works with any CLI editor and file format."
    ; `P
        "Stitch comes preconfigured to handle an org-esque file format, but can be \
         reconfigured to handle any file format you want (SEE ENVIRONMENT).  "
    ; `P
        "To set up, you will need to set STITCH_DIRECTORY (SEE ENVIRONMENT) at minimum. \
         Stitch does not come with any built-in note-capturing tool, but you can easily \
         set one up on your own (SEE EXAMPLES)."
    ; `P
        "When you enter the program for the first time, press '?' to see the list of \
         keybindings."
    ]
  in
  let example_set_up_basic =
    [ `S Manpage.s_examples
    ; `P "To get started, start by setting up a note directory in your shell profile"
    ; `Pre "export STITCH_DIRECTORY=/home/bob/notes"
    ; `P
        "Stitch does not specify anything on how to capture your notes, but you can add \
         the following in your profile to have a basic note capture command"
    ; `Pre
        "function capture {\n\
        \  NEW_NOTE=\"\\$STITCH_DIRECTORY/\\$(date +'%y-%m-%d.%H:%M.%S').org\"\n\
        \  echo '*  ' >> \\$NEW_NOTE \n\
        \  \\$EDITOR \"\\$NEW_NOTE\" +1:3 \"\n\
         }\n"
    ; `P
        "With that, you can begin to capture your notes and they will be displayed in \
         reverse chronological order in stitch. You can add tags, for example :journal: \
         and :work:."
    ; `P
        "Once added, you can start viewing your notes in Stitch. So if you added a few \
         journal notes, you can view them with"
    ; `Pre "stitch -t :journal:"
    ; `P
        "If you press s, you will see toggle to see all notes stitched together. You can \
         see all commands with '?'"
    ; `P "You can also launch stitch without arguments to see all."
    ; `P
        "To set up TODO capturing, you can add a command to your shell profile to \
         capture TODO items"
    ; `Pre
        "function todo {\n\
        \  NEW_NOTE=\"\\$STITCH_DIRECTORY/\\$(date +'%y-%m-%d.%H:%M.%S').org\"\n\
        \  echo '* TODO  ' >> \\$NEW_NOTE \n\
        \  \\$EDITOR \"\\$NEW_NOTE\" +1 \n\
         }"
    ; `P
        "After that, you can capture a few TODO items, and you will be able to view them \
         if you press 2. You can see done items if you press 3. Press '?' to see how to \
         toggle the todo items."
    ]
  in
  let credit =
    [ `S "CREDIT"
    ; `P "Stitch was inspired by the note-taking tool Howm for EMacs by HIRAOKA Kazuyuki."
    ]
  in
  let info =
    Cmd.info
      ~envs
      "stitch"
      ~version:"0.1 ALPHA"
      ~doc
      ~man:(List.concat [ bugs; author; description; example_set_up_basic; credit ])
  in
  Cmd.v info headlines_t


let () = exit (Cmd.eval headlines_cmd)