summaryrefslogtreecommitdiff
path: root/.config/bash/rc.sh
blob: ed55f75d68e6b2360b583fe4f0e772f41e3bc7fb (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
80
# ~/.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

# don't put duplicate lines in the history. See bash(1) for more options
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

shopt -s checkwinsize # update the values of LINES and COLUMNS
shopt -s globstar # Let ** recursively scan directories

# 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)"

# 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

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}"
}

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\$ '
else
	PS1="$(make_prompt false)"'\n\$ '
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

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
	. ${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
fi