add path command, fix options handling

This commit is contained in:
ge committed 2025-05-13 10:43:11 +03:00
1 parent a69b839ee0
commit 88abd35c8e
3 files changed
+21 -20

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
`n!` (notes!, nex, nexclamation) is a text notes manager. `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: Compilation:
+1
View File
@@ -8,6 +8,7 @@ Commands:
lsd print list of directories in notes path. lsd print list of directories in notes path.
s, search search in notes via 'grep --color=always -rni'. s, search search in notes via 'grep --color=always -rni'.
g, grep search in notes via custom grep. g, grep search in notes via custom grep.
p, path print absolute path to file.
h, help print this help message and exit. h, help print this help message and exit.
Options: Options:
+19 -19
View File
@@ -21,27 +21,17 @@ fn main() {
mut pref := Preferences{} mut pref := Preferences{}
argv := arguments()[1..] argv := arguments()[1..]
opts := cmdline.only_options(argv) opts := cmdline.only_options(argv)
match true { for opt in opts {
'-trace' in opts { match opt {
pref.trace = true '-trace' { pref.trace = true }
} '-no-notes-path' { pref.no_notes_path = true }
'-no-notes-path' in opts { '-no-chdir' { pref.no_chdir = true }
pref.no_notes_path = true '-grep-raw' { pref.grep_raw = true }
} '-grep-no-color' { pref.grep_no_color = true }
'-no-chdir' in opts { '-grep-no-recursive' { pref.grep_no_recursive = true }
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 {} else {}
} }
}
args := cmdline.only_non_options(argv) args := cmdline.only_non_options(argv)
if args.len == 0 { if args.len == 0 {
os.chdir(notes_path)! os.chdir(notes_path)!
@@ -121,6 +111,16 @@ fn main() {
println(result.output.trim_space()) println(result.output.trim_space())
return 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' { 'h', 'help' {
println(help.to_string().trim_space()) println(help.to_string().trim_space())
return return