aboutsummaryrefslogtreecommitdiff
path: root/misc/.bashrc
blob: 3212c8747d33b948b45f03621e21b86efbf305fa (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# If not running interactively, don't do anything.  This too is taken
# from Debian 9's bashrc.
case $- in
  *i*) ;;
  *) return;;
esac

# use emacs for editor
export EDITOR="emacsclient -c -a emacs"         # $EDITOR opens in terminal
export VISUAL="emacsclient -c -a emacs"         # $VISUAL opens in GUI mode

export LC_ALL="en_AU.utf8"

# Shorter version of a common command that it used herein.
_checkexec ()
{
    command -v "$1" > /dev/null
}

# Machine-specific and personal settings
source ~/.bashrc_local

## prompts
# git prompt
if [[ -f /usr/share/git/completion/git-prompt.sh ]]; then
  source /usr/share/git/completion/git-prompt.sh
elif [[ -f /etc/bash_completion.d/git-prompt ]]; then
  source /etc/bash_completion.d/git-prompt
fi

# prompt
RESET="\[\033[0m\]"
RED="\[\033[0;31m\]"
GREEN="\[\033[01;32m\]"
BLUE="\[\033[01;34m\]"
YELLOW="\[\033[0;33m\]"
if [ -n "$SSH_CONNECTION" ]; then
  PS_INFO="$GREEN\u@\h$RESET:$BLUE\w"
else
  PS_INFO="$RESET$BLUE\w"
fi
PS_GIT="$YELLOW\$(__git_ps1)"
PS_TIME="\[\033[\$((COLUMNS-10))G\] $RED[\t]"
PS1="\${PS_FILL}\[\033[0G\]${PS_INFO}${PS_GIT}${PS_TIME}\n${RESET}\$ "
export PS1

# Use bash-completion, if available
[[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] && \
  . /usr/share/bash-completion/bash_completion

# Enable tab completion when starting a command with 'sudo'
[ "$PS1" ] && complete -cf sudo

# Include my scripts in the PATH.
if [ -d "$HOME"/bin ]
then
  PATH=$PATH:"$HOME"/bin
fi

if [ -d "$HOME"/.local/bin ]
then
  PATH=$PATH:"$HOME"/.local/bin
fi

# from ~/.bashrc_local, adding more to PATH
my_local_add_path

export PATH

# Default pager.  Note that the option I pass to it will quit once you
# try to scroll past the end of the file.
if [ "$TERM" = "dumb" ]
then
  export PAGER="cat"
  alias less="cat"
else
  export PAGER="less --quit-at-eof"
fi

export MANPAGER="$PAGER"

# Enter directory and list contents
cd ()
{
    if [ -n "$1" ]
    then
        builtin cd "$@" && ls -pvA --color=auto --group-directories-first
    else
        builtin cd ~ && ls -pvA --color=auto --group-directories-first
    fi
}

# Back up a file. Usage "backupthis <filename>"
backupthis ()
{
    cp -riv $1 ${1}-$(date +%Y%m%d%H%M).backup;
}

# append to history file. don't overwrite it.
shopt -s histappend
# increase history size to infinity
export HISTSIZE=-1
export HISTFILESIZE=-1
# ignore ls and history in history
export HISTIGNORE="ls:history"
export HISTTIMEFORMAT="[%F %T] "
export HISTCONTROL=ignoreboth

# aliases
test -s ~/.alias && . ~/.alias || true
alias shutdown='sudo /sbin/shutdown -hP now'
alias reboot='sudo /sbin/reboot'
alias wifi-menu='sudo /usr/bin/wifi-menu'
alias cd-='cd -'
alias cd#='cd ~'
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias ls='ls --color=always'
alias l.='ls -d .* --color=auto'
alias ll='ls -l'
alias updatedb='sudo updatedb'
# wget it like it's curl
alias wgets="wget -O- 2>/dev/null"
# this allows to open an url with tor-browser from within emacs, see
# `my-browse-url-tor-browser'
alias tor-browser="tor-browser --allow-remote"
alias which='alias | which -i'
alias chx="chmod +x"
# dedicated emacs instances for emms and erc, see `my-profile' in my
# emacs init files
alias emms='EMACS_PROFILE=emms emacs'
alias erc='EMACS_PROFILE=erc emacs'

# Safer default for cp, mv, rm.  These will print a verbose output of
# the operations.  If an existing file is affected, they will ask for
# confirmation.  This can make things a bit more cumbersome, but is a
# generally safer option.
alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -iv'

# git
alias gcgrep='git log --pretty=format:"%h %ad - %an: %<(80,trunc)%s" | grep'

# pacman package manager
if _checkexec pacman
then
  # General package management
  alias pSyu="sudo pacman -Syu"   # system upgrade
  alias pSyyu="sudo pacman -Syyu" # when updating mirrors
  alias pD="sudo pacman -D"       # set `--asdeps` or `--asexplicit`

  # Search remote database and download packages
  alias pSs="pacman -Ss"      # search remote for package
  alias pS="sudo pacman -S"   # sync download

  # Query the file database
  alias pF="pacman -F"
  pFw()
  {
    pacman -F $(which "$1")
  }

  # Search local database
  alias pQs="pacman -Qs"      # query list
  alias pQmq="pacman -Qmq"    # list foreign packages
  alias pQdt="pacman -Qdt"    # list orphans

  # Inspect packages (remote and local)
  alias pSi="pacman -Si"      # remote package details
  alias pQi="pacman -Qi"      # local package details
  alias pQl="pacman -Ql"      # local package file lists

  # Remove packages
  alias pRs="sudo pacman -Rs"     # remove package
  alias pRnsc="sudo pacman -Rnsc" # remove package recursively

  # Clear cache
  alias pcache1="sudo paccache -rk 1" # remove cache except last item
  alias pcache0="sudo paccache -ruk0" # remove all cache
fi

# from ~/.bashrc_local, more aliases
my_local_aliases

#ibus
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

#fix small vlc interface
export QT_AUTO_SCREEN_SCALE_FACTOR=0

# start the agent automatically and make sure that only one
# ssh-agent process runs at a time
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
  ssh-agent -t 600 > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
  source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi

# calibre
export CALIBRE_TEMP_DIR=$HOME/tmp

# ccache
export USE_CCACHE=1
export CCACHE_EXEC=/usr/bin/ccache

# cvs
export CVS_RSH="ssh"

# from ~/.bashrc_local, export more stuff
my_local_export