6 min read
Jan 22, 2024
Dotfiles and how i manage them
$HOME
, to $HOME sweet $HOME
, basically your personalised settings.In this blog, I will try to explain how my dotfiles are setup, and some settings/configurations I have. You can find a current copy of my dotfiles here.
Shell
As for the shell i am using bash
. I am working on Windows for the while and the standard installation of Git Bash or WSL works fine for me. A guide to install WSL can be found from Microsoft here. As well as i have picked up and learnt my way through bash and the command line in general and hence i stick to it.
I have tried out ZSH and oh-my-zsh
and its great as well. Some suggestions are to use with zsh-autosuggestions package and zsh-syntaxhighlighting package.
Bash Config (.bashrc
)
Customising bash requires you to edit your .bashrc
file located in your home directory typically denoted by ~
.
Here's a top level view of what i have in my .bashrc
This evaluates dircolors for the ls command.
These are various keybindings, shell options, exports of environment variables, custom functions and aliases which i have enabled.
Useful Bindings
These will allow you to press the up key after typing a command to search your history to let you see the previous ways you had used it which is useful if you forgot the certain way you used a command before.
There are more, check out my dotfiles or anyone else's or research on the interet to find more!
Useful functions
This allows to extract given almost any sort of compressed file which is useful as I do not need to remember which command to use specifically.
This function makes a directory and drops you into it all at once.
A great resource I had found for my git aliases is the oh-my-zsh
repo - git.plugin.zsh
For some bling in the terminal, this line displays a ascii cow saying a random quote each time i open a terminal. This uses the fortune and cowsay programs with the Tux Cowfile.
The next 3 lines allow for utf8 input and output in the terminal.
Given all this custom settings and more you would obviously want to back them up and use it across machines or if you have a new machine.
A typical prompt of mine looks something like this -
How to manage the various dotfiles across machines?
Typically on Linux, people will symlink their dotfiles kept in some other directory, generally under version control, to their home directory where everything should exist to allow the programs to pick the settings up.
So, you will see people doing this,
This code snippet above is a for loop in bash which loops through the given array of dotfiles and links them to the home directory.
Given on linux, this works very fine.
So granted I'm using Git Bash on Windows, it should work on Windows as well right?
The sad answer is no, even though there is a ln
command, it doesn't seem to do anything. Enabling symlink option while installing looks to do the trick.
Anyway I decided to tackle this and write powershell script which does the same for me.
Heres that script,
This does the same thing and now the files are correctly linked to the other directory under version control. And that directory is very much my dotfiles repository.
Some modern replacements
Some of the commands have modern replacements (mostly in rust these days) and some extra commands that I install and use for my day to day. These are also included in my dotfiles to run instead of the standard commands. Lets take a brief look over them.
- 7zip - For working with archives https://7-zip.org/
- bat - A better
cat
https://github.com/sharkdp/bat - bc - GNU
bc
the calculator https://www.gnu.org/software/bc/bc.html - delta - For better diffs https://dandavison.github.io/delta/
- exiftool - Viewing and editing metadata https://exiftool.org
- eza - A modern, maintained replacement for ls, built on exa. https://github.com/eza-community/eza
- fd - Alternative to
find
- https://github.com/sharkdp/fd - ffmpeg - A complete, cross-platform solution to record, convert and stream audio and video. : https://ffmpeg.org
- glow - Markdown reader for the terminal with a TUI https://github.com/charmbracelet/glow
- hexyl - Hex viewer, which uses colored output. https://github.com/sharkdp/hexyl
- jq - Lightweight and flexible command-line JSON processor https://jqlang.github.io/jq
- micro - A terminal-based text editor that aims to be easy to use and intuitive https://micro-editor.github.io
- ngrok - For forwarding servers onto open internet. https://ngrok.com
- pandoc - Universal markup converter https://pandoc.org
- ripgrep - Better
grep
. Recursively searches directories for a regex pattern. https://github.com/BurntSushi/ripgrep - tokei - Count lines of code https://github.com/XAMPPRocky/tokei
- tre-command - Improved Tree command https://github.com/dduan/tre
- zoxide - A faster way to navigate your filesystem https://github.com/ajeetdsouza/zoxide
I set some of these as aliases to original commands as replacements. You can view them in my aliases here.
Thats about it for the setup. I might later do a dev setup blog soon going over the tools and technologies I use.
References
- My dotfiles
- A collection of popular dotfiles setups I have taken a lot of inspiration and things from these