# Beyond Hosting .bash_profile #### Data arrays for init ==start #### ARRAY_PATH=( ${HOME}/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/libexec /usr/bin/X11 /opt/X11/bin /usr/X11R6/bin /usr/games $(echo ${PATH} | sed 's/:/\n/g') ) # Array of shell options to be set ARRAY_SHELL_OPTIONS=( cdable_vars cdspell checkhash checkwinsize histappend no_empty_cmd_completion xpg_echo ) # Array of shell options that only work with bash 4+ ARRAY_SHELL_OPTIONS_BASH4=( autocd dirspell ) #### Data arrays for init ==final #### #### Color variables ==start #### # Output styles export C_RST="\e[0m" export C_BLD="\e[1m" export C_DRK="\e[2m" export C_FLS="\e[5m" export C_INV="\e[7m" export C_ITA="\e[3m" export C_UDL="\e[4m" # Alert! export C_ALT="\e[41;5m" # Colors export C_BLK="${C_RST}\e[30m" export C_RED="${C_RST}\e[31m" export C_GRN="${C_RST}\e[32m" export C_YLW="${C_RST}\e[33m" export C_BLU="${C_RST}\e[34m" export C_MGT="${C_RST}\e[35m" export C_CYN="${C_RST}\e[36m" export C_WHT="${C_RST}\e[37m" #### Color variables ==final #### #### User color config ==start #### # Root = red, non-root = green [[ "${UID}" == "0" ]] && C_ENV="${C_RED}" || C_ENV="${C_ENV-${C_GRN}}" export C_ENV export C_ENV_BOLD="${C_BLD}${C_ENV}" #### User color config ==final #### #### Path config ==start #### ARRAY_PATH=($(echo ${PATH} | sed 's/:/\n/g') ${ARRAY_PATH[@]}) unset PATH for ENTRY in ${ARRAY_PATH[@]}; do # Skip entry if it's already in PATH [[ "${PATH}" =~ (:|^)${ENTRY}(:|$) ]] && continue # Skip entry if it is a symlink [[ -h ${ENTRY} ]] && continue; # Add entry from array if it is present and a directory [[ -d ${ENTRY} ]] && PATH="${PATH}${PATH+:}${ENTRY}" done export PATH #### Path config ==final #### #### Hostname config ==start #### # If we have a hostname file, use it; otherwise call the hostname binary [[ -s /etc/hostname ]] && HOSTNAME_DATA="$(cat /etc/hostname)" || HOSTNAME_DATA="$(hostname -f)" # Determine subdomain count DOMAIN_COUNT="${HOSTNAME_DATA//[^.]}" DOMAIN_COUNT="${#DOMAIN_COUNT}" # Parse for domain if [[ "${DOMAIN_COUNT}" -ge "1" ]]; then export DOMAIN_FULL="$(echo ${HOSTNAME_DATA} | cut -d '.' -f 2-)" fi export DOMAIN_FULL="${DOMAIN_FULL-local}" # Parse for hostname export HOST_SHORT="${HOSTNAME_DATA%%.*}" if [[ "${DOMAIN_COUNT}" -ge "3" ]]; then export DOMAIN=$(echo ${HOSTNAME_DATA} | cut -d '.' -f ${DOMAIN_COUNT}-) HOST_SUB="${HOST_SHORT}.${DOMAIN_FULL/\.${DOMAIN}/}" fi # Failstate catch export HOST_SUB="${HOST_SUB-${HOST_SHORT}}" export DOMAIN="${DOMAIN-local}" # Populate ${HOSTNAME} environment variable if missing export HOSTNAME="${HOSTNAME-${HOSTNAME_DATA}}" #### Hostname config ==final #### #### Shell option config ==start #### # Configure various shell options for OPTION in ${ARRAY_SHELL_OPTIONS[@]}; do shopt -s ${OPTION} &> /dev/null done # Configure bash 4+ shell options, if we're running it if [[ "${BASH_VERSION%%.*}" -ge 4 ]]; then for OPTION in ${ARRAY_SHELL_OPTIONS_BASH4[@]}; do shopt -s ${OPTION} &> /dev/null done fi # Generate PS1 prompt with _prompt_generate function in .bashrc export PROMPT_COMMAND='_prompt_generate' #### Shell option config ==final #### # Source user's bashrc [[ -f ${HOME}/.bashrc ]] && . ${HOME}/.bashrc # vim: set syntax=sh filetype=sh ts=2 sw=2 tw=0 noet :