diff --git a/bashrc b/bashrc index 932188d..de3ca26 100644 --- a/bashrc +++ b/bashrc @@ -21,22 +21,6 @@ else start_agent fi -# Set environment -# Support colors in less -export LESS_TERMCAP_mb=$(tput bold; tput setaf 1) -export LESS_TERMCAP_md=$(tput bold; tput setaf 1) -export LESS_TERMCAP_me=$(tput sgr0) -export LESS_TERMCAP_se=$(tput sgr0) -export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) -export LESS_TERMCAP_ue=$(tput sgr0) -export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 2) -export LESS_TERMCAP_mr=$(tput rev) -export LESS_TERMCAP_mh=$(tput dim) -export LESS_TERMCAP_ZN=$(tput ssubm) -export LESS_TERMCAP_ZV=$(tput rsubm) -export LESS_TERMCAP_ZO=$(tput ssupm) -export LESS_TERMCAP_ZW=$(tput rsupm) - # # Alternate Paths # @@ -52,12 +36,10 @@ export LESS_TERMCAP_ZW=$(tput rsupm) # App env variables # export EDITOR='vim' -export GREP_COLOR='1;36' export HISTIGNORE="&:[ ]*:ls:ls -a:cd:cd .." # leave commands out of history log export HISTCONTROL='ignoredups' export HISTSIZE=5000 export HISTFILESIZE=5000 -export LSCOLORS='ExGxbEaECxxEhEhBaDaCaD' export PAGER='less' export TZ='America/New_York' export VAULT_TOKEN=root @@ -76,7 +58,7 @@ shopt -s nocaseglob # case-insensitive pathname expansion shopt -s autocd # enter directory without cd shopt -s cdspell # correct minor errors in directory names with cd shopt -s dirspell # attempt spelling correction on directory names in completion -shopt -s dotglob # includes filenames beginning with a `.' in filename expansion +#shopt -s dotglob # includes filenames beginning with a `.' in filename expansion shopt -s histappend # append to history file, instead of overwriting it shopt -s no_empty_cmd_completion # not attempt to search for possible completions on an empty line. shopt -s globstar # recursive globbing with ** @@ -88,9 +70,17 @@ stty -ixon # disable ^S/^Q flow control # # colors # -#alias ls='ls --color=auto' # ls colored output -export GREP_COLOR="mt=1;36" # grep colored ouput -alias grep='grep --color=auto' # grep colored ouput +if [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "sun"* ]] ; then + # BSD/macOS + export LS_COLORS='ExGxbEaECxxEhEhBaDaCaD' + echo "BSD/macOS detected: LS_COLORS set for BSD/macOS." + +else + # Linux + export LS_COLORS='di=34:ln=36:su=31;47:sg=35;47' + echo "Linux detected: LS_COLORS set for Linux." +fi +export GREP_COLOR='1;36' export LESS="-R" # less colored output export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold @@ -101,7 +91,9 @@ export LESS_TERMCAP_ue=$'\E[0m' # end underline export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline +# # Aliases +# alias ..='echo "cd .."; cd ..' alias ag='rg' # sorry silver searcher alias chomd='chmod' @@ -109,6 +101,8 @@ alias curl='curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Fir alias externalip='curl -sS https://www.daveeddy.com/ip' alias gerp='grep' alias hl='rg --passthru' +alias ls='ls --color=auto' # ls colored output +alias grep='grep --color=auto' # grep colored output alias l='ls' alias ll='ls -lrtha' alias suod='sudo' @@ -132,7 +126,87 @@ alias gs='git status' alias gt='git tag' alias gu='git pull' # gu = git update +# Prompt +# Store `tput` colors for future use to reduce fork+exec +# the array will be 0-255 for colors, 256 will be sgr0 +# and 257 will be bold +COLOR256=() +COLOR256[0]=$(tput setaf 1) +COLOR256[256]=$(tput sgr0) +COLOR256[257]=$(tput bold) + +# Colors for use in PS1 that may or may not change when +# set_prompt_colors is run +PROMPT_COLORS=() + +# Change the prompt colors to a theme, themes are 0-29 +set_prompt_colors() { + local h=${1:-0} + local color= + local i=0 + local j=0 + for i in {22..231}; do + ((i % 30 == h)) || continue + + color=${COLOR256[$i]} + # cache the tput colors + if [[ -z $color ]]; then + COLOR256[$i]=$(tput setaf "$i") + color=${COLOR256[$i]} + fi + PROMPT_COLORS[$j]=$color + ((j++)) + done +} + +# Construct the prompt +# [(exit code)] - [git branch] <$|#> + +# exit code of last process +PS1='$(ret=$?;(($ret!=0)) && echo "\[${COLOR256[0]}\]($ret) \[${COLOR256[256]}\]")' + +# username (red for root) +PS1+='\[${PROMPT_COLORS[0]}\]\[${COLOR256[257]}\]$(((UID==0)) && echo "\[${COLOR256[0]}\]")\u\[${COLOR256[256]}\]@' + + +# hostname +PS1+='\[${PROMPT_COLORS[3]}\]\h ' + +# zonename (global zone warning) +# PS1+='\[${COLOR256[0]}\]\[${COLOR256[257]}\]'"$(zonename 2>/dev/null | grep -q '^global$' && echo 'GZ:')"'\[${COLOR256[256]}\]' + +# uname +#PS1+='\[${PROMPT_COLORS[2]}\]'"$(uname | tr '[:upper:]' '[:lower:]')"' ' + +# cwd +PS1+='\[${PROMPT_COLORS[5]}\]\w ' + +# optional git branch +PS1+='$(branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null); [[ -n $branch ]] && echo "\[${PROMPT_COLORS[2]}\](\[${PROMPT_COLORS[3]}\]git:$branch\[${PROMPT_COLORS[2]}\]) ")' + +# prompt character +PS1+='\[${PROMPT_COLORS[0]}\]\$\[${COLOR256[256]}\] ' + +# set the theme +set_prompt_colors 24 + +# Prompt command +_prompt_command() { + local user=$USER + local host=${HOSTNAME%%.*} + local pwd=${PWD/#$HOME/\~} + local ssh= + [[ -n $SSH_CLIENT ]] && ssh='[ssh] ' + printf "\033]0;%s%s@%s:%s\007" "$ssh" "$user" "$host" "$pwd" +} +PROMPT_COMMAND=_prompt_command + +PROMPT_DIRTRIM=6 + + +# # Functions +# sscreate() { openssl req \ -x509 \ @@ -218,82 +292,6 @@ gmm() { # git merge $main git merge "$mb" } -# Prompt -# Store `tput` colors for future use to reduce fork+exec -# the array will be 0-255 for colors, 256 will be sgr0 -# and 257 will be bold -COLOR256=() -COLOR256[0]=$(tput setaf 1) -COLOR256[256]=$(tput sgr0) -COLOR256[257]=$(tput bold) - -# Colors for use in PS1 that may or may not change when -# set_prompt_colors is run -PROMPT_COLORS=() - -# Change the prompt colors to a theme, themes are 0-29 -set_prompt_colors() { - local h=${1:-0} - local color= - local i=0 - local j=0 - for i in {22..231}; do - ((i % 30 == h)) || continue - - color=${COLOR256[$i]} - # cache the tput colors - if [[ -z $color ]]; then - COLOR256[$i]=$(tput setaf "$i") - color=${COLOR256[$i]} - fi - PROMPT_COLORS[$j]=$color - ((j++)) - done -} - -# Construct the prompt -# [(exit code)] - [git branch] <$|#> - -# exit code of last process -PS1='$(ret=$?;(($ret!=0)) && echo "\[${COLOR256[0]}\]($ret) \[${COLOR256[256]}\]")' - -# username (red for root) -PS1+='\[${PROMPT_COLORS[0]}\]\[${COLOR256[257]}\]$(((UID==0)) && echo "\[${COLOR256[0]}\]")\u\[${COLOR256[256]}\]@' - - -# hostname -PS1+='\[${PROMPT_COLORS[3]}\]\h ' - -# zonename (global zone warning) -# PS1+='\[${COLOR256[0]}\]\[${COLOR256[257]}\]'"$(zonename 2>/dev/null | grep -q '^global$' && echo 'GZ:')"'\[${COLOR256[256]}\]' - -# uname -#PS1+='\[${PROMPT_COLORS[2]}\]'"$(uname | tr '[:upper:]' '[:lower:]')"' ' - -# cwd -PS1+='\[${PROMPT_COLORS[5]}\]\w ' - -# optional git branch -PS1+='$(branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null); [[ -n $branch ]] && echo "\[${PROMPT_COLORS[2]}\](\[${PROMPT_COLORS[3]}\]git:$branch\[${PROMPT_COLORS[2]}\]) ")' - -# prompt character -PS1+='\[${PROMPT_COLORS[0]}\]\$\[${COLOR256[256]}\] ' - -# set the theme -set_prompt_colors 24 - -# Prompt command -_prompt_command() { - local user=$USER - local host=${HOSTNAME%%.*} - local pwd=${PWD/#$HOME/\~} - local ssh= - [[ -n $SSH_CLIENT ]] && ssh='[ssh] ' - printf "\033]0;%s%s@%s:%s\007" "$ssh" "$user" "$host" "$pwd" -} -PROMPT_COMMAND=_prompt_command - -PROMPT_DIRTRIM=6 # Print all 256 colors colors() {