Skip to content

The .docsfile

Posted on:February 22, 2024

Today I came up with an interesting idea while working on a project. I’m sure this isn’t a profoundly novel idea, but it felt worth sharing.

Often while working within a repository, there will be a list of documentation URLs that I use. These URLs typically vary per-repository and if the documentation is separate from the repository itself, I then have to hunt for the docs in my bookmarks or confluence or what-have-you.

So it occurred to me: what if I had a flexible way to assign arbitrary documentation that I could easily access from the command line? So I slapped on my bashing-coding hat and came up with this:

# Utility function to allow us to open the documentation for the current project
function docs() {
   if [[ -f ".docsfile" ]]; then
      open $(cat .docsfile)
   else
      vim -c ':exe "normal i# Replace this line with the URL to this projects documentation"' .docsfile
      [[ -f ".docsfile" ]] && echo ".docsfile" >> .git/info/exclude
   fi
}

So now inside any repo, I can just run docs to access any documentation needs.

This script is auto-loaded in my dotfiles so I have access to it any time I’m in a session where my dotfiles are loaded.

Here’s the highlights:

A few ideas to improve it:


Thanks for reading! If you enjoyed this, you may also enjoy following me on twitter!