2024-06-03 01:45:55 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# shellcheck disable=SC2154
|
2024-06-03 02:10:23 +02:00
|
|
|
set -eo pipefail
|
2024-06-03 01:45:55 +02:00
|
|
|
|
2024-06-03 02:14:46 +02:00
|
|
|
# Cancel execution of system-wide punktdateien-bashrc if user-wide installation is detected
|
|
|
|
if [ -n "${BASHRCD_SYSTEM}" ] && [ -d "${HOME}/.bashrc.d" ] && [ -f "${HOME}/.bashrc.d/startup.sh" ]; then
|
|
|
|
set +eo pipefail
|
2024-06-03 02:16:14 +02:00
|
|
|
return 0
|
2024-06-03 02:14:46 +02:00
|
|
|
fi
|
|
|
|
|
2024-06-03 02:10:47 +02:00
|
|
|
# Define variables
|
|
|
|
export "BASHRCD_FALLBACK=exec env --ignore-environment bash --norc --noprofile"
|
|
|
|
|
|
|
|
if [ -z "${BASHRCD_SYSTEM}" ]; then
|
|
|
|
export "BASHRCD_HOMEDIR=${HOME:?}/.bashrc.d"
|
|
|
|
else
|
|
|
|
export "BASHRCD_HOMEDIR=/etc/bashrc.d"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# cd into to home directory
|
|
|
|
cd "${BASHRCD_HOMEDIR}" || (
|
2024-06-03 01:45:55 +02:00
|
|
|
echo ":: Can't cd into ${HOME:?}/.bashrc.d"
|
2024-06-03 02:10:47 +02:00
|
|
|
${BASHRCD_FALLBACK}
|
2024-06-03 01:45:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Initialize basic stuff
|
|
|
|
[[ -f "init.d/path.sh" ]] && source "init.d/path.sh"
|
|
|
|
[[ -f "init.d/variables.sh" ]] && source "init.d/variables.sh"
|
|
|
|
[[ -f "init.d/aliases.sh" ]] && source "init.d/aliases.sh"
|
|
|
|
[[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh"
|
|
|
|
|
|
|
|
# Create new configuration file
|
2024-06-03 02:10:47 +02:00
|
|
|
if [ ! -f "config.sh" ]; then
|
|
|
|
if [ -n "${BASHRCD_SYSTEM}" ] && [ "${UID}" != "0" ]; then
|
|
|
|
echo ":: Warning: Can't create system-wide configuration file as normal user."
|
|
|
|
else
|
|
|
|
$(which cat) << EOF >> config.sh
|
2024-06-03 01:45:55 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
CONFIG_FLOW_CONTROL=0
|
|
|
|
CONFIG_AUTOSAVE_HISTORY=1
|
|
|
|
CONFIG_CUSTOM_PROMPT=1
|
|
|
|
CONFIG_EDITOR=nano
|
|
|
|
CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman
|
|
|
|
CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru
|
|
|
|
EOF
|
2024-06-03 02:10:47 +02:00
|
|
|
fi
|
|
|
|
fi
|
2024-06-03 01:45:55 +02:00
|
|
|
|
|
|
|
# Load configuration file
|
|
|
|
source "config.sh"
|
|
|
|
|
|
|
|
# Process configuration changes
|
|
|
|
# -> Flow control
|
|
|
|
[[ "${CONFIG_FLOW_CONTROl}" == "0" ]] && stty -ixon
|
|
|
|
[[ "${CONFIG_FLOW_CONTROL}" == "1" ]] && stty ixon
|
|
|
|
|
|
|
|
# -> Autosave history
|
|
|
|
[[ "${CONFIG_AUTOSAVE_HISTORY}" == "1" ]] && export "PROMPT_COMMAND=history -a"
|
|
|
|
|
|
|
|
# -> Custom prompt
|
|
|
|
if [[ "${CONFIG_CUSTOM_PROMPT}" == "1" ]]; then
|
|
|
|
export "PS1=\[\033[38;5;33m\][\[$(tput sgr0)\]\[\033[38;5;38m\]\u\[$(tput sgr0)\]\[\033[38;5;33m\]@\[$(tput sgr0)\]\[\033[38;5;38m\]\H\[$(tput sgr0)\]\[\033[38;5;33m\]:\[$(tput sgr0)\]\[\033[38;5;38m\]\W\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;214m\]\$?\[$(tput sgr0)\]\[\033[38;5;33m\]]\\$\[$(tput sgr0)\] "
|
|
|
|
export "PS2=\[\033[38;5;196m\][incomplete]: \033[0;10m"
|
|
|
|
export "PS4=\${0}:\${LINENO}+ "
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -> Editor
|
|
|
|
export "EDITOR=${CONFIG_EDITOR}"
|
|
|
|
|
|
|
|
# -> Package manager replacement
|
|
|
|
if [ -n "${CONFIG_REPLACE_PKGMGR_ORIGINAL}" ] && [ -n "${CONFIG_REPLACE_PKGMGR_REPLACEMENT}" ]; then
|
|
|
|
# shellcheck disable=SC2139
|
|
|
|
alias "${CONFIG_REPLACE_PKGMGR_ORIGINAL}=${CONFIG_REPLACE_PKGMGR_REPLACEMENT}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Initialize shell programs
|
|
|
|
for file in programs.d/*; do
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
source "${file}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Run startup scripts
|
|
|
|
for file in startup.d/*; do
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
source "${file}"
|
|
|
|
done
|
2024-06-03 02:10:23 +02:00
|
|
|
|
2024-06-03 02:12:11 +02:00
|
|
|
unset BASHRCD_SYSTEM
|
2024-06-03 02:10:23 +02:00
|
|
|
set +eo pipefail
|