bkmr 7.0.0

A Unified CLI Tool for Bookmark, Snippet, and Knowledge Management
Documentation
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
// src/cli/args.rs
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser, Clone)]
#[command(author, version, about, long_about = None)]
#[command(arg_required_else_help = true, disable_help_subcommand = true)]
/// A bookmark manager for the terminal
pub struct Cli {
    /// Optional name to operate on
    pub name: Option<String>,

    /// Sets a custom config file
    #[arg(short, long, value_name = "FILE")]
    pub config: Option<PathBuf>,

    /// Turn debugging information on
    #[arg(short, long, action = clap::ArgAction::Count)]
    pub debug: u8,

    #[arg(long = "no-color", help = "Disable colored output")]
    pub no_color: bool,

    #[arg(
        long = "generate-config",
        help = "bkmr --generate-config > ~/.config/bkmr/config.toml"
    )]
    pub generate_config: bool,

    #[command(subcommand)]
    pub command: Option<Commands>,
}

#[derive(Subcommand, Clone)]
pub enum Commands {
    /// Searches Bookmarks
    Search {
        /// FTS query (full text search)
        fts_query: Option<String>,

        #[arg(
            short = 'e',
            long = "exact",
            help = "match exact, comma separated list"
        )]
        tags_exact: Option<String>,

        #[arg(long = "exact-prefix", help = "tags to prefix the exact option")]
        tags_exact_prefix: Option<String>,

        #[arg(short = 't', long = "tags", help = "match all, comma separated list")]
        tags_all: Option<String>,

        #[arg(long = "tags-prefix", help = "tags to prefix the tags option")]
        tags_all_prefix: Option<String>,

        #[arg(
            short = 'T',
            long = "Tags",
            help = "not match all, comma separated list"
        )]
        tags_all_not: Option<String>,

        #[arg(long = "Tags-prefix", help = "tags to prefix the Tags option")]
        tags_all_not_prefix: Option<String>,

        #[arg(short = 'n', long = "ntags", help = "match any, comma separated list")]
        tags_any: Option<String>,

        #[arg(long = "ntags-prefix", help = "tags to prefix the ntags option")]
        tags_any_prefix: Option<String>,

        #[arg(
            short = 'N',
            long = "Ntags",
            help = "not match any, comma separated list"
        )]
        tags_any_not: Option<String>,

        #[arg(long = "Ntags-prefix", help = "tags to prefix the Ntags option")]
        tags_any_not_prefix: Option<String>,

        #[arg(short = 'o', long = "descending", help = "sort descending (implies --sort modified if no --sort given)")]
        order_desc: bool,

        #[arg(short = 'O', long = "ascending", help = "sort ascending (implies --sort modified if no --sort given)")]
        order_asc: bool,

        #[arg(long = "sort", help = "sort field: id, title, modified (default: id). Without -o/-O, id/title default ascending, modified defaults descending")]
        sort_field: Option<String>,

        #[arg(long = "np", help = "no prompt")]
        non_interactive: bool,

        #[arg(
            long = "fzf",
            help = "use fuzzy finder: [CTRL-O: copy to clipboard (shell scripts: copy 'bkmr open --no-edit <id> --' command), CTRL-E: edit, CTRL-D: delete, CTRL-A: clone, CTRL-P: show details, ENTER: open]"
        )]
        is_fuzzy: bool,

        #[arg(
            long = "fzf-style",
            help = "fuzzy finder style: classic or enhanced",
            default_value = "classic"
        )]
        fzf_style: Option<String>,

        #[arg(long = "json", help = "non-interactive mode, output as json")]
        is_json: bool,

        #[arg(short = 'l', long = "limit", help = "limit number of results")]
        limit: Option<i32>,

        #[arg(
            long = "interpolate",
            help = "process template interpolation in search results display (not needed for FZF mode or bookmark actions - they interpolate automatically)"
        )]
        interpolate: bool,

        #[arg(
            long = "shell-stubs",
            help = "output shell function stubs for shell script bookmarks (automatically filters for _shell_ type)"
        )]
        shell_stubs: bool,

        #[arg(
            long = "stdout",
            help = "output selected bookmark content to stdout instead of executing (for shell wrapper integration)"
        )]
        stdout: bool,

        #[arg(long = "embeddable", help = "filter to show only embeddable bookmarks")]
        embeddable: bool,
    },
    /// Hybrid Search combining FTS and semantic search with RRF fusion
    #[command(name = "hsearch")]
    HSearch {
        /// Search query text
        query: String,

        #[arg(short = 't', long = "tags", help = "all-of tag filter (comma-separated)")]
        tags_all: Option<String>,

        #[arg(short = 'T', long = "Tags", help = "exclude-all tag filter")]
        tags_all_not: Option<String>,

        #[arg(short = 'n', long = "ntags", help = "any-of tag filter")]
        tags_any: Option<String>,

        #[arg(short = 'N', long = "Ntags", help = "exclude-any tag filter")]
        tags_any_not: Option<String>,

        #[arg(short = 'e', long = "exact", help = "exact tag match")]
        tags_exact: Option<String>,

        #[arg(long = "mode", default_value = "hybrid", help = "search mode: hybrid or exact")]
        mode: String,

        #[arg(short = 'l', long = "limit", help = "limit number of results")]
        limit: Option<i32>,

        #[arg(long = "json", help = "output as JSON (includes rrf_score)")]
        is_json: bool,

        #[arg(long = "fzf", help = "use fzf for interactive selection")]
        is_fuzzy: bool,

        #[arg(long = "stdout", help = "output to stdout for piping")]
        stdout: bool,

        #[arg(long = "np", help = "no prompt")]
        non_interactive: bool,
    },
    /// Semantic Search using local embeddings
    SemSearch {
        /// Input for similarity search (search terms)
        query: String,

        #[arg(short = 'l', long = "limit", help = "limit number of results")]
        limit: Option<i32>,

        #[arg(long = "np", help = "no prompt")]
        non_interactive: bool,
    },
    /// Open/launch bookmarks or view files
    Open {
        /// list of ids, separated by comma, no blanks OR file path when used with --file
        ids: String,
        #[arg(long = "no-edit", help = "skip interactive editing for shell scripts")]
        no_edit: bool,
        #[arg(
            long = "file",
            help = "treat ids parameter as file path for direct viewing"
        )]
        file: bool,
        #[arg(
            last = true,
            help = "Arguments to pass to shell scripts (use -- to separate: bkmr open ID -- arg1 arg2)"
        )]
        script_args: Vec<String>,

        #[arg(
            long = "stdout",
            help = "output bookmark content to stdout instead of executing"
        )]
        stdout: bool,
    },
    /// Add a bookmark
    Add {
        url: Option<String>,
        /// list of tags, separated by comma, no blanks in between
        tags: Option<String>,
        #[arg(long = "title", help = "title")]
        title: Option<String>,
        #[arg(short = 'd', long = "description", help = "title")]
        desc: Option<String>,
        #[arg(long = "no-web", help = "do not fetch URL data")]
        no_web: bool,
        #[arg(short = 'e', long = "edit", help = "edit the bookmark while adding")]
        edit: bool,
        #[arg(
            short = 't',
            long = "type",
            help = "bookmark type (uri, snip, text, shell, md, env)",
            default_value = "uri"
        )]
        bookmark_type: String,
        #[arg(short = 'c', long = "clone", help = "clone an existing bookmark by ID")]
        clone_id: Option<i32>,
        #[arg(long = "stdin", help = "read content from stdin into url field")]
        stdin: bool,
        #[arg(
            long = "open-with",
            help = "custom command to open this bookmark (replaces default open behavior)"
        )]
        open_with: Option<String>,
    },
    /// Delete bookmarks
    Delete {
        /// list of ids, separated by comma, no blanks
        ids: String,
    },
    /// Update bookmarks
    Update {
        /// list of ids, separated by comma, no blanks
        ids: String,
        #[arg(short = 't', long = "tags", help = "add tags to taglist")]
        tags: Option<String>,
        #[arg(short = 'n', long = "ntags", help = "remove tags from taglist")]
        tags_not: Option<String>,
        #[arg(short = 'f', long = "force", help = "overwrite taglist with tags")]
        force: bool,
        #[arg(
            long = "open-with",
            help = "set custom command to open this bookmark (use empty string to clear)"
        )]
        open_with: Option<String>,
    },
    /// Edit bookmarks
    Edit {
        /// Edit bookmarks, list of ids, separated by comma, no blanks
        ids: String,
        #[arg(
            long = "force-db",
            help = "force edit database content instead of source file for file-imported bookmarks"
        )]
        force_db: bool,
    },
    /// Show Bookmarks (list of ids, separated by comma, no blanks)
    Show {
        ids: String,
        #[arg(long = "json", help = "output as json")]
        is_json: bool,
    },
    /// Opens n random URLs
    Surprise {
        #[arg(short = 'n', help = "number of URLs to open", default_value_t = 1)]
        n: i32,
    },
    /// Tag for which related tags should be shown. No input: all tags are printed
    Tags {
        /// Tag for which related tags should be shown. No input: all tags are shown
        tag: Option<String>,
    },
    /// Initialize bookmark database
    CreateDb {
        /// pathname to database file (optional, uses config path if not provided)
        #[arg(help = "Path where the database will be created (default: ~/.config/bkmr/bkmr.db)")]
        path: Option<String>,

        #[arg(long, help = "Pre-fill the database with demo entries")]
        pre_fill: bool,
    },
    /// Set whether a bookmark can be embedded (used for semantic search)
    SetEmbeddable {
        /// ID of the bookmark
        id: i32,

        #[arg(long = "enable", help = "Enable embedding for this bookmark")]
        enable: bool,

        #[arg(long = "disable", help = "Disable embedding for this bookmark")]
        disable: bool,
    },
    /// Backfill embeddings for bookmarks that are marked embeddable but lack embeddings.
    Backfill {
        #[arg(short = 'd', long = "dry-run", help = "only show what would be done")]
        dry_run: bool,

        #[arg(
            short = 'f',
            long = "force",
            help = "force recompute of all embeddings (except _imported_)"
        )]
        force: bool,
    },
    /// Load bookmarks from JSON array file
    LoadJson {
        /// Path to the JSON file containing an array of bookmark objects
        #[arg(help = "Path to JSON file with an array of bookmark objects")]
        path: String,

        #[arg(short = 'd', long = "dry-run", help = "only show what would be done")]
        dry_run: bool,
    },

    /// Load texts for semantic similarity search as bookmarks.
    /// The actual content of the file is not stored in the database, only the embeddings.
    LoadTexts {
        #[arg(short = 'd', long = "dry-run", help = "only show what would be done")]
        dry_run: bool,

        #[arg(
            short = 'f',
            long = "force",
            help = "force update embeddings even if content has not changed"
        )]
        force: bool,

        /// Path to NDJSON file containing text documents (one per line)
        #[arg(help = "Path to NDJSON file with text documents (one JSON object per line)")]
        path: String,
    },

    /// Import files from directories, parsing frontmatter metadata.
    ///
    /// Supported file types: .sh (shell scripts), .py (python scripts), .md (markdown files)
    ///
    /// Required frontmatter format (YAML):
    /// ---
    /// name: "Script Name"        # Required: bookmark title
    /// tags: ["tag1", "tag2"]     # Optional: comma-separated tags  
    /// type: "_shell_"            # Optional: content type (_shell_, _md_, _snip_)
    /// ---
    ///
    /// Or hash-style format (for scripts):
    /// #!/bin/bash
    /// # name: Script Name
    /// # tags: tag1, tag2
    /// # type: _shell_
    ImportFiles {
        /// Directories or files to import
        #[arg(help = "Directories or files to import")]
        paths: Vec<String>,

        #[arg(
            short = 'u',
            long = "update",
            help = "Update existing bookmarks when content differs"
        )]
        update: bool,

        #[arg(
            long = "delete-missing",
            help = "Delete bookmarks whose source files no longer exist"
        )]
        delete_missing: bool,

        #[arg(
            short = 'd',
            long = "dry-run",
            help = "Show what would be done without making changes"
        )]
        dry_run: bool,

        #[arg(
            short = 'v',
            long = "verbose",
            help = "Show detailed information about skipped files and validation issues"
        )]
        verbose: bool,

        #[arg(
            long = "base-path",
            help = "Base path variable name from config (e.g., SCRIPTS_HOME). Paths must be relative to the base path location."
        )]
        base_path: Option<String>,
    },

    /// Show program information and configuration details
    Info {
        #[arg(short = 's', long = "schema", help = "Show database schema")]
        show_schema: bool,
    },
    /// Generate shell completions for bash, zsh, or fish
    Completion {
        /// Shell to generate completions for (bash, zsh, fish)
        shell: String,
    },
    /// Start LSP (Language Server Protocol) server for snippet completion
    Lsp {
        /// Disable bkmr template interpolation (serve raw templates instead of processed content)
        #[arg(long, help = "Disable bkmr template interpolation")]
        no_interpolation: bool,
    },
    #[command(hide = true)]
    Xxx {
        /// list of ids, separated by comma, no blanks
        ids: String,
        #[arg(short = 't', long = "tags", help = "add tags to taglist")]
        tags: Option<String>,
    },
}