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 2025-08-30 11:19:10 +02:00
commit f0e143242b
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
10 changed files with 228 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'

28
.config/shell/env Normal file
View file

@ -0,0 +1,28 @@
#!/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`.

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

@ -0,0 +1,74 @@
#!/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 -e
XDG_DATA_HOME="$HOME/.local/share" # also set in ~/.config/shell/env
DOTFILES_DIR="$XDG_DATA_HOME/dotfiles" # also set in ~/.config/shell/env
# Check if the dotfiles were installed previously
if [ -d "$DOTFILES_DIR" ] && [ "${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 ""
else
# Remove an already installed dotfiles repository
if [ -d "$DOTFILES_DIR" ]; then
rm -rf "$DOTFILES_DIR"
fi
if [ -z "$DOTFILES_BRANCH" ]; then
# Auto-detect if we're on a desktop system
if [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ] || [ "$(systemctl --user is-active graphical-session.target 2>/dev/null)" = "active" ]; then
export DOTFILES_BRANCH="desktop"
else
export DOTFILES_BRANCH="main"
fi
elif [ "$DOTFILES_BRANCH" != "desktop" ] && [ "$DOTFILES_BRANCH" != "main" ]; then
echo ""
echo "'DOTFILES_BRANCH' may only be one of: 'desktop' or 'main'"
exit 1
fi
mkdir -p "$XDG_DATA_HOME"
git clone --bare https://code.webartifex.biz/alexander/dotfiles "$XDG_DATA_HOME/dotfiles"
# Do not checkout project documentation intended for web GUIs (e.g., GitHub)
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" config core.sparseCheckout true
echo "/*" > "$DOTFILES_DIR/info/sparse-checkout"
echo "!LICENSE.txt" >> "$DOTFILES_DIR/info/sparse-checkout"
echo "!README.md" >> "$DOTFILES_DIR/info/sparse-checkout"
# Put the dotfiles in the user's `$HOME` folder
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" checkout --force "$DOTFILES_BRANCH"
# Do not show files not tracked in the dotfiles repository because there are simply too many
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" config --local status.showUntrackedFiles no
# The author of this file prefers to use SSH to sync his machines with the origin
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" remote set-url origin git@git.webartifex.biz:alexander/dotfiles.git
echo ""
echo "The dotfiles were installed successfully"
# Mimic starting a new shell to get new dotfiles right away
if [ -n "$ZSH_VERSION" ]; then
. "$HOME/.zshrc"
else
. "$HOME/.profile"
fi
fi

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"

44
README.md Normal file
View file

@ -0,0 +1,44 @@
# Dotfiles
This repository contains useful (config) files.
It is structured into two branches:
- [desktop](https://code.webartifex.biz/alexander/dotfiles/src/branch/desktop)
- [main](https://code.webartifex.biz/alexander/dotfiles/src/branch/main)
`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 && . ./install-dotfiles && rm ./install-dotfiles
```
or
```
wget https://code.webartifex.biz/alexander/dotfiles/raw/branch/main/.local/bin/install-dotfiles -O install-dotfiles && . ./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.
Normally, I advice 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/).