Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title to the filename e.g.1a2 - title #6

Closed
FamRau opened this issue Sep 28, 2021 · 6 comments
Closed

Add title to the filename e.g.1a2 - title #6

FamRau opened this issue Sep 28, 2021 · 6 comments

Comments

@FamRau
Copy link

FamRau commented Sep 28, 2021

My naming convention for my Zettel is: number - title.

e.g.
1a2 - Rationality
1a3 - Preference

Would it be possible to add an option to automatically add the first inner title to the file name?

@sarantsatsral-qy
Copy link

This would be excellent

@pauloday
Copy link
Contributor

pauloday commented Oct 20, 2021

I have a PR adding this: #7

@Dyldog
Copy link
Owner

Dyldog commented Oct 21, 2021

This issue has been graciously fixed by @pauloday. Great stuff!

@Dyldog Dyldog closed this as completed Oct 21, 2021
@pauloday
Copy link
Contributor

pauloday commented Oct 21, 2021

No problem, I wanted this feature to and I'm glad to share my code. I just updated my main notes folder through the plugins menu and it looks like it's working, thanks @Dyldog for the fast turnaround.

I did have to delete and reinstall the plugin for the settings menu to show up, but other than that it works. If you're using this in a folder with a bunch of id'd notes already, you'll need to add a separator to them before they're recognized in "Separator" mode. That's why I added the "Fuzzy" mode, which will match the old and new style filenames. It may match some other non-Luhman files though.

The default separator is '⁝ ' because it looks cool and you can't use ":" in Obsidian filenames. For @FamRau's setup you'd use " - " as the separator (note the whitespace). I'm also CCing @shanvrolijk in case they didn't get notified from the other messages in this thread.

Here's the bash script I used to update my filenames with the title and separator. It takes the title from the first header in the file and adds it with the separator as the title of a new file in './output'. This may overwrite things if there's already a folder named output, so be careful:

#!/bin/bash
sep="⁝ "
mkdir ./output
for f in *.md; do
        title=`grep '\#.*' $f | head -1 | cut -c3-`
        newpath="./output/${f%.*}$sep$title.md"
        echo "copying $f to $newpath"
        cp "$f" "$newpath"
done

Once you're happy with the filenames, use this script to update all the links. It assumes the existing links are only the id and modifies the files in place, so just use it in the output directory from above then make sure it looks good:

#!/bin/bash
sep="⁝ "
for f in *.md; do
        regex="s/\[\[${f%$sep*}\]\]/[[${f%.*}]]/g"
        for modf in *.md; do
                sed -i "$regex" "$modf"
        done
done

Note: these will miss notes if any titles have any of the Obsidian forbidden chars in them, I think that's at least '/|:' and maybe more. use grep -ho "# .*" *.md to see all the titles it'll use.

Let me know if there are any suggestions or bugs you find!

@sarantsatsral-qy
Copy link

Thank you @pauloday <3

@FamRau
Copy link
Author

FamRau commented Oct 21, 2021

@pauloday Thank you so much for this feature. I really appreciate it, because this plugin is so helpful in my daily research work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants