1
0
Fork 0

Add base configuration

- Follow XDG standard: ~/.config and ~/.local folders
- Set environment variables and define aliases within ~/.config/shell
- Add installation script for easy setup
- Add README.md with info on the installation and general notes
This commit is contained in:
Alexander Hess 2026-06-11 18:28:00 +02:00
commit 74d1e2ab00
Signed by: alexander
GPG key ID: D88F903B85326FFE
10 changed files with 258 additions and 0 deletions

8
.bashrc Normal file
View file

@ -0,0 +1,8 @@
#!/bin/bash
# `bash`-specific configurations
# Load configuration files common to all kinds of shells,
# if not already done by a `bash` login shell
[ -z "$PROFILE_LOADED" ] && [ -f "$HOME/.profile" ] && . "$HOME/.profile"

3
.config/shell/README.md Normal file
View file

@ -0,0 +1,3 @@
# Shell-related Configurations
This folder contains files that are sourced by `bash` and `zsh`.

7
.config/shell/aliases Normal file
View file

@ -0,0 +1,7 @@
#!/bin/sh
# Aliases used in all kinds of shells
# Manage the bare `git` repository in ~/ holding the dotfiles
alias dotfiles='git --git-dir=$XDG_DATA_HOME/dotfiles --work-tree=$HOME'

33
.config/shell/env Normal file
View file

@ -0,0 +1,33 @@
#!/bin/sh
# Environment variables for all kinds of shells
# Standard XDG base directories
# See: https://wiki.archlinux.org/title/XDG_Base_Directory
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share" # also set in ~/.local/bin/install-dotfiles
export XDG_STATE_HOME="$HOME/.local/state"
# Make up a XDG directory for binaries (that does not exist in the standard)
export XDG_BIN_HOME="$HOME/.local/bin"
# Convenient names for various places in the system
export DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.local/bin/install-dotfiles
# Generic shell configs
export GPG_TTY=$(tty)
export PAGER="less --chop-long-lines --ignore-case --LONG-PROMPT --no-init --status-column --quit-if-one-screen"
export TERM=xterm-256color
export TZ="Europe/Berlin"
# Move common tools' config and cache files into XDG directories
export LESSHISTFILE="$XDG_STATE_HOME/less/history"

3
.local/bin/README.md Normal file
View file

@ -0,0 +1,3 @@
# User-local Executables
This folder contains executable files that are on the `$PATH`.

91
.local/bin/install-dotfiles Executable file
View file

@ -0,0 +1,91 @@
#!/bin/sh
# Installation script to make the dotfiles available in ~/
#
# `git` is the only dependency for this script to run (See: https://git-scm.com)
#
# See: https://code.webartifex.biz/alexander/dotfiles#installation
set -eu
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" # also set in ~/.config/shell/env
DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.config/shell/env
# Defaults to the minimal/server version on the "main" branch
# => Set DOTFILES_BRANCH=desktop explicitly when installing on a desktop machine
DOTFILES_BRANCH="${DOTFILES_BRANCH:-main}"
DOTFILES_HTTPS="https://code.webartifex.biz/alexander/dotfiles"
DOTFILES_SSH="git@git.webartifex.biz:alexander/dotfiles.git"
BACKUP_DIR="$HOME/.dotfiles-backup-$(date +%Y%m%d-%H%M%S)"
if [ -d "$DOTFILES_DIR" ]; then
if [ "${FORCE_INSTALL:-}" != "1" ]; then
echo ""
echo "The dotfiles are already installed at: $DOTFILES_DIR"
echo ""
echo "Options:"
echo " - Set 'export FORCE_INSTALL=1' and run installation again"
echo " - Update with 'dotfiles pull' and continue using them"
echo ""
exit 0
fi
echo "Backing up the existing repository to: $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
mv "$DOTFILES_DIR" "$BACKUP_DIR/dotfiles"
fi
git clone --bare "$DOTFILES_HTTPS" "$DOTFILES_DIR"
_git() {
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" "$@"
}
if ! _git show-ref --verify --quiet "refs/heads/$DOTFILES_BRANCH"; then
echo ""
echo "Branch '$DOTFILES_BRANCH' does not exist in the repository"
echo ""
echo "Available branches:"
_git branch --format=' %(refname:short)'
echo ""
exit 1
fi
# Do not checkout project documentation intended for web GUIs
_git config core.sparseCheckout true
{
echo "/*"
echo "!LICENSE.txt"
echo "!README.md"
} > "$DOTFILES_DIR/info/sparse-checkout"
# Put the dotfiles in the user's $HOME folder
_git checkout --force "$DOTFILES_BRANCH"
# Do not show files not tracked in the dotfiles repository because there are simply too many
_git config --local status.showUntrackedFiles no
# Prefer `ssh` for syncing between the machines
_git remote set-url origin "$DOTFILES_SSH"
echo ""
echo "The dotfiles were installed successfully (branch: $DOTFILES_BRANCH)"
echo ""
echo "Reload your shell to start using them:"
echo " exec \$SHELL -l"
echo ""

View file

54
.profile Normal file
View file

@ -0,0 +1,54 @@
#!/bin/sh
# Main setup file executed for all kinds of shells
# Prevent loading ~/.profile twice in `bash`
export PROFILE_LOADED=1
# Basic utilities
_command_exists() {
command -v "$1" 1>/dev/null 2>&1
}
_in_bash() {
[ -n "$BASH_VERSION" ]
}
_in_zsh() {
[ -n "$ZSH_VERSION" ]
}
_prepend_to_path () {
if [ -d "$1" ] ; then
case :$PATH: in
*:$1:*) ;;
*) PATH=$1:$PATH ;;
esac
fi
}
# Load configuration files common to all kinds of shells
[ -f "$HOME/.config/shell/env" ] && . "$HOME/.config/shell/env"
[ -f "$HOME/.config/shell/aliases" ] && . "$HOME/.config/shell/aliases"
# Source ~/.profile_local, which holds machine-specific ENV variables
[ -f "$HOME/.profile_local" ] && . "$HOME/.profile_local"
# Load `bash`-specific configurations for non-login `bash` shells
if [ -n "$BASH_VERSION" ] && [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
# Put local executables on the `$PATH`
_prepend_to_path "$HOME/.local/bin"
# Ensure ~/.profile is loaded each time `bash` starts
unset PROFILE_LOADED

7
.zshrc Normal file
View file

@ -0,0 +1,7 @@
#!/bin/zsh
# `zsh`-specific configurations
# Load configuration files common to all kinds of shells
[ -f "$HOME/.profile" ] && . "$HOME/.profile"

52
README.md Normal file
View file

@ -0,0 +1,52 @@
# Dotfiles
This repository contains useful (config) files.
There are two "production" branches:
- [main](https://code.webartifex.biz/alexander/dotfiles/src/branch/main)
- [desktop](https://code.webartifex.biz/alexander/dotfiles/src/branch/desktop)
`main` contains dotfiles intended to be used on all kinds of machines
and can be thought of as a "minimal" or "server" version.
`desktop` is (re-)based on top of `main`
and adds "desktop" related dotfiles (e.g., GNOME stuff).
## Installation
Simply run:
```sh
curl https://code.webartifex.biz/alexander/dotfiles/raw/branch/main/.local/bin/install-dotfiles > install-dotfiles && sh ./install-dotfiles && rm ./install-dotfiles
```
or
```sh
wget https://code.webartifex.biz/alexander/dotfiles/raw/branch/main/.local/bin/install-dotfiles -O install-dotfiles && sh ./install-dotfiles && rm ./install-dotfiles
```
This downloads a simple [installation script](.local/bin/install-dotfiles)
and then executes it.
The script has only one dependency, namely [git](https://git-scm.com).
So, it should not be too hard to get this going.
When it finishes, reload your shell to start using the dotfiles:
```sh
exec $SHELL -l
```
For the *desktop* variant, run `export DOTFILES_BRANCH=desktop` before installation.
Normally, I advise against executing shell scripts from the internet,
but this one is short enough to be read even by beginners.
So, convince yourself that it is not harmful!
## Shells
The config files in this repository are optimized for usage with
[GNU's Bourne again shell](https://man7.org/linux/man-pages/man1/bash.1.html),
or `bash` for short,
and the popular [zsh](https://www.zsh.org/).