notes by alifeee profile picture tagged obsidian (3) rss

return to notes / blog / website / weeknotes / linktree

here I may post some short, text-only notes, mostly about programming. source code.

tags: all (33) scripting (11) bash (4) geojson (3) jq (3) linux (3) obsidian (3) ActivityPub (2) github (2) html (2) ............ see all (+42)

uploading files to a GitHub repository with a bash script # prev single next top

tags: obsidian, github, scripting • 364 'words', 109 secs @ 200wpm

I write these notes in Obsidian. To upload, them, I could visit https://github.com/alifeee/blog/tree/main/notes, click "add file", and copy and paste the file contents. I probably should do that.

But, instead, I wrote a shell script to upload them. Now, I can press "CTRL+P" to open the Obsidian command pallette, type "lint" (to lint the note), then open it again and type "upload" and upload the note. At this point, I could walk away and assume everything went fine, but what I normally do is open the GitHub Actions tab to check that it worked properly.

The process the script undertakes is:

  1. check user inputs are good (all variables exist, file is declared)
  2. check if file exists or not already in GitHub with a curl request
  3. generate a JSON payload for the upload request, including:
    1. commit message
    2. commit author & email
    3. file contents as a base64 encoded string
    4. (if file exists already) sha1 hash of existing file
  4. make a curl request to upload/update the file!

As I use it from inside Obsidian, I use an extension called Obsidian shellcommands, which lets you specify several commands. For this, I specify:

export org="alifeee"
export repo="blog"
export fpath="notes/"
export git_name="alifeee"
export git_email="alifeee@alifeee.net"
export GITHUB_TOKEN="github_pat_3890qwug8f989wu89gu98w43ujg98j8wjgj4wjg9j83wjq9gfj38w90jg903wj"
{{vault_path}}/scripts/upload_to_github.sh {{file_path:absolute}}

…and when run with a file open, it will upload/update that file to my notes folder on GitHub.

This is maybe a strange way of doing it, as the "source of truth" is now "my Obsidian", and the GitHub is really just a place for the files to live. However, I enjoy it.

I've made the script quite generic as you have to supply most information via environment variables. You can use it to upload an arbitrary file to a specific folder in a specific GitHub repository. Or… you can modify it and do what you want with it!

It's here: https://gist.github.com/alifeee/d711370698f18851f1927f284fb8eaa8

back to top

how I organise my notes (project-active-resource-archive) # prev single next top

tags: obsidian, note-taking • 584 'words', 175 secs @ 200wpm

I make a lot of notes¹. Currently, I use Obsidian on my computer, laptop, and phone, and I use Syncthing to synchronise all the notes between my devices. I like making notes because if I write something down, I don't have to worry about forgetting it, and (maybe backwardsly) I can forget it with ease... because I know where I can go to remember it. It frees up my brain a lot. No thoughts. Head empty.

¹ At time of writing I have 1018 notes (result of find . -type f -name "*.md" | wc -l) (the Notion -> Obsidian export makes all database items into notes, so this is quite inflated by a bunch of empty "database" notes).

I used to use Notion but I realised: I would prefer to be making plaintext notes; I didn't like what they were doing with AI; the app was quite slow to use; and I had to be online (a lot of the time) to use it. With Obsidian, I can write notes offline, and they are only ever stored on my own devices, and synced between them.

I have four folders in the root folder of my obsidian, these are

1-Project
2-Active
3-Resource
4-Archive

This layout is called "PARA" (Project Active Resource Archive). I found out about it several years ago; I don't remember where.

The theory (or how I use it) is that you organise notes like:

So, as an example, my current:

There are many ways to organise notes, but I like this way because I can always pretty obviously fit a note into one of the three categories, so I don't have to constantly move notes around, or think too much about where they belong. Also, every few years it feels pretty great to empty out the project notes folder (an impossible task).

back to top

linting markdown from inside Obsidian # prev single next top

tags: obsidian, scripting, markdown • 382 'words', 115 secs @ 200wpm

I like Obsidian. I started using it recently instead of Notion. It is very nice.

The fact that it is static files is nice. The fact that those files are markdown is even nicer.

I sync it to all my devices with Syncthing. Sometimes there are sync conflicts, but https://github.com/friebetill/obsidian-file-diff makes solving that super easy.

Anyway, I've been writing these notes in Obsidian. I have then been copying and pasting the content into https://dlaa.me/markdownlint/ to find problems with my Markdown formatting. It's mainly when I forget to wrap links in <> as this makes them not render as HTML links - I sort of like this as you (my automatic tool) shouldn't try and decide what is and isn't a link, but also maybe you should because you can probably recognise them pretty well with a very established regex by now.

Anyway, I found an Obsidian extension which lets you specify shell commands https://github.com/Taitava/obsidian-shellcommands that you can run via the command palette. This seems super neat - I can do ANYTHING now.

Anyway, I installed it and made a command to lint the current markdown file. I had to install npm globally because it wasn't working when being called from the Obsidian script, and then I made this command to run the lint.

First install the markdownlint CLI:

npm install -g markdownlint-cli

The command is:

(cd {{folder_path:absolute}}; source /usr/alifeee/.nvm/nvm.sh && nvm use 20 && markdownlint {{file_name}} --disable MD013 && echo "no lint issues!")

I disabled MD013 which is the insane rule which wants you to have loads of line breaks per paragraph (I prefer my paragraph to be one really really long line please).

It's not perfect (the output is just in an ugly pop up window), but it is nice to run it locally.

Next... perhaps automatic uploading of notes from Obsidian, and I won't even have to open https://github.com/alifeee/blog/tree/main/notes to add a note to this site... dangerous...

(p.s., I managed to write this without any lint issues ;] )

back to top