From 88abd35c8e3f04b7653ef3acc7a18bf8d2de955e Mon Sep 17 00:00:00 2001 From: ge Date: Tue, 13 May 2025 10:43:11 +0300 Subject: [PATCH] add path command, fix options handling --- README.md | 2 +- help.txt | 1 + main.v | 38 +++++++++++++++++++------------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7db45a5..fd0d4cc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ `n!` (notes!, nex, nexclamation) is a text notes manager. -Use it with [completion](completion) script. See help.txt for usage info. +Use it with [completion](completion) script. See [help.txt](help.txt) for usage info. Compilation: diff --git a/help.txt b/help.txt index e761319..b784247 100644 --- a/help.txt +++ b/help.txt @@ -8,6 +8,7 @@ Commands: lsd print list of directories in notes path. s, search search in notes via 'grep --color=always -rni'. g, grep search in notes via custom grep. + p, path print absolute path to file. h, help print this help message and exit. Options: diff --git a/main.v b/main.v index 881e00b..f2192f8 100644 --- a/main.v +++ b/main.v @@ -21,26 +21,16 @@ fn main() { mut pref := Preferences{} argv := arguments()[1..] opts := cmdline.only_options(argv) - match true { - '-trace' in opts { - pref.trace = true + for opt in opts { + match opt { + '-trace' { pref.trace = true } + '-no-notes-path' { pref.no_notes_path = true } + '-no-chdir' { pref.no_chdir = true } + '-grep-raw' { pref.grep_raw = true } + '-grep-no-color' { pref.grep_no_color = true } + '-grep-no-recursive' { pref.grep_no_recursive = true } + else {} } - '-no-notes-path' in opts { - pref.no_notes_path = true - } - '-no-chdir' in opts { - pref.no_chdir = true - } - '-grep-raw' in opts { - pref.grep_raw = true - } - '-grep-no-color' in opts { - pref.grep_no_color = true - } - '-grep-no-recursive' in opts { - pref.grep_no_recursive = true - } - else {} } args := cmdline.only_non_options(argv) if args.len == 0 { @@ -121,6 +111,16 @@ fn main() { println(result.output.trim_space()) return } + 'p', 'path' { + p := os.join_path_single(notes_path, argv[1]) + if os.is_file(p) { + println(p) + return + } else { + eprintln('E: ${p} is not file or does not exist') + exit(1) + } + } 'h', 'help' { println(help.to_string().trim_space()) return