forked from zk-org/zk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd-new.tesh
131 lines (112 loc) · 4.12 KB
/
cmd-new.tesh
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
$ cd new
# Print help for `zk new`
$ zk new --help
>Usage: zk new [<directory>]
>
>Create a new note in the given notebook directory.
>
>Arguments:
> [<directory>] Directory in which to create the note.
>
>Flags:
> -h, --help Show context-sensitive help.
> --notebook-dir=PATH Turn off notebook auto-discovery and set manually
> the notebook where commands are run.
> -W, --working-dir=PATH Run as if zk was started in <PATH> instead of the
> current working directory.
> --no-input Never prompt or ask for confirmation.
>
> -i, --interactive Read contents from standard input.
> -t, --title=TITLE Title of the new note.
> --date=DATE Set the current date.
> -g, --group=NAME Name of the config group this note belongs to.
> Takes precedence over the config of the
> directory.
> --extra=KEY=VALUE,... Extra variables passed to the templates.
> --template=PATH Custom template used to render the note.
> -p, --print-path Print the path of the created note instead of
> editing it.
> -n, --dry-run Don't actually create the note. Instead, prints
> its content on stdout and the generated path on
> stderr.
> --id=ID Skip id generation and use provided value.
# Default note title.
$ zk new --print-path
>{{working-dir}}/untitled.md
$ cat untitled.md
># Untitled
>
>
# Provide a custom title.
$ zk new --title "Custom title" --print-path
>{{working-dir}}/custom-title.md
$ cat custom-title.md
># Custom title
>
>
# Provide a custom note id
$ zk new --group id --id 123abc --dry-run
2>{{working-dir}}/123abc.md
# Provide a custom title (short flag).
$ zk new -t "Another custom title" -p
>{{working-dir}}/another-custom-title.md
# Opens the editor after creating a new note.
$ EDITOR="echo 'edit'" zk new --title "Edit"
>edit {{working-dir}}/edit.md
# Prints the path of newly created note instead of editing it.
$ EDITOR="echo 'edit'" zk new --title "Print path" --print-path
>{{working-dir}}/print-path.md
# Set explicitely today's date (natural dates).
$ zk new --group date --date "January 2nd" --dry-run
2>{{working-dir}}/02-01.md
$ zk new --group date --date "December 24th" --dry-run
2>{{working-dir}}/24-12.md
# Set explicitely today's date (RFC 3339)
$ zk new --group date-raw --date "2022-01-23T13:55:48+01:00" --dry-run
2>{{working-dir}}/2022-01-23 13:55:48 +0100 {{match ".+"}}.md
$ zk new --group date-raw --date "2022-02-17T17:53:12" --dry-run
2>{{working-dir}}/2022-02-17 17:53:12 {{match ".+"}}.md
$ zk new --group date-raw --date "2022-02-17T17:53" --dry-run
2>{{working-dir}}/2022-02-17 17:53:00 {{match ".+"}}.md
$ zk new --group date-raw --date "2022-02-17" --dry-run
2>{{working-dir}}/2022-02-17 00:00:00 {{match ".+"}}.md
$ zk new --group date-raw --date "2022-02" --dry-run
2>{{working-dir}}/2022-02-01 00:00:00 {{match ".+"}}.md
$ zk new --group date-raw --date "2022" --dry-run
2>{{working-dir}}/2022-01-01 00:00:00 {{match ".+"}}.md
# Dry run doesn't write the note.
$ zk new --dry-run --title "Dry run"
># Dry run
>
>
2>{{working-dir}}/dry-run.md
1$ cat dry-run.md
2>cat: dry-run.md: No such file or directory
# Dry run (short flag).
$ zk new -n --title "Dry run"
># Dry run
>
>
2>{{working-dir}}/dry-run.md
# Pipe content in a new note.
$ echo "Content of the note" | EDITOR=cat zk new --interactive --title "Piped note"
># Piped note
>
>Content of the note
>
# Redirect file to standard input when creating a new note.
$ echo "Content of the note" > input
$ EDITOR=cat zk new --interactive --title "Note from redirected input" < input
># Note from redirected input
>
>Content of the note
>
# Existing notes are not overwritten, but can be edited.
$ zk new --force-input n --title "Piped note"
>? piped-note.md already exists, do you want to edit this note instead? (y/N)
# Check that the content was not overwritten
$ cat piped-note.md
># Piped note
>
>Content of the note
>