hedgedoc / cli

A tiny CLI for HedgeDoc
GNU Affero General Public License v3.0
150 stars 37 forks source link

Import all Markdown files in a directory #32

Closed davidak closed 4 years ago

davidak commented 4 years ago

This should work:

codimd import /path/to/markdown/files

Workaround

[davidak@X230:~/code/cli/bin]$ for file in ~/Downloads/hackmd/*.md; do xdg-open $(CODIMD_SERVER='https://pad.nixnet.services' ./codimd import "$file" | awk '{print $4}'); done

(You have to open the imported note for it to appear in the history.)

pirate commented 4 years ago

I don't think this is worth implementing tbh, the bash loop is simple enough, and auto-importing directories is not a behavior that's expected for everyone. e.g if I mistype a path and forget the ending, I don't want it attempting to import every entry in a directory that potentially has thousands of random files in it. Also what if the user wants to import text files that don't end in .md? What about files that start with .? What if there are a mix of files in the directory (e.g. .DS_Store and others the user might not even know about), should we import only the ones that look like markdown and ignore the others? There are lots of edge-cases that make it less intuitive for the average use-case, I think it's safer to force the user to be explicit.

export CODIMD_SERVER='https://pad.nixnet.services'
for file in ~/Downloads/hackmd/*.md
    ./codimd import "$file" >> note_urls.txt
done

The URL output will also be fixed by #31, making the xdg-open + awk workaround in your example snippet unnecessary.

deletosh commented 1 year ago

If a search brought you here, here's a post-codimd version:

export HEDGEDOC_SERVER='https://notes.example.com'  

for file in ~/Downloads/hackmd/*.md 
do
    hedgedoc import "$file" >> note_urls.txt
done