aboutsummaryrefslogtreecommitdiff
path: root/bin/main.ml
blob: a4df7161acdb2333f23d63b2e348afb4ec038076 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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 separately 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 ~marcc/stitch-general@lists.sr.ht." ]
  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 "Stitch currently only works with a system where you have one file per note."
    ; `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 capturing system."
    ; `Pre
        "function capture {\n\
        \  JRNL=\"\\$STITCH_DIRECTORY/\\$(date +'%y-%m-%d.%H:%M.%S').org\"\n\
        \  echo '*  ' > /tmp/capture  \n\
        \  \\$EDITOR /tmp/capture +1\n\
        \  if grep -q '^\\\\*\\\\s*\\$' /tmp/capture \n\
        \  then \n\
        \     echo \"Empty capture; ignoring\"\n\
        \  else \n\
        \     echo \"Storing capture in \\$JRNL\"\n\
        \     cat /tmp/capture > \\$JRNL\n\
        \  fi\n\
         }"
    ; `P
        "Now you can run capture in your terminal and it will prompt you to write your \
         note and store it in your notes with a timestamp."
    ; `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\
        \  TODO_BASE='* TODO  '\n\
        \  JRNL=\"\\$STITCH_DIRECTORY/\\$(date +'%y-%m-%d.%H:%M.%S').org\"\n\
        \  echo '* TODO  ' > /tmp/capture\n\
        \  \\$EDITOR /tmp/capture +1\"\n\
        \  if grep -q '^\\\\* TODO\\\\s*\\$' /tmp/capture \n\
        \  then \n\
        \     echo \"Empty capture\"\n\
        \  else \n\
        \     echo \"Storing capture in \\$JRNL\"\n\
        \     cat /tmp/capture > \\$JRNL\n\
        \  fi\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 commands =
    [ `S "COMMANDS"
    ; `P ""
    ; `P
        "You can run arbitrary commands in Stitch. These commands can make use of the \
         variable substitutions below."
    ; `I ("%(file)", "Currently selected file")
    ; `I ("%(line)", "Currently selected content")
    ]
  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.0.3 ALPHA"
      ~doc
      ~man:
        (List.concat
           [ description; commands; example_set_up_basic; bugs; author; credit ])
  in
  Cmd.v info headlines_t


let () = exit (Cmd.eval headlines_cmd)