commit 74d1e2ab0048d8e7c052db7ab4a38fc49dd303c7 Author: Alexander Hess Date: Thu Jun 11 18:28:00 2026 +0200 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 diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..8e7b6a1 --- /dev/null +++ b/.bashrc @@ -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" diff --git a/.config/shell/README.md b/.config/shell/README.md new file mode 100644 index 0000000..bd3a821 --- /dev/null +++ b/.config/shell/README.md @@ -0,0 +1,3 @@ +# Shell-related Configurations + +This folder contains files that are sourced by `bash` and `zsh`. diff --git a/.config/shell/aliases b/.config/shell/aliases new file mode 100644 index 0000000..eaf280d --- /dev/null +++ b/.config/shell/aliases @@ -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' diff --git a/.config/shell/env b/.config/shell/env new file mode 100644 index 0000000..ffe8b25 --- /dev/null +++ b/.config/shell/env @@ -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" diff --git a/.local/bin/README.md b/.local/bin/README.md new file mode 100644 index 0000000..2fe7197 --- /dev/null +++ b/.local/bin/README.md @@ -0,0 +1,3 @@ +# User-local Executables + +This folder contains executable files that are on the `$PATH`. diff --git a/.local/bin/install-dotfiles b/.local/bin/install-dotfiles new file mode 100755 index 0000000..6dc2602 --- /dev/null +++ b/.local/bin/install-dotfiles @@ -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 "" diff --git a/.local/state/less/.gitkeep b/.local/state/less/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.profile b/.profile new file mode 100644 index 0000000..9641b87 --- /dev/null +++ b/.profile @@ -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 diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..3a46429 --- /dev/null +++ b/.zshrc @@ -0,0 +1,7 @@ +#!/bin/zsh + +# `zsh`-specific configurations + + +# Load configuration files common to all kinds of shells +[ -f "$HOME/.profile" ] && . "$HOME/.profile" diff --git a/README.md b/README.md new file mode 100644 index 0000000..641f4d6 --- /dev/null +++ b/README.md @@ -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/).