summaryrefslogtreecommitdiffstats
path: root/.config/bash/bashrc
blob: bd3994b7a12595964bb16ba8decb8c013e550613 (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
# bashrc
#
# Sourced by `~/.bashrc` (which is executed by non-login interactive shells)

[[ $- != *i* ]] && return # if not running interactively, stop

function source_if_readable() {
	local f="${1:?file argument missing}"
	# shellcheck disable=1090
	if [[ -r $f ]]; then source "$f"; fi
}

# The terminal consumes certain characters before the shell see them. This
# disables them so Readline can bind them.
#
# `stty` settings live on the terminal device, not in the shell process.
#
#   -ixon               Ctrl+S and Ctrl+Q (output flow control)
#   werase undef        Ctrl+W (erase word)
stty -ixon werase undef

# ** expands to all files and directories recursively
# **/ expands to all directories recursively
shopt -s globstar
shopt -s extglob # extended pattern matching (like `?(a|b|c)`)

alias r="fc -s" # See <term://bash -c 'fc --help'>
alias wl-copy="wl-copy --trim-newline"
alias trash='gio trash'
alias l='ls -l --human-readable'
alias mv='mv --interactive' # Prompt before overwriting
alias cp='cp --interactive' # Prompt before overwriting

export INPUTRC="$HOME/.config/bash/inputrc" # Readline configuration
export VISUAL=nvim EDITOR=nvim              # used by various programs like `git`, `fc`, `man`, …
export MANPAGER="nvim +Man!" MANWIDTH=120   # `nvim` as pager for `man`

# Colors and prompt
# The terminal emulator sets $TERM
if [[ $TERM == +(xterm-256color|tmux-256color|foot) ]]; then
	eval "$(dircolors --bourne-shell)" # Set LS_COLORS which is used by other programs
	alias ls='ls --color=auto'
	alias grep='grep --color=auto'
	alias yay='yay --color auto'
	alias pacman='pacman --color auto'
	alias bat='bat --color=always'
	export LESS="--RAW-CONTROL-CHARS" # `less` display colors instead of the raw escape sequences
	source_if_readable "$HOME/.config/bash/prompt"
fi

# History
shopt -s histappend             # append to instead of overwriting HISTFILE
export HISTSIZE=10000           # number of commands to save in history
export HISTTIMEFORMAT='%F %T  ' # history entry timesptamp format, also enables multi-line entries
export HISTFILESIZE=-1          # don't truncate history
export HISTCONTROL="ignoreboth" # don't save duplicate lines or lines starting with a space

# Completion
source_if_readable /usr/share/bash-completion/bash_completion # see https://github.com/scop/bash-completion/#bash-completion
source_if_readable "$HOME/.config/fzf/fzf.bash"               # fzf configuration

source_if_readable "$HOME/.config/bash/localrc" # local configuration

# vim: ft=bash