1 ###########################
2 # Settings for all shells #
3 ###########################
5 # Set umask, depending on the user ID
6 if [ "$(id -un)" = "root" ]; then
12 # Add ~/bin and subdirs to PATH if needed
14 echo "$PATH" | tr ':' '\n' | grep -qxF "$p" || PATH="${p}:$PATH"
15 done < <(find ~/bin -type d 2> /dev/null)
17 # Set EMAIL from the freedesktop environment.d
18 if [ -r ~/.config/environment.d/10-email.conf ]; then
19 # shellcheck disable=SC1090
20 source ~/.config/environment.d/10-email.conf
24 # Pick up SSH agent socket in case it isn't set automatically
25 if [ -z "$SSH_AUTH_SOCK" ]; then
26 SSH_AUTH_SOCK="/run/user/$(id -u)/keyring/ssh"
31 ###########################
32 # Interactive shells only #
33 ###########################
35 if [ -z "${PS1}" ]; then
44 # Bash should check the terminal size after every command terminates
47 # Don't attempt to tab-complete an empty line
48 shopt -s no_empty_cmd_completion
50 # Prevent overwriting existing files on stdout redirection
56 export HISTCONTROL='erasedups:ignoredups:ignorespace'
57 export HISTSIZE='100000'
58 export HISTTIMEFORMAT='%F %T '
65 # Disable CTRL-s / CTRL-q
69 PROMPT_COMMAND='echo -ne "\\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\\007"'
76 # Revision control status for git, hg, svn
78 function find_up_exists {
81 if [ -e "$d/$1" ]; then
89 [ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
91 find_up_exists .git || return
92 GIT_PS1_SHOWDIRTYSTATE=1 \
93 GIT_PS1_SHOWUNTRACKEDFILES=1 \
94 __git_ps1 ' (%s)' 2> /dev/null
98 find_up_exists .hg || return
100 status="$(hg status | cut -c1 | sort -u | tr -d ' \n')"
104 function my_svn_ps1 {
105 find_up_exists .svn || return
107 status="$(svn status --ignore-externals 2> /dev/null | cut -c1 | sort -u | tr -d ' \n')"
108 [ -n "$status" ] && echo -n " ($s)"
113 PS1="$PS1"'\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
114 PS1="$PS1"'\[\033[01;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]'
116 if ! [[ "$TERM" =~ ^screen ]]; then
119 # matches with shelltitle in .screenrc
120 PS1="$PS1"'\n\[\033k\033\\\]\$> '
124 #################################
125 # Display return codes on error #
126 #################################
128 function print_exit_code {
129 _exit_msg="\\033[01;33mexit code: $?\\033[00m"
130 if [ -z "${BASH_SOURCE[1]}" ]; then
135 trap print_exit_code ERR
150 if emacsclient --version &> /dev/null; then
151 export ALTERNATE_EDITOR='vim'
152 export EDITOR='emacsclient --tty'
154 if [[ "$TERM" == screen* ]]; then
155 alias edit='emacsclient --tty'
157 alias edit='emacsclient --create-frame --no-wait'
165 ##########################
166 # ls aliases and colours #
167 ##########################
170 # shellcheck disable=SC2046
171 eval $(TERM=xterm dircolors 2> /dev/null)
174 export LSCOLORS="ExFxCxDxBxEGEDABAGACAD"
177 if ls --color=auto -v &> /dev/null; then
178 alias ls='ls --color=auto -v'
179 elif gls --color=auto -v &> /dev/null; then
180 alias ls='gls --color=auto -v'
181 elif ls -G &> /dev/null; then
194 alias _psresources='ps -wAo pid,user,%cpu,%mem,stat,start,time,args'
195 if [ "$(uname)" = "Linux" ]; then
196 alias pscpu='_psresources --sort -%cpu|less -S'
197 alias psmem='_psresources --sort -%mem|less -S'
198 alias pstree='ps --forest -weo pid,user:16,args --sort start_time|less -S'
199 alias pstime='ps -wAo pid,user,lstart,args --sort start_time|less -S'
201 alias pscpu='_psresources -r|less -S'
202 alias psmem='_psresources -m|less -S'
203 alias pstime='ps -wAo pid,user,lstart,args|less -S'
210 alias f='find . -iname'
211 if echo x | grep -q --color=auto x &> /dev/null; then
212 alias grep='grep --color=auto'
215 alias scp='scp -o ControlPath=none'
217 alias watch='watch -n1'
218 alias sudo='sudo ' # ability to use aliases with sudo
219 alias sudosu='sudo su -l -s /bin/bash'
220 alias py='PYTHONSTARTUP=~/.pythonrc.py python'
221 alias webshare='python3 -mhttp.server'
223 if ! command -v pbcopy &> /dev/null; then
224 alias pbcopy='xsel --clipboard --input'
225 alias pbcopym='xsel --input'
226 alias pbpaste='xsel --clipboard --output'
227 alias pbpastem='xsel --output'
230 # man with coloured headings and a terminal title
232 echo -ne "\\033]0;man $*\\007"
235 LESS_TERMCAP_md=$'\E[01;38;5;74m' \
236 LESS_TERMCAP_me=$'\E[0m' \
237 LESS_TERMCAP_us=$'\E[04;38;5;146m' \
238 LESS_TERMCAP_ue=$'\E[0m' \
239 man --encoding ascii "$@"
242 # Creates the directory if it doesn't exist, and changes into it
244 # shellcheck disable=SC2164
245 mkdir -p "$1" && cd "$1"
248 # Sets the nice and ionice priorities for the current shell to the lowest values
254 # SSH to an unknown host and print the new known_hosts entry
256 local new_known_hosts_file
257 new_known_hosts_file="$(mktemp)"
258 ssh -o UserKnownHostsFile="$new_known_hosts_file" "$@" echo 'Connection ok'
259 cat "$new_known_hosts_file"
260 rm -f "$new_known_hosts_file"
263 # SSH without verifying host key
264 function ssh_unsafe {
265 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"