From 081cf16acce0576b20cc83cdccb17bea39a8f8dd Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 4 Jun 2024 20:53:38 +0200 Subject: [PATCH] Move settings to settings.d directory --- settings.d/autosave-history.sh | 3 +++ settings.d/custom-prompt.sh | 7 +++++++ settings.d/editor.sh | 3 +++ settings.d/flow-control.sh | 4 ++++ settings.d/replacement-pkgmgr.sh | 6 ++++++ startup.sh | 35 ++++++++------------------------ 6 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 settings.d/autosave-history.sh create mode 100644 settings.d/custom-prompt.sh create mode 100644 settings.d/editor.sh create mode 100644 settings.d/flow-control.sh create mode 100644 settings.d/replacement-pkgmgr.sh diff --git a/settings.d/autosave-history.sh b/settings.d/autosave-history.sh new file mode 100644 index 0000000..5efe3af --- /dev/null +++ b/settings.d/autosave-history.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +[[ "${CONFIG_AUTOSAVE_HISTORY}" == "1" ]] && export "PROMPT_COMMAND=history -a" diff --git a/settings.d/custom-prompt.sh b/settings.d/custom-prompt.sh new file mode 100644 index 0000000..df93853 --- /dev/null +++ b/settings.d/custom-prompt.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +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 diff --git a/settings.d/editor.sh b/settings.d/editor.sh new file mode 100644 index 0000000..197a197 --- /dev/null +++ b/settings.d/editor.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +export "EDITOR=${CONFIG_EDITOR}" diff --git a/settings.d/flow-control.sh b/settings.d/flow-control.sh new file mode 100644 index 0000000..b152aa4 --- /dev/null +++ b/settings.d/flow-control.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +[[ "${CONFIG_FLOW_CONTROl}" == "0" ]] && stty -ixon +[[ "${CONFIG_FLOW_CONTROL}" == "1" ]] && stty ixon diff --git a/settings.d/replacement-pkgmgr.sh b/settings.d/replacement-pkgmgr.sh new file mode 100644 index 0000000..6a6b127 --- /dev/null +++ b/settings.d/replacement-pkgmgr.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +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 diff --git a/startup.sh b/startup.sh index ad67ca8..85edf82 100755 --- a/startup.sh +++ b/startup.sh @@ -32,17 +32,19 @@ cd "${BASHRCD_HOMEDIR}" || ( [[ -f "init.d/aliases.sh" ]] && source "init.d/aliases.sh" [[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh" -# Create new configuration file +# Create default configuration file 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 #!/usr/bin/env bash -CONFIG_FLOW_CONTROL=0 +# Example configuration + CONFIG_AUTOSAVE_HISTORY=1 CONFIG_CUSTOM_PROMPT=1 CONFIG_EDITOR=nano +CONFIG_FLOW_CONTROL=0 CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru EOF @@ -52,30 +54,11 @@ fi # Load configuration file [[ -f "config.sh" ]] && 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 - +# Run settings scripts +for file in settings.d/*; do + # shellcheck disable=SC1090 + source "${file}" +done # Initialize shell programs for file in programs.d/*; do