bash_colour() function #23

Merged
sev merged 1 commits from bash_colours into master 3 years ago
  1. 9
      .bash_aliases
  2. 108
      .bash_profile

9
.bash_aliases

@ -1,9 +1,9 @@
alias 'x'='clear'
alias 'su+'='sudo -i'
alias 'ls'="/usr/bin/ls ${LS_OPTIONS} -h"
alias 'll'="/usr/bin/ls ${LS_OPTIONS} -hl"
alias 'la'="/usr/bin/ls ${LS_OPTIONS} -hla"
alias 'ls'="ls ${LS_OPTIONS} -h"
alias 'll'="ls ${LS_OPTIONS} -hl"
alias 'la'="ls ${LS_OPTIONS} -hla"
alias 'rm'='rm --preserve-root -v -I'
alias 'chown'='chown --preserve-root -v'
alias 'chmod'='chmod --preserve-root -v'
@ -11,6 +11,9 @@ alias 'mkdir'='mkdir -p -v'
alias 'grep'='grep --color=auto'
alias 'cp'='cp -r -v'
alias 'mv'='mv -v'
alias 'ip'='ip -color=auto'
alias 'dmesg'='dmesg --color=always'
alias 'diff'='diff --color=auto'
alias 'emacs'='emacs -nw'
alias '..'='cd ..'
alias 'fucking'='sudo'

108
.bash_profile

@ -1,14 +1,77 @@
#!/usr/bin/env bash
__COL_RST='\033[00m'
__COL_RED='\033[01;31m'
__COL_GRN='\033[01;32m'
__COL_YLW='\033[01;33m'
__COL_BLU='\033[01;34m'
__ROOT_PS1="\[${__COL_RED}\]\h\[${__COL_BLU}\] \w #\[${__COL_RST}\] "
__USER_PS1="\[${__COL_GRN}\]\u@\h\[${__COL_BLU}\] \w \$\[${__COL_RST}\] "
__ROOT_PS2="\[${__COL_YLW}\]|\[${__COL_RST}\] "
__USER_PS2="\[${__COL_YLW}\]|\[${__COL_RST}\] "
bash_colour() {
local ___colour=''
local ___formatting=''
local ___bg_colour=''
# Text colour
case "${1,,}" in
'reset' ) ___colour='00' ;;
'default' ) ___colour='39' ;;
'black' ) ___colour='30' ;;
'red' ) ___colour='31' ;;
'green' ) ___colour='32' ;;
'yellow' ) ___colour='33' ;;
'blue' ) ___colour='34' ;;
'magenta' ) ___colour='35' ;;
'cyan' ) ___colour='36' ;;
'white' ) ___colour='97' ;;
'light_gray' | 'l_gray' ) ___colour='37' ;;
'dark_gray' | 'd_gray' ) ___colour='90' ;;
'light_red' | 'l_red' ) ___colour='91' ;;
'light_green' | 'l_green' ) ___colour='92' ;;
'light_yellow' | 'l_yellow' ) ___colour='93' ;;
'light_blue' | 'l_blue' ) ___colour='94' ;;
'light_magenta' | 'l_magenta' ) ___colour='95' ;;
'light_cyan' | 'l_cyan' ) ___colour='96' ;;
*) ___colour='00' ;;
esac
# Text formatting
case "${2,,}" in
'normal' ) ___formatting='00' ;;
'bold' ) ___formatting='01' ;;
'underlined' ) ___formatting='04' ;;
'blink' ) ___formatting='05' ;;
'inverted' ) ___formatting='07' ;;
*) ___formatting='00';
esac
# Background colour
case "${3,,}" in
'default_background' | 'default_bg' ) ___bg_colour='49' ;;
'black_background' | 'black_bg' ) ___bg_colour='40' ;;
'red_background' | 'red_bg' ) ___bg_colour='41' ;;
'green_background' | 'green_bg' ) ___bg_colour='42' ;;
'yellow_background' | 'yellow_bg' ) ___bg_colour='43' ;;
'blue_background' | 'blue_bg' ) ___bg_colour='44' ;;
'magenta_background' | 'magenta_bg' ) ___bg_colour='45' ;;
'cyan_background' | 'cyan_bg' ) ___bg_colour='46' ;;
'white_background' | 'white_bg' ) ___bg_colour='107' ;;
'light_gray_background' | 'l_gray_bg' ) ___bg_colour='47' ;;
'dark_gray_background' | 'd_gray_bg' ) ___bg_colour='100' ;;
'light_red_background' | 'l_red_bg' ) ___bg_colour='101' ;;
'light_green_background' | 'l_green_bg' ) ___bg_colour='102' ;;
'light_yellow_background' | 'l_yellow_bg' ) ___bg_colour='103' ;;
'light_blue_background' | 'l_blue_bg' ) ___bg_colour='104' ;;
'light_magenta_background' | 'l_magenta_bg' ) ___bg_colour='105' ;;
'light_cyan_background' | 'l_cyan_bg' ) ___bg_colour='106' ;;
*) ___bg_colour='49' ;;
esac
if [[ ${___colour} -ne 00 ]] ; then
echo -n "\e[${___formatting};${___bg_colour};${___colour}m"
else
echo -n "\e[${___colour}m"
fi
}
__ROOT_PS1="\[$(bash_colour 'red' 'bold')\]\h\[$(bash_colour 'blue' 'bold')\] \w #\[$(bash_colour 'reset')\] "
__USER_PS1="\[$(bash_colour 'green' 'bold')\]\u@\h\[$(bash_colour 'blue' 'bold')\] \w \$\[$(bash_colour 'reset')\] "
__ROOT_PS2="\[$(bash_colour 'yellow' 'bold')\]|\[$(bash_colour 'reset')\] "
__USER_PS2="\[$(bash_colour 'yellow' 'bold')\]|\[$(bash_colour 'reset')\] "
__which_first_found()
{
@ -126,14 +189,19 @@ __export_lesspipe_opts() {
export LESS='-r'
fi
# Export LS_OPTIONS
if [[ -z "${LS_OPTIONS}" ]]; then
export LS_OPTIONS='--color=auto'
fi
# Add colours for less
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
export LESS_TERMCAP_mb="$(bash_colour 'red' 'bold')"
export LESS_TERMCAP_md="$(bash_colour 'red' 'bold')"
export LESS_TERMCAP_me="$(bash_colour 'reset')"
export LESS_TERMCAP_se="$(bash_colour 'reset')"
export LESS_TERMCAP_so="$(bash_colour 'yellow' 'bold' 'blue_bg')"
export LESS_TERMCAP_ue="$(bash_colour 'reset')"
export LESS_TERMCAP_us="$(bash_colour 'green' 'bold')"
}
# --- SSH agent --- #
@ -187,22 +255,22 @@ agent()
# --- MyIP resolver --- #
_myip_ip4()
{
echo -en "${__COL_BLU}IPv4:${__COL_RST} "
echo -en "$(bash_colour 'blue' 'bold')IPv4:$(bash_colour 'reset') "
curl -4 --no-keepalive \
--silent \
--connect-timeout "3" \
--get "${1}" 2>/dev/null \
|| echo -e "${__COL_RED}Unable to determine${__COL_RST}" 1>&2
|| echo -e "$(bash_colour 'red' 'bold')Unable to determine$(bash_colour 'reset')" 1>&2
}
_myip_ip6()
{
echo -en "${__COL_BLU}IPv6:${__COL_RST} "
echo -en "$(bash_colour 'blue' 'bold')IPv6:$(bash_colour 'reset') "
curl -6 --no-keepalive \
--silent \
--connect-timeout "3" \
--get "${1}" 2>/dev/null \
|| echo -e "${__COL_RED}Unable to determine${__COL_RST}" 1>&2
|| echo -e "$(bash_colour 'red' 'bold')Unable to determine$(bash_colour 'reset')" 1>&2
}
myip()

Loading…
Cancel
Save