summaryrefslogtreecommitdiff
path: root/.config/bash/rc.sh
blob: dee42b42a76dac5c5b2ebd7c5d8b1d098acf2553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# ~/.bashrc: executed by bash(1) for non-login shells.
# 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
[[ $- != *i* ]] && return

# 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] '
export HISTSIZE=5000
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=''

################################################################################
# Overly complicated setting of PS1                                            #
################################################################################

# 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() {
	echo "${BOLD}${GREEN}\u@\h${BLUE}:\w${RESET}"
}

if 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.)
	RESET="$(tput sgr0)"
	BOLD="$(tput bold)"
	RED="$(tput setaf 1)"
	GREEN="$(tput setaf 2)"
	BLUE="$(tput setaf 4)"

	_STATUS="${BOLD}["
	_STATUS+="\$(v=\$?; [[ \$v = 0 ]] && c='${GREEN}' || c='${RED}'; printf %s%03i \$c \$v)"
	_STATUS+="${RESET}${BOLD}]${RESET}"
else
	_STATUS='[$?]'
fi
PS1="${_STATUS} $(make_prompt)"'\n\$ '
unset RESET BOLD RED GREEN BLUE _STATUS
PS1="$(term-title $(make_prompt))$PS1"
unset make_prompt

################################################################################

# Load my alaises
if [[ -f ${XDG_CONFIG_HOME}/bash/aliases.sh ]]; then
	. ${XDG_CONFIG_HOME}/bash/aliases.sh
fi

# 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