Config aliases
Some of my most used shell aliases are aliases for editing configuration files.
Many programs can be configured via text files, but it can be annoying to remember where to find a particular config file or to repeatedly jump to a configuration file when testing changes. Programs like shells themselves, editors, locally installed databases and other utilities need to be (re)configured from time to time. Fortunately, shell aliases can help.
Let’s say you want to be able to quickly configure a text editor like Helix. To do so you will need to know the path to the config file (but you only have to look it up once!) and decide which program to use for editing it. In my case, I use Helix (abbreviated as hx
) and the default helix configuration file is at ~/.config/helix/config.toml.
Hence, the shell alias would look like this:
alias hxconf="hx ~/.config/helix/config.toml"
Such an alias will work in both Bash and Z shells (Zsh) and you only need to place it in the appropriate Bash/Zsh config file. For example, in the case of Z shell it is ~/.zshrc
on Linux. In fact, I suggest that you create a zshconf
or bashconf
alias while you are at it.
It doesn’t matter whether you prefer to edit configuration files in the terminal, using VSCode, or need to open a different program altogether. In any case, opening the configuration directly from the command line is very convenient. I use config aliases for their ergonomics even though most configs I edit are in my separate dotfiles directory.
Some examples from my ~/.zshrc
:
alias zshconf="hx ~/dotfiles/.zshrc"
alias starshipconf="hx ~/.config/starship.toml"
alias hxconf="hx ~/dotfiles/.config/helix/config.toml"
alias tmuxconf="hx ~/dotfiles/.tmux.conf"
alias gitconf="hx ~/dotfiles/.gitconfig"
alias pgservice="hx ~/dotfiles/.pg_service.conf"
alias pgpass="hx ~/dotfiles/.pgpass"
alias zellijconf="hx ~/dotfiles/.config/zellij/config.kdl"
Instead of invoking the editing program directly, you can also use $EDITOR if you have it set to the correct program. It will make the configuration more flexible when changing the default editor (unless you need a specific program for a particular conf file).
May your aliases serve you well,
Petr