bash: adapt bashrc for debian, taking some niceties from its bashrc
[~bandali/configs] / .bashrc
CommitLineData
a38abd4c
AB
1# Bash initialization for interactive non-login shells and
2# for remote shells (info "(bash) Bash Startup Files").
3
4# Export 'SHELL' to child processes. Programs such as 'screen'
5# honor it and otherwise use /bin/sh.
6export SHELL
7
8if [[ $- != *i* ]]
9then
10 # We are being invoked from a non-interactive shell. If this
11 # is an SSH session (as in "ssh host command"), source
12 # /etc/profile so we get PATH and other essential variables.
13 [[ -n "$SSH_CLIENT" ]] && source /etc/profile
14
15 # Don't do anything else.
16 return
17fi
18
16ff2912
AB
19if [ -n "$IS_GUIX_SYSTEM" ]; then
20 # Source the system-wide file.
21 source /etc/bashrc
22fi
d99f86cd 23
acb525a9
AB
24# from https://unix.stackexchange.com/a/55935
25a_prompt() {
26 cwd=$(sed -e "s:$HOME:~:" -e "s:\(\.\?[^/]\)[^/]*/:\1/:g" <<<$PWD)
27 printf $cwd
28}
a38abd4c
AB
29# Adjust the prompt depending on whether we're in 'guix environment'.
30if [ -n "$GUIX_ENVIRONMENT" ]
31then
32 PS1="\u@\h [env] \$(a_prompt)> "
33else
34 PS1="\u@\h \$(a_prompt)> "
35fi
acb525a9 36
d99f86cd
AB
37# i-beam cursor
38# echo -e "\033[5 q" # blinking
9daac239 39# echo -e "\033[6 q" # non-blinking
d99f86cd 40
58a81de3 41# various bash tweaks
16ff2912 42# append to the history file, don't overwrite it
58a81de3
AB
43shopt -s histappend
44shopt -s cmdhist
16ff2912
AB
45# check the window size after each command and, if necessary,
46# update the values of LINES and COLUMNS.
47shopt -s checkwinsize
48# If set, the pattern "**" used in a pathname expansion context will
49# match all files and zero or more directories and subdirectories.
50#shopt -s globstar
51# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
58a81de3
AB
52HISTSIZE=
53HISTFILESIZE=
16ff2912
AB
54# don't put duplicate lines or lines starting with space in the
55# history.
58a81de3 56HISTCONTROL=ignoreboth
16ff2912 57# ignore a few very common commands and don't add them to history
d99f86cd 58HISTIGNORE='ls:l:s:g:[bf]g:history'
58a81de3
AB
59HISTTIMEFORMAT='%F %T '
60stty stop ""
6b8582fa 61
dc9a8087 62# aliases
a38abd4c 63alias ls='ls -p --color=auto'
d99f86cd
AB
64alias l='ls -lh' # long format and human-readable sizes
65alias ll='l -A' # long format, all files
16ff2912
AB
66alias dir='dir --color=auto'
67alias vdir='vdir --color=auto'
a38abd4c 68alias grep='grep --color=auto'
16ff2912
AB
69alias fgrep='fgrep --color=auto'
70alias egrep='egrep --color=auto'
dc9a8087
AB
71alias mpv="mpv --ytdl-format mp4"
72alias mv="mv -iv"
73alias cp="cp -iv"
c036d6d7 74alias mbsync='mbsync -c "$XDG_CONFIG_HOME"/isync/mbsyncrc'
249a5298 75alias getmail='getmail --getmaildir "$XDG_CONFIG_HOME"/getmail --rcfile getmailrc'
ab79953a 76alias m="mbsync csclub; mbsync uwaterloo; mbsync shemshak; mbsync gnub"
dc9a8087 77alias best="youtube-dl -f best"
d355f997
AB
78alias e="$EDITOR"
79alias se="SUDO_EDITOR=\"emacsclient\" sudo -e"
dc9a8087
AB
80
81aur() {
82 cd ~/usr/builds
d55c009f 83 [ -d ${1} ] || git clone https://aur.archlinux.org/${1}.git
dc9a8087
AB
84 cd ${1}
85}
86
16ff2912
AB
87# separate alias definitions file, if exists
88if [ -f ~/.bash_aliases ]; then
89 . ~/.bash_aliases
90fi
91
92# enable programmable completion features (not needed if already
93# enabled in /etc/bash.bashrc and if /etc/profile sources
94# /etc/bash.bashrc).
95if ! shopt -oq posix; then
96 if [ -f /usr/share/bash-completion/bash_completion ]; then
97 . /usr/share/bash-completion/bash_completion
98 elif [ -f /etc/bash_completion ]; then
99 . /etc/bash_completion
100 fi
101fi
102
47d195d9
AB
103if [ -z "$IS_GUIX_SYSTEM" ]; then
104 if ! pgrep -u "$USER" ssh-agent > /dev/null; then
105 ssh-agent > ~/.ssh-agent-thing
106 fi
107 if [[ ! "$SSH_AUTH_SOCK" ]]; then
108 eval "$(<~/.ssh-agent-thing)"
109 fi
6e39e3a2 110fi