]> code.delx.au - dotfiles/blobdiff - .bashrc
bash: pre-exec xterm titlebar
[dotfiles] / .bashrc
diff --git a/.bashrc b/.bashrc
index bd586785cad1e68b82a4d9e8da03600f7fbe5971..8a8408861533eec7bc4aecec7fd241679aa5ca91 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -1,3 +1,5 @@
+# shellcheck disable=SC1090 disable=SC1091 # -- Can't follow non-constant source
+
 ###########################
 # Settings for all shells #
 ###########################
@@ -12,19 +14,21 @@ fi
 # Add ~/bin and subdirs to PATH if needed
 while read -r p; do
     echo "$PATH" | tr ':' '\n' | grep -qxF "$p" || PATH="${p}:$PATH"
-done < <(find ~/bin -type d 2> /dev/null)
+done < <(find -L ~/bin -maxdepth 1 -type d 2> /dev/null)
 
 # Set EMAIL from the freedesktop environment.d
-if [ -r ~/.config/environment.d/10-email.conf ]; then
-    # shellcheck disable=SC1090
-    source ~/.config/environment.d/10-email.conf
-    export EMAIL
+if ls ~/.config/environment.d/*.conf &> /dev/null; then
+    eval "$(awk -F= '{print $0 ";export " $1}' ~/.config/environment.d/*.conf)"
 fi
 
-# Pick up SSH agent socket in case it isn't set automatically
+# Pick up SSH agent socket
 if [ -z "$SSH_AUTH_SOCK" ]; then
-    SSH_AUTH_SOCK="/run/user/$(id -u)/keyring/ssh"
-    export SSH_AUTH_SOCK
+    if [ -r ~/.ssh-agent.env ]; then
+        source ~/.ssh-agent.env
+    else
+        SSH_AUTH_SOCK="/run/user/$(id -u)/keyring/ssh"
+        export SSH_AUTH_SOCK
+    fi
 fi
 
 
@@ -57,6 +61,7 @@ export HISTCONTROL='erasedups:ignoredups:ignorespace'
 export HISTSIZE='100000'
 export HISTTIMEFORMAT='%F %T '
 
+[ -r /etc/bash_completion ] && source /etc/bash_completion
 
 ##################
 # Terminal setup #
@@ -65,9 +70,8 @@ export HISTTIMEFORMAT='%F %T '
 # Disable CTRL-s / CTRL-q
 stty -ixon
 
-# hostname:workingdir
-PROMPT_COMMAND='echo -ne "\\033]0;$(hostname| cut -d. -f1):${PWD/$HOME/~}\\007"'
-
+# Use dark background colors in apps like vim
+export COLORFGBG='15;0'
 
 #############
 # Fancy PS1 #
@@ -86,7 +90,13 @@ function find_up_exists {
     return 1
 }
 
-[ -r /usr/share/git/completion/git-prompt.sh ] && source /usr/share/git/completion/git-prompt.sh
+for p in /usr/lib/git-core/git-sh-prompt \
+         /usr/share/git/completion/git-prompt.sh \
+         /usr/local/share/git-core/contrib/completion/git-prompt.sh
+do
+    [ -r "$p" ] && source "$p" && break
+done
+
 function my_git_ps1 {
     find_up_exists .git || return
     GIT_PS1_SHOWDIRTYSTATE=1 \
@@ -105,7 +115,7 @@ function my_svn_ps1 {
     find_up_exists .svn || return
     local status
     status="$(svn status --ignore-externals 2> /dev/null | cut -c1 | sort -u | tr -d ' \n')"
-    [ -n "$status" ] && echo -n " ($s)"
+    [ -n "$status" ] && echo -n " ($status)"
 }
 
 # Two line prompt
@@ -167,8 +177,7 @@ fi
 ##########################
 
 # GNU ls colours
-# shellcheck disable=SC2046
-eval $(TERM=xterm dircolors 2> /dev/null)
+eval "$(TERM=xterm dircolors 2> /dev/null)"
 
 # BSD ls colours
 export LSCOLORS="ExFxCxDxBxEGEDABAGACAD"
@@ -217,7 +226,7 @@ alias bc='bc -ql'
 alias watch='watch -n1'
 alias sudo='sudo ' # ability to use aliases with sudo
 alias sudosu='sudo su -l -s /bin/bash'
-alias py='PYTHONSTARTUP=~/.pythonrc.py python'
+alias python='PYTHONSTARTUP=~/.pythonrc.py python3'
 alias webshare='python3 -mhttp.server'
 
 if ! command -v pbcopy &> /dev/null; then
@@ -229,14 +238,13 @@ fi
 
 # man with coloured headings and a terminal title
 function man {
-    echo -ne "\\033]0;man $*\\007"
-
     env \
         LESS_TERMCAP_md=$'\E[01;38;5;74m' \
         LESS_TERMCAP_me=$'\E[0m' \
         LESS_TERMCAP_us=$'\E[04;38;5;146m' \
         LESS_TERMCAP_ue=$'\E[0m' \
-    man --encoding ascii "$@"
+        LC_CTYPE=C \
+    man "$@"
 }
 
 # Creates the directory if it doesn't exist, and changes into it
@@ -265,6 +273,26 @@ function ssh_unsafe {
     ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"
 }
 
+
+#########################
+# Optional local config #
+#########################
+
+[ -r ~/.bashrc_local ] && source ~/.bashrc_local
+
+
+##################
+# xterm titlebar #
+##################
+
+# When at a prompt display `hostname:workingdir`
+PROMPT_COMMAND='echo -ne "\\033]0;$(hostname|cut -d. -f1):${PWD/$HOME/\~}\\007"'
+
+# Display the command about to be executed
+# This must go at the end of bashrc to avoid running the trap on commands in the bashrc
+trap 'echo -ne "\\033]0;$BASH_COMMAND\007"' DEBUG
+
+
 ###########
 # The end #
 ###########