29.04.2019 -- #

Dotfiles, sharing your Unix environment preferences since the dawn of personal computing. This week I was going through my dotfiles repo and cleaning up when I learned a few things. Ended up completely restructuring my repo and rewriting my sync script.

Repo: https://gitlab.com/BTBTravis/dotfiles/tree/master
Sync Script: https://gitlab.com/BTBTravis/dotfiles/blob/master/write.sh

120k dotfile repos on github

120k dotfile repos on github

One of the problems I faced how to split between mac and linux. I started with a separate branch for mac but after a while that became a complete mess as the sync script diverged. This time I was feeling more confident in my bash scripting so let the sync script handle it. I just restructured the repo with a /mac and /linux folders and then just detected operating system in when syncing. Also keeping duplicate files is not such a problem for me since I can vimdiff quite easily for changes.

Extending the sync script to handle these cases provided some good bash learning.

  • case statements: – Woh I didn’t know bash had pattern matching. Coming off elixir and elm projects its nice to see.

  • file based conditionals – If your in bash probably your doing so because you want to be close to the file system. Turns out it has super powered file based conditionals

    \# check if file exists and is a file
    if [ -f "$REMOTE_FILE" ]; then
    \# check if file is a symlink
    if [ -L "$REMOTE_FILE" ]; then

full list of “File test operators” in the docs

  • quote variable usages – after a lot of WTF debugging it was all solved by quoting a variable, docs

  • stay away from ~/ – save the $ cd ~/ for the shell and use "$HOME"/ while bash scripting

  • drop the leading dash in tar arguments – tar argument for me at least have been a notorious pain in the ass. I often get the arguments switched around causing “file not found” errors. Turns out tar does not follow all the Unix argument conventions and its best to drop the leading dash as in
    DON’T tar -cvf ./hello_world.tar ./files
    DO tar cvf ./hello_world.tar ./files

Now that my dotfiles are in order, I’m hoping to publish more content on the various projects I currently have in the works.

\- [ tech ]