↖ Writing

Dotfiles

Dotfiles

After tinkering with them for some time in a private repository, I made my dotfiles public on GitHub.1

I really enjoy poking through other programmers’ dotfiles. It allows you to look behind the curtain and learn from their setup.

So, my setup is also inspired by a few other resources:

Highlights

I find these parts of my dotfiles especially useful in my day-to-day coding.

nvim

Git commit management

return {
	"tpope/vim-fugitive",
	config = function()
		local keymap = vim.keymap -- for conciseness
		-- Git keybinds / fugitive keybinds
		keymap.set("n", "<leader>g", ":G<CR>") -- open Git view
		keymap.set("n", "<leader>gsc", ":Gwrite | :G commit<CR>") -- git stage and commit
		keymap.set("n", "<leader>gg", ":Gwrite | :G commit<CR>") -- git stage and commit
		keymap.set("n", "<leader>gs", ":Gwrite <CR>") -- git stage
		keymap.set("n", "<leader>ga", ":G add --all -- ':!src/content/*' ':!.gitignore' | :G commit<CR>") -- git stage all (except commonly ignored)
		keymap.set("n", "<leader>gc", ":G commit<CR>") -- git commit
		keymap.set("n", "<leader>gp", ":G push<CR>") -- git push
	end,
}

From fugitive.lua.

I have been able to stick with Git best practices of small and contained commits much easier after mapping some keys to common Git actions. I use <leader>gg to stage and commit the current file all the time.

Setting up gitsigns to select and stage hunks also encourages me to keep changes contained in my commits.

Lualine unsaved file symbol

Screenshot of the nvim interface. At the bottom there is a filled circle next to the filenameThe filled circle next to the filename in the bottom indicates unsaved changes.

I found it helpful to add an indicator to the lualine setup to indicate unsaved changes in a file. I can’t tell you how often I was refreshing localhost to see my changes before, without having actually saved the file 😅

Open CMS file in browser

This bit of code in keymaps.lua is specific to my work setup, but it highlights how modular and powerful nvim is in its config:

local keymap = vim.keymap -- for conciseness
local secrets = require("joschua.secrets")

keymap.set(
	"n",
	"<leader>k",
	"gg/kontentId<cr>WyW:!open 'https://app.kontent.ai/"
		.. secrets.kontentId
		.. "/content-inventory/00000000-0000-0000-0000-000000000000/content/<c-r>\"'<cr>"
) -- open kontent id in browser

On pressing <leader>k, nvim goes to the top (gg), searches for the string ‘kontentId’ (/kontentId<cr), jumps a word forward (W), copies that word (yW), then executes a shell command to open a URL in the browser, including a secret identifier (:!open 'https://…').

Jumping directly to the CMS entry of a local copy has saved me heaps of tedious clicking and searching. This example is specific to my context but shows how nvim can easily handle complex macros.

Other

  • I mentioned ni on this blog before, and I set up some aliases for it. I run nr dev and nr build dozens of times a day, so I shortened them to nd and nb to have those commands at my fingertips.
  • I have been using cooklang less, as Apple Reminders rolled out their auto-classification on shopping lists, but it’s still a cool and nerdy way to keep track of recipes from the command line.
  • Another command I use frequently is dark (or light) which is defined in my .zshrc to set a colour mode of kitty.

Conclusion

Dotfiles are a highly personal and customised thing. But I hope that by poking through my setup at selfire1/dotfiles, you too can have a look behind the curtain and steal inspiration to make your setup that bit more productive.

Footnotes

  1. Since the previous history contained some semi-sensitive data, I had to reset the git history when going public.

  2. Although I don’t see myself following him down the nix path – for now at least 😅