badd10de.dev

UNIX


Dotfiles

I keep my dotfiles organize in a git repository using StreakyCobra’s method

To initialize a new dotfile repository use the following:

git init --bare $HOME/.dotfiles
alias cfg='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
cfg cfg --local status.showUntrackedFiles no
echo "alias cfg='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.bashrc

Now you can access dotfiles git commands from anywhere with:

cfg status
cfg add .vimrc -f
cfg commit -m 'Add vimrc'
cfg push

To restore the dotfiles to a new machine:

git clone --bare <git-repo-url> $HOME/.dotfiles
alias cfg='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
cfg checkout

Tips

Watch files for changes

Tail

We can see the output being written to a file by using the tail command.

tail -f log/development.log

Guard

We can use guard to monitor source code files and compile them when we save the file.

To install it we can use gem:

gem install guard
gem install guard-shell
guard init shell

Then you can edit the Guardfile to filter the files we want to check and perform any action we want. As an example, the following will check haskell files and compile them on save:

guard :shell do
    watch /.*\.l?hs$/ do |m|
        `runghc #{m[0]}`
    end
end
}

Peat

Peat is an utility created by Steve Losh, and only depends on Python being installed. You can pipe any command to peat and it will start watching them. If it detects any changes, the argument of peat will be executed:

find . -name hello.c | peat "make hello && ./hello"

Inotify

In Linux, we can use inotify to watch for system changes and act accordingly. In this script you can watch all directories in the current path and execute whatever you pass it as an argument:

#!/bin/sh
# Depends on 'inotify-tools' package
FORMAT=$(echo -e "\033[1;33m%w%f\033[0m written")
"$@"
while inotifywait -qre close_write --format "$FORMAT" .
do
    "$@"
done

Converting images for web performance

I like to rescale and bitcrush images for using on the web to reduce their size. You can always keep a high resolution image available for when you click on them. ImageMagick to the rescue!

convert src_img.jpg -resize 800 -dither FloydSteinberg -depth 3 -colors 5 dst_img.png

Essential UNIX packages

Some packages necesary for a normal installation using my workflow, should be applicable for Linux, FreeBSD and macOS.

Development tools

Programming languages

Linux specific

Utilities

Network analysis

Web browsers

Xorg/Appearance

Other

Resources