X-Git-Url: https://arthur.barton.de/gitweb/?p=ConfigScripts.git;a=blobdiff_plain;f=sys%2Fbashrc;h=190e1df293cb4e8146a0afb1f04a2106ceea441e;hp=5f06233100a012015382e57ec029674fb0f2c8b0;hb=2c2c42d14e811665c13602c2a44d204f7725e601;hpb=091b3921138c012f8e7604de77b4a39c894ec19b diff --git a/sys/bashrc b/sys/bashrc index 5f06233..190e1df 100644 --- a/sys/bashrc +++ b/sys/bashrc @@ -1,24 +1,57 @@ # # /etc/bash.bashrc: System-wide rc file for interactive bash(1) shells. -# Written 2003-2011 by Alexander Barton (alex@barton.de) +# Written 2003-2015 by Alexander Barton (alex@barton.de) # -[ -e ~/.ConfigScripts.debug ] && echo " >> /etc/bash.bashrc ..." +[ -e ~/.ConfigScripts.debug ] && echo " .. /etc/bash.bashrc ..." BASHRCREAD="true" [ -z "$PROFILEREAD" -a -r /etc/profile ] && source /etc/profile +[ -z "$PROFILEREAD" -a -r ~/.etc/profile ] && source ~/.etc/profile + +[ -e ~/.ConfigScripts.debug ] && echo " >> /etc/bash.bashrc ..." # Interactive shell? -[ "$PS1" ] || return +case "$-" in + *i*) ;; + *) return ;; +esac -# Shell options -shopt -s checkwinsize -shopt -s cdspell -shopt -s histappend +# Initialize keychain(1) ssh-agent and gpg-agent helper +[ -e ~/.ConfigScripts.debug ] && echo " - keychain ..." +type -t keychain >/dev/null \ + && eval "`keychain --agents ssh --eval --inherit any-once --quick --quiet`" + +# Common command aliases (1/2) +alias ".."="cd .." +alias "ls"="ls -F" +alias "ll"="ls -l" +alias "l"="ll -a" + +# Shell options (1/2) set mark-directories on set mark-symlinked-directories on HISTCONTROL=ignoredups +HISTSIZE=500 +HISTFILESIZE=2000 + +# Shell prompt +PS1="\u@\h:\w \$ " + +# Make sure that the following commands are only run with bash >= 2.x +case "$BASH_VERSION" in + "0."*|"1."*) return; ;; + *) +esac + +# Shell options (2/2) +[ -e ~/.ConfigScripts.debug ] && echo " - shell options ..." +shopt -s checkwinsize +shopt -s cdspell +shopt -s histappend +shopt -s histreedit +shopt -s histverify # Shell functions sshnew() { @@ -28,7 +61,12 @@ sshtmp() { ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" "$@" } +# Map up & down to history search once a command has been started +bind '"\e[A":history-search-backward' +bind '"\e[B":history-search-forward' + # Colors +[ -e ~/.ConfigScripts.debug ] && echo " - colors ..." case "$TERM" in ansi|cons25|cygwin|dtterm|linux|rxvt|screen*|vt100|vt200|vt220|vt320| \ xterm|xterm-color|xterm-256color) @@ -55,6 +93,7 @@ case "$TERM" in COLOR_PROMPT_USER="\[\e[1;32m\]" COLOR_PROMPT_ROOT="\[\e[1;31m\]" COLOR_VCS="\[\e[1;33m\]" + COLOR_HISTORY=$reset # colors for less(1) pager export LESS_TERMCAP_mb=$'\E[1;33m' @@ -67,35 +106,43 @@ case "$TERM" in esac # Enable bash completion, if available -[ -z "$BASH_COMPLETION" -a -r /etc/bash_completion ] \ - && source /etc/bash_completion -[ -z "$BASH_COMPLETION" -a -r /opt/homebrew/etc/bash_completion ] \ - && source /opt/homebrew/etc/bash_completion -[ -z "$BASH_COMPLETION" -a -r /opt/local/etc/bash_completion ] \ - && source /opt/local/etc/bash_completion +if ! shopt -oq posix; then + [ -e ~/.ConfigScripts.debug ] && echo " - bash completion ..." + [ -z "$BASH_COMPLETION" -a -r /etc/bash_completion ] \ + && source /etc/bash_completion + [ -z "$BASH_COMPLETION" -a -r /usr/local/etc/bash_completion ] \ + && source /usr/local/etc/bash_completion + [ -z "$BASH_COMPLETION" -a -r /opt/homebrew/etc/bash_completion ] \ + && source /opt/homebrew/etc/bash_completion + [ -z "$BASH_COMPLETION" -a -r /opt/local/etc/bash_completion ] \ + && source /opt/local/etc/bash_completion +fi -# Shell prompt -PS1_Path() { - P="${PWD/$HOME/~}" - echo "${P/???????????????????????????????*/${P:0:8}...${P: -20}}" -} +# Enable local virtualenvwrapper installation, if available +[ -e ~/.ConfigScripts.debug ] && echo " - virtualenvwrapper ..." +[ -r /usr/local/bin/virtualenvwrapper.sh ] \ + && source /usr/local/bin/virtualenvwrapper.sh +# Shell prompt +[ -e ~/.ConfigScripts.debug ] && echo " - prompt ..." PS1="${COLOR_PREPOSTTXT}${PS1_BEGIN:-<}" -[ "$UID" -eq 0 ] \ +[ "$LOGNAME" = "root" ] \ || PS1="${PS1}${COLOR_USER}\u${COLOR_AT}@" PS1="${PS1}${COLOR_HOST}\h" PS1="${PS1}${COLOR_COLON}:" -PS1="${PS1}${COLOR_PATH}\$(PS1_Path)" +PS1="${PS1}${COLOR_PATH}\W " +PS1="${PS1}${COLOR_HISTORY}\!" PS1="${PS1}${COLOR_PREPOSTTXT}${PS1_END:->}${COLOR_RESET} " -[ "$UID" -eq 0 ] \ +[ "$LOGNAME" = "root" ] \ && PS1="${PS1}${COLOR_PROMPT_ROOT}\\\$${COLOR_RESET} " \ || PS1="${PS1}${COLOR_PROMPT_USER}\\\$${COLOR_RESET} " -[ "$(type -t __git_ps1)" ] \ +type -t __git_ps1 >/dev/null \ && PS1="\$(__git_ps1 '(${COLOR_VCS}%s${COLOR_RESET}) ')${PS1}" PS1="${chroot_name:+[${COLOR_CHROOT}$chroot_name${COLOR_RESET}] }${PS1}" PS1="${COLOR_RESET}${PS1}" # If the command-not-found package is installed, use it +[ -e ~/.ConfigScripts.debug ] && echo " - command_not_found ..." if [ -r /etc/bash_command_not_found ]; then . /etc/bash_command_not_found elif [ -x /usr/lib/command-not-found ]; then @@ -110,16 +157,13 @@ elif [ -x /usr/lib/command-not-found ]; then } fi -# Common command aliases -alias ","="clear && logout" -alias ".."="cd .." -alias "ls"="ls -F" -alias "ll"="ls -l" -alias "l"="ll -a" +# Common command aliases (2/2) +[ -e ~/.ConfigScripts.debug ] && echo " - aliases ..." alias "lasth"="last | head -n \`expr \\\$LINES - 2\`" +alias "lastf"="last | grep -v \"^\$LOGNAME\"" # Aliases for screen(1), if installed -type -p screen >/dev/null 2>&1 +type -t screen >/dev/null if [ $? -eq 0 ]; then alias "s"="screen" alias "sr"="screen -dr" @@ -127,23 +171,16 @@ if [ $? -eq 0 ]; then fi # less(1) filter, if available -type -p lesspipe >/dev/null 2>&1 && eval `lesspipe` - -# Initialize ccache(1), if installed -if [ -d "/usr/lib/ccache" ]; then - PATH="/usr/lib/ccache:$PATH" - # Set the cache directory to local storage, if available - [ -w "/usr/local/home/$USER" ] \ - && export CCACHE_DIR="/usr/local/home/$USER/.ccache" -fi +type -t lesspipe >/dev/null \ + && eval `lesspipe` # Setup slrn(1) and cleanscore(1), if installed -type -p cleanscore >/dev/null 2>&1 -[ $? -eq 0 ] && alias slrn="cleanscore -f ~/.slrnscore && slrn" +type -t cleanscore >/dev/null \ + && alias slrn="cleanscore -f ~/.slrnscore && slrn" -# Enable color support of ls(1) and also add handy aliases +# Enable color support of ls(1) if [ "$TERM" != "dumb" ]; then - type -p dircolors >/dev/null 2>&1 && eval `dircolors -b` + type -t dircolors >/dev/null && eval `dircolors -b` ls --color / >/dev/null 2>&1 if [ $? -eq 0 ]; then # "GNU style" @@ -158,9 +195,10 @@ if [ "$TERM" != "dumb" ]; then fi # If this is an xterm set the title to user@host:dir +[ -e ~/.ConfigScripts.debug ] && echo " - prompt command ..." case $TERM in xterm*|rxvt|screen) - PROMPT_COMMAND='printf "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' + PROMPT_COMMAND='printf "\033]0;${LOGNAME}@${HOSTNAME}: ${PWD}\007"' ;; *) ;; @@ -169,6 +207,6 @@ esac # Source local files, if readable [ -r "/etc/bashrc.local" ] && source /etc/bashrc.local [ -r "/etc/bash.bashrc.local" ] && source /etc/bash.bashrc.local -[ -r "/var/lib/$ME/bash.bashrc" ] && source /var/lib/$ME/bash.bashrc +[ -r "/var/lib/$HOSTNAME/bash.bashrc" ] && source /var/lib/$HOSTNAME/bash.bashrc # -eof-