xwmx / nb

CLI and local web plain text note‑taking, bookmarking, and archiving with linking, tagging, filtering, search, Git versioning & syncing, Pandoc conversion, + more, in a single portable script.
https://xwmx.github.io/nb
GNU Affero General Public License v3.0
6.61k stars 188 forks source link

Get filepath for note #162

Open gautampk opened 2 years ago

gautampk commented 2 years ago

Hello,

Apologies if I'm missing something obvious, but is there a way to get the raw absolute filepath for a given note, so I can integrate it with other command line tools? For example it would sometimes be useful to be able to append text directly without opening an editor, e.g.:

echo "New line of text" >> $(nb 3 path)
xwmx commented 2 years ago

Hi @gautampk! You can get the full path with nb show --path, e.g,:

echo "New line of text" >> "$(nb show 3 --path)"

nb edit can receive piped input, so you can rewrite the example to do a full edit with automatic commit using:

echo "New line of text" | nb edit 3

By default, piped input is appended to the note. nb edit also includes --overwrite and --prepend options.

gautampk commented 2 years ago

Aha, perfect! Thank you

gautampk commented 2 years ago

Hi again,

Sorry to re-open but there's a slight problem. When I use nb s 3 --path after editing nb does the pretty print waiting thing, which then causes issues; e.g.:

# edit file here
export file=$(nb s 3 --path)
org2task $file > $file # a shell script I wrote
zsh: no such file or directory:  [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H [\]  ^H^H^H^H^H^H [|]  ^H^H^H^H^H^H [/]  ^H^H^H^H^H^H [-]  ^H^H^H^H^H^H    ^H^H^H^H/path/to/notes/test.org

It looks like the [/] thing is output to STDOUT (also where the path is output to) so I can't just re-direct it away. Is there a way to switch this off so it just outputs nothing until the actual path?

Sorry to be a pain! I really love this tool and just want to integrate it more fully into my workflow. The issue is resolved if I run any nb show 3 command before the path command that is saved.

xwmx commented 2 years ago

No problem! That’s the spinner. It's being triggered by a subsequent nb call that's creating a git commit because the notebook repository is dirty after the content is added to the file. There are a couple different ways to approach this. You can pipe the content to nb edit and let it make the commit automatically:

org2task $file | nb edit 3

Alternatively, you can use nb git checkpoint to create a commit after adding content to the file directly:

org2task $file > $file
nb git checkpoint

Since the spinner is showing up right after the org2task command, the call to nb that's printing the spinner might be in the shell environment.

Let me know if this helps.