# /etc/profile
# 9front style — simple, clear, no bloat

# Safe delete for the interactive login shell: rm moves targets into
# /etc/trash instead of destroying them. Paths already inside the trash
# and everything from scripts (non-login shells) use the real rm.
rm() {
    local TR=/etc/trash
    local parsed=0 a base dest n
    [ -d "$TR" ] || { command mkdir -p "$TR" 2>/dev/null || { command rm "$@"; return; }; }
    for a in "$@"; do
        case "$a" in
            --) parsed=1; continue ;;
            -*) [ "$parsed" = 1 ] && echo "rm: option '$a' ignored" >&2; continue ;;
        esac
        case "$a" in
            "$TR"/*) command rm -r -- "$a" 2>/dev/null; continue ;;
        esac
        [ -e "$a" ] || [ -L "$a" ] || continue
        base=$(command basename "$a")
        dest="$TR/$base"
        n=0
        while [ -e "$dest" ]; do
            n=$((n+1))
            dest="$TR/${base}.$(date +%H%M%S).$n"
        done
        command mv -- "$a" "$dest" 2>/dev/null && \
            echo "rm: '$base' -> /etc/trash/"
    done
}

append_path() {
    case ":$PATH:" in
        *:"$1":*) ;;
        *) PATH="${PATH:+$PATH:}$1" ;;
    esac
}

if test -d /etc/profile.d/; then
    for f in /etc/profile.d/*.sh; do
        test -r "$f" && . "$f"
    done
fi

unset -f append_path

export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export GNUPGHOME=/etc/gnupg
export PASSWORD_STORE_DIR=/etc/password-store
export CARGO_HOME=/etc/cargo
export AQBANKING_HOME=/etc/aqbanking
export HISTFILE=/var/lib/history/root_history
export HISTSIZE=5000
export EDITOR=vi
export MANPAGER=less
export TZ="Europe/Berlin"

append_path /usr/bin
export PATH

if [ -t 0 ] && [ -c /dev/tty0 ]; then
    setfont /usr/share/kbd/consolefonts/ter-v16n.psf.gz 2>/dev/null
    loadkeys de-latin1 2>/dev/null
fi

if [ -z "$TMUX" ] && command -v tmux >/dev/null 2>&1; then
    exec tmux
fi
# opencode
export PATH=/root/.opencode/bin:$PATH
