This repo contains config files (commonly called dotfiles) targeting Linux and WSL. It is my humble attempt to optimize ergonomics, security, and productivity. No doubt that I spent too much time micro-optimizing them, and I still have a psychotic urge to keep improving them. Hopefully, I'll be able to recover one day.
Feel free to steal anything that seems useful to you. That said, you shouldn't blindly copy stuff because:
In addition, I provide absolutely no backward compatibility guarantees, and I sometimes fully reset the git history and start from scratch (though that will hopefully stop once this repo is more stable).
Specific configs that may be more interesting for you: vim, tmux, zsh, vscode, ipython, ranger, i3, bash, and probably others I forgot.
functions.sh
) and for terminal settings (settings.sh
), since I have amy-tool
and not my_tool
. They should also have no file.sh
for shell scripts, .py
forI roughly follow Google's style guide with the following additions:
LIKE_THIS
("constants" is quoted because thereaddon-info.json
for plugins since it's rarelyMany scripts in this repo are written in bash and zsh. In order to make the code easier to manage, I try to follow the Google Style Guide along with the following additions:
Bash scripts start with a #!/usr/bin/env bash
shebang.
Functions that are private to the script and are not intended to be exported
should have a leading underscore, for example _my_func
. Functions that are
exported from a script should never have a leading underscore, (i.e.
my_func
, not _my_func
).
printf '%s\n' "${var}"
is preferred over echo "${var}"
because the latter
can interpret escape sequences (such as \b
). However, printing string
literals with not special chars is fine and shorter (echo 'message'
).
All scripts should pass shellcheck with no warnings or errors.
Single quotes are preferred over double quotes when substitution is not used.
Functions should not use the function
keyword and should generally use
underscores to separate words, unless they're interactive shell functions
that are expected to be extracted to their own executable, in which case they
can use dashes.
"Library scripts" (intended to be sourced from other scripts) should always
use underscores in the filenames and end with a .sh
filename extension,
while "executable scripts" should always use dashes and without a filename
extension.
Files are structured as following:
${REPO_ROOT}
and other constantsmain
functionmain
Example:
#!/usr/bin/env bash
#
# This script does XYZ. Usage:
# my_script <arg> [opt_arg]
# See https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -o errexit -o errtrace -o nounset -o pipefail
# shellcheck disable=SC2155
readonly REPO_ROOT="$([[ ${CONFIG_GET_ROOT:-0} == 1 ]] && config-repo-root "${BASH_SOURCE[0]}" || echo "${HOME}")"
readonly OTHER_CONST=3
# shellcheck source=../../.my_scripts/lib/base.sh
source -- "${REPO_ROOT}/.my_scripts/lib/base.sh"
_private_func() {
echo 'This is a private function'
}
main() {
printf 'Called main with args: %s\n' "$*"
}
main "$@"
Note that old scripts may not conform to this style yet.