From 1e9c2fdf6f8072002ef775a72c794170a7cea915 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 27 Nov 2012 00:12:43 -0500 Subject: largely redo my bash config --- .config/bash/aliases.sh | 3 +- .config/bash/rc.sh | 102 +++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 51 deletions(-) diff --git a/.config/bash/aliases.sh b/.config/bash/aliases.sh index 8241b95..f47bf4c 100644 --- a/.config/bash/aliases.sh +++ b/.config/bash/aliases.sh @@ -53,7 +53,6 @@ unset redshift ###################################################################### # Some almost-function aliases # ###################################################################### -xterm-title() { echo "];$@"; } # Oh, wait this one *is* a function alias lock="clear; away -C 'This terminal is locked'" -alias plock="xterm-title Terminal Locked;lock" +alias plock="term-title Terminal Locked;lock" mvln() { mv $1 $2; ln -s $2 $1; } diff --git a/.config/bash/rc.sh b/.config/bash/rc.sh index ed55f75..bfba6d4 100644 --- a/.config/bash/rc.sh +++ b/.config/bash/rc.sh @@ -1,80 +1,84 @@ # ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples - # I include this file for all interactive invocations of bash(1), whether # they are login shells or not. # If not running interactively, don't do anything -[ -z "$PS1" ] && return +[[ $- != *i* ]] && return + +# set variable identifying the chroot you work in (used in the prompt below) +if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]]; then + debian_chroot="$(cat /etc/debian_chroot)" +fi -# don't put duplicate lines in the history. See bash(1) for more options +# Why is this not on by default? +# "We have a cached value, but it isn't valid anymore. Should we trash it?" +# "Duh, yes!" +shopt -s checkhash + +################################################################################ + +# History settings export HISTCONTROL=ignoredups export HISTFILE=${XDG_CACHE_HOME}/bash/history export HISTTIMEFORMAT='[%Y-%m-%d %H:%M] ' shopt -s histappend # append to the history file, don't overwrite it +mkdir -p "${HISTFILE%/*}" +# General settings shopt -s checkwinsize # update the values of LINES and COLUMNS shopt -s globstar # Let ** recursively scan directories +PROMPT_COMMAND='' -# Why is this not on by default? -# "We have a cached value, but it isn't valid anymore. Should we trash it?" -shopt -s checkhash - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x "`which lesspipe 2>/dev/null`" ] && eval "$(SHELL=/bin/sh lesspipe)" +################################################################################ +# Overly complicated setting of PS1 # +################################################################################ -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi +# Belongs in aliases, but I use it here +term-title() { + local fmt='' + case "$TERM" in + screen|tmux) fmt='\ek%s\e\\';; + xterm*|rxvt*) fmt='\e]0;%s\a';; + esac + printf "$fmt" "$*" +} make_prompt() { - local RESET='' - local BOLD='' - local GREEN='' - local BLUE='' - if $1; then - RESET="$(tput sgr0)" - BOLD="$(tput bold)" - GREEN="$(tput setaf 2)" - BLUE="$(tput setaf 4)" - fi - local CHROOT='${debian_chroot:+($debian_chroot)}' - echo "${RESET}${BOLD}${CHROOT}${GREEN}"'\u@\h'"${RESET}:${BOLD}${BLUE}"'\w'"${RESET}" + local _CHROOT='${debian_chroot:+($debian_chroot)}' + echo "${BOLD}${_CHROOT}${GREEN}\u@\h${RESET}${BOLD}${BLUE}:\w${RESET}" } -if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then +if [[ -x /usr/bin/tput ]] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) - PS1="$(make_prompt true )"'\n\$ ' + RESET="$(tput sgr0)" + BOLD="$(tput bold)" + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + BLUE="$(tput setaf 4)" + + _STATUS="${BOLD}[" + _STATUS+='$(v=$?; if [[ $v = 0 ]]; then c='"'${GREEN}'"'; else c='"${RED}"'; fi; printf %s%03i $c $v)' + _STATUS+="${RESET}${BOLD}]${RESET}" else - PS1="$(make_prompt false)"'\n\$ ' + _STATUS='[$?]' fi - -# If this is an xterm set the title to user@host:dir -case "$TERM" in - xterm*|rxvt*) - PS1="\[\e]0;$(make_prompt false)\a\]$PS1";; -esac - +PS1="${_STATUS} $(make_prompt)"'\n\$ ' +unset RESET BOLD RED GREEN BLUE _STATUS use_color +PS1="$(term-title $(make_prompt))$PS1" unset make_prompt -# Include modular config files -if [ -d "${XDG_CONFIG_HOME}/rc.d" ]; then - for file in "${XDG_CONFIG_HOME}/rc.d"/*.sh; do - . "$file" - done -fi +################################################################################ -if [ -f ${XDG_CONFIG_HOME}/bash/aliases.sh ]; then +# Load my alaises +if [[ -f ${XDG_CONFIG_HOME}/bash/aliases.sh ]]; then . ${XDG_CONFIG_HOME}/bash/aliases.sh fi -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if [ -f /etc/bash_completion ]; then - . /etc/bash_completion +# Include modular config files +if [[ -d ${XDG_CONFIG_HOME}/bash/rc.d ]]; then + for file in "${XDG_CONFIG_HOME}/bash/rc.d"/*.sh; do + . "$file" + done fi -- cgit v1.1-4-g5e80