Micro

Micro

Quick thoughts, updates, and shorter musings. Like tweets, but on my own site.

Using 1password CLI for secrets

I use the same dotfiles for my work and person computers. Because we’re using Github packages at work, I’ve had an annoying issue where I have to set the token for Github packages in my .npmrc file but I don’t want to leak this token by checking it into Github so I reference an env variable. So my .npmrc file looks something like this:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_READ_TOKEN}
@contentful:registry=https://npm.pkg.github.com
loglevel=warn

But this meant that I have to manually set the NPM_TOKEN and GITHUB_PACKAGES_READ_TOKEN so that this file can find them in the environment. It’s a small thing but it was annoying me.

Today, I discovered that I can use the 1password CLI to set these values in my .zshrc and then I no longer have to think about it. Here’s how to do it.

  1. Install the 1password CLI, you can find instructions here
  2. Save the secrets in 1password
  3. Then use this to learn how to get secret references from your 1password desktop app
  4. Then add this to your .zshrc:
Terminal window
export GITHUB_PACKAGES_READ_TOKEN=$(op read "op://<vault-name>/GITHUB_PACKAGES_READ_TOKEN/password")
export NPM_TOKEN=$(op read "op://<vault-name>/NPM_TOKEN/password")
  1. Source your .zshrc and that’s it.

There are other interesting commands in the 1password CLI like op inject if you want to inject your secrets into env files, etc. Check it out!

I'm back on VSCode

I’m back on VSCode. I’ve used neovim for a while. I started on VSCode and once I learnt the vim motions I really wanted to move to neovim but I didn’t want to have to deal with the stress of setting it up. Eventually the vim vscode extension started being buggy and freezing and that forced me.

The first time I tried to set everything up myself, you have probably predicted that this didn’t go too well. Fortunately, not too long after that I discovered LunarVim. I set that up and I was of to the horses. LunarVim lost it’s appeal to me when I got to a place when I needed to customise something. So I switch to NvChad which was a delight. I eventually switched to AstroNvim primarily because of their plugin ecosystem where things are already preconfigered with the common settings. This reminded me of vscode’s plugin system. At this point I didn’t think I’d change. However, last holiday I figured I’d give vscode another shot since it’s been so long and I found that the vim plugin is not so buggy. So I ported over most of my most used key bindings and that’s what I’m using now.

Now that I’m back I realise there are some quality of life things I like about vscode that I’d forgotten. Small things like auto import and cleanup of imports. Anyway the rest feels very much like my AstroNvim setup.

Clean up merged branches

I use the following to clean up merged branches from remote:

Terminal window
git fetch -p && for branch in $(git for-each-ref --format "%(refname) %(upstream:track)" refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done

Owning my own reading log

I liked Tom MacWright’s take on why he’s “leaving” GoodReads and owning his own reading log. I liked it so much, in fact, that I decided to do the same. So I exported all my books from GoodReads. The export comes as a CSV so I found a CSV to JSON convertor online and turned it into JSON. Wrote a little script to split the JSON into individual markdown files for each book. And then created a collection on my Astro site.

I no longer have all the info about the books and the book cover from GoodReads. Fortunately the export comes with an ISBN and I can use that on the Open Library API to fetch the cover if they have it and display it on my site. The rest was html and css and now I have a books section on my site.

Using connection pooled URL with Supabase and Prisma

If you ever encounter this error while trying to run a migration with prisma on your supabase database:

Terminal window
Error: Schema engine error:
ERROR: prepared statement "s0" does not exist

You’re likely using the wrong URL to connect to your database. Prisma needs a different URL for doing migrations if your normal database URL uses connection pooling. For more information, see this article for a more comprehensive guide

How to remove file from Git history

I have googled this enough times for me to keep it in my own notes.

From time to time I find that in my building and carelessly using git add . I have added a file or files into git that I shouldn’t have had in there in the first place. When this happens I want to delete the file from the git history completely. Maybe there’s a better way to do that but this does what I want.

Anyway, the answer to “How to remove file from Git history” that I always use is here. This is the specific answer I use.

Terminal window
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch path_to_file' HEAD