From: Frank Brehm Date: Wed, 17 Jun 2020 11:29:38 +0000 (+0200) Subject: Adding files/bashrc-centos8 X-Git-Tag: 2.1.2^2~9^2~31^2~29 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=b2029ac072c53f700985fefb4bcf3da8590b3b94;p=pixelpark%2Fcreate-vmware-tpl.git Adding files/bashrc-centos8 --- diff --git a/files/bashrc-centos8 b/files/bashrc-centos8 new file mode 100644 index 0000000..c232962 --- /dev/null +++ b/files/bashrc-centos8 @@ -0,0 +1,280 @@ +#!/bin/bash + +# /etc/bashrc + +# Author: Frank Brehm + +# System wide functions and aliases +# Environment stuff goes in /etc/profile + +# It's NOT a good idea to change this file unless you know what you +# are doing. It's much better to create a custom.sh shell script in +# /etc/profile.d/ to make custom changes to your environment, as this +# will prevent the need for merging in future updates. + +#------------------------------------------------------------------- +prompt_status() { + local e=$?; + [[ $e != 0 ]] && echo -e "$e "; +} + +#------------------------------------------------------------------- +append_path() { + if [[ "$#" == 0 ]] ; then + echo "append_path(): No path given." >&2 + return 2 + fi + + local verbose= + if [[ "$VERBOSE" ]] ; then + if [[ "$VERBOSE" =~ ^[n|f] || "$VERBOSE" == "0" ]] ; then + : + else + verbose=y + fi + fi + + local path= + while [[ "$#" != 0 ]] ; do + path="$1" + shift + + if [[ ! -e "${path}" ]] ; then + if [[ $verbose ]] ; then + echo "append_path(): directory '${path}' does not exists." >&2 + fi + elif [[ ! -d "${path}" ]] ; then + echo "append_path(): path '${path}' is not a directory." >&2 + continue + fi + + if [[ -z "${PATH}" ]] ; then + export PATH="${path}" + elif [[ "${PATH}" =~ ^${path}: || "${PATH}" =~ :${path}: || "${PATH}" =~ :${path}$ ]] ; then + if [[ $verbose ]] ; then + echo "append_path(): path '${path}' already included." >&2 + fi + continue + else + export PATH="${PATH}:${path}" + fi + + if [[ $verbose ]] ; then + echo "append_path(): PATH is now '${PATH}'." + fi + + done +} + +#------------------------------------------------------------------- +prepend_path() { + + if [[ "$#" == 0 ]] ; then + echo "prepend_path(): No path given." >&2 + return 2 + fi + + local verbose= + if [[ "$VERBOSE" ]] ; then + if [[ "$VERBOSE" =~ ^[n|f] || "$VERBOSE" == "0" ]] ; then + : + else + verbose=y + fi + fi + + local path= + while [[ "$#" != 0 ]] ; do + path="$1" + shift + + if [[ ! -e "${path}" ]] ; then + if [[ $verbose ]] ; then + echo "prepend_path(): directory '${path}' does not exists." >&2 + fi + elif [[ ! -d "${path}" ]] ; then + echo "prepend_path(): path '${path}' is not a directory." >&2 + continue + fi + + if [[ -z "${PATH}" ]] ; then + export PATH="${path}" + elif [[ "${PATH}" =~ ^${path}: || "${PATH}" =~ :${path}: || "${PATH}" =~ :${path}$ ]] ; then + if [[ $verbose ]] ; then + echo "prepend_path(): path '${path}' already included." >&2 + fi + continue + else + export PATH="${path}:${PATH}" + fi + + if [[ $verbose ]] ; then + echo "prepend_path(): PATH is now '${PATH}'." + fi + + done +} + +#------------------------------------------------------------------- +# console colors: + +detect_color() { + + local safe_term="${TERM//[^[:alnum:]]/?}" + local match_lhs="" + local use_color="false" + local term= + + if [[ -f ~/.dir_colors ]] ; then + match_lhs="${match_lhs}$( grep '^TERM ' ~/.dir_colors | sed -e 's/^TERM *//' -e 's/ .*//')" + fi + if [[ -f /etc/DIR_COLORS ]] ; then + match_lhs="${match_lhs}$( grep '^TERM ' /etc/DIR_COLORS | sed -e 's/^TERM *//' -e 's/ .*//')" + fi + if [[ -z ${match_lhs} ]] ; then + type -P dircolors >/dev/null && \ + match_lhs=$(dircolors --print-database | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//') + fi + for term in ${match_lhs} ; do + # shellcheck disable=SC2053 + if [[ "${safe_term}" == ${term} || "${TERM}" == ${term} ]] ; then + use_color="true" + break + fi + done + + # console colors: + if [[ "${use_color}" == "true" ]] ; then + HAS_COLOR="y" + fi + +} + + +# Prevent doublesourcing +if [[ -z "$BASHRCSOURCED" ]]; then + BASHRCSOURCED="Y" + HAS_COLOR="n" + + detect_color + + # configure history + HISTSIZE=100000 + HISTFILESIZE=100000 + HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S ' + HISTCONTROL=ignorespace + + # hold these special chars when piping to less + export LESS="--RAW-CONTROL-CHARS" + + # make less more friendly for non-text input files, see lesspipe(1) + [[ -x /bin/lesspipe ]] && eval "$(SHELL=/bin/sh lesspipe)" + + # are we an interactive shell? + if [[ "$PS1" ]]; then + + if [[ "${HAS_COLOR}" == "y" ]] ; then + if type -t __git_ps1 >/dev/null ; then + if [[ "$UID" = 0 ]]; then + PS1='\[\e[31m\]$(prompt_status)\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w\[\033[01;31m\]$(__git_ps1)\[\033[01;35m\] \$ \[\033[00m\]' + else + PS1='\[\e[31m\]$(prompt_status)\[\033[01;32m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w\[\033[01;31m\]$(__git_ps1)\[\033[01;35m\] > \[\033[00m\]' + fi + else + if [[ "$UID" = 0 ]]; then + PS1='\[\e[31m\]$(prompt_status)\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]' + else + PS1='\[\e[31m\]$(prompt_status)\[\033[01;32m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]> \[\033[00m\]' + fi + fi + else + if type -t __git_ps1 >/dev/null ; then + PS1='$(prompt_status)\u@\h \w$(__git_ps1) \$ ' + else + PS1='$(prompt_status)\u@\h \w\$ ' + fi + fi + + + if [ -z "$PROMPT_COMMAND" ]; then + + PROMPT_COMMAND='history -a' + case $TERM in + xterm*|rxvt*) + PROMPT_COMMAND='history -a; printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' + ;; + screen) + PROMPT_COMMAND='history -a; printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' + ;; + *) + [[ -e /etc/sysconfig/bash-prompt-default ]] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default + ;; + esac + fi + + # Turn on parallel history + shopt -s histappend + history -a + # Turn on checkwinsize + shopt -s checkwinsize + + alias ls='ls --color=auto' + + alias ..='cd ..' + alias ...='cd ../..' + alias cd..='cd ..' + alias cd...='cd ../..' + alias l='ls -l' + alias la='ls -la' + alias ll='ls -lA' + alias md='mkdir -p' + + + fi + + if ! shopt -q login_shell ; then # We're not a login shell + + # Need to redefine pathmunge, it gets undefined at the end of /etc/profile + pathmunge () { + case ":${PATH}:" in + *:"$1":*) + ;; + *) + if [[ "$2" == "after" ]] ; then + PATH=$PATH:$1 + else + PATH=$1:$PATH + fi + esac + } + + # By default, we want umask to get set. This sets it for non-login shell. + # Current threshold for system reserved uid/gids is 200 + # You could check uidgid reservation validity in + # /usr/share/doc/setup-*/uidgid file + if [[ "${UID}" -gt 199 && "$( id -gn )" == "$( id -un )" ]]; then + umask 002 + else + umask 022 + fi + + SHELL=/bin/bash + # Only display echos from profile.d scripts if we are no login shell + # and interactive - otherwise just process them to set envvars + for i in /etc/profile.d/*.sh; do + if [ -r "$i" ]; then + if [ "$PS1" ]; then + . "$i" + else + . "$i" >/dev/null + fi + fi + done + + unset i + unset -f pathmunge + + fi + +fi +# vim: ts=4 sw=4 et filetype=sh list