From 12f86b412b281d7c10b36eed13159a05873fc050 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 18:11:04 +0100 Subject: [PATCH 1/8] [bash] remove hosts from hostname colouring --- bash/bash.d/prompt_command | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/bash/bash.d/prompt_command b/bash/bash.d/prompt_command index 0d961a1..046cdd2 100644 --- a/bash/bash.d/prompt_command +++ b/bash/bash.d/prompt_command @@ -58,18 +58,11 @@ function __colored_hostname() { local PS1 if color ; then - case "${HOSTNAME%%.*}" in - 'esson') PS1+="${IGre}\h${RCol}";; - 'tinsmith') PS1+="${Gre}\h${RCol}";; - 'blacksmith') PS1+="${Blu}\h${RCol}";; + case "${HOST%%.*}" in 'locksmith') PS1+="${Pur}\h${RCol}";; 'bladesmith') PS1+="${Yel}\h${RCol}";; 'gunsmith') PS1+="${Red}\h${RCol}";; 'goldsmith') PS1+="${IYel}\h${RCol}";; - 'lilo'*) PS1+="${BWhi}\h${RCol}";; - 'hg'*) PS1+="${BRed}\h${RCol}";; - 'gouda'|'bunnik'|'houten'|'zandberg'|'bussum'|'baarn') PS1+="${Gre}${On_Whi}HEF:${Blu}${On_Whi}\h${RCol}";; - 'messier'*) PS1+="${Blu}Astro:${Red}\h${RCol}";; *) PS1+="${Blu}${On_Whi}\h${RCol}";; esac else From b8f391ae2012532cbb3dedba17bfe85bb329e851 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 19:10:57 +0100 Subject: [PATCH 2/8] [bash] rewrite hostname colouring --- bash/bash.d/prompt_command | 49 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/bash/bash.d/prompt_command b/bash/bash.d/prompt_command index 046cdd2..8c6e3ee 100644 --- a/bash/bash.d/prompt_command +++ b/bash/bash.d/prompt_command @@ -52,21 +52,42 @@ function vte_thing() { export PROMPT_COMMAND=__prompt_command -function __colored_hostname() { - local HOST="${1:-$HOSTNAME}" +function __PS1_hostname() { + # returns a formatted hostname local color="${2:-$(color)}" - local PS1 - if color ; then - case "${HOST%%.*}" in - 'locksmith') PS1+="${Pur}\h${RCol}";; - 'bladesmith') PS1+="${Yel}\h${RCol}";; - 'gunsmith') PS1+="${Red}\h${RCol}";; - 'goldsmith') PS1+="${IYel}\h${RCol}";; - *) PS1+="${Blu}${On_Whi}\h${RCol}";; - esac - else - PS1+="\h" + # no colours? no need to run + if ! color ; then + echo "\h"; + return + fi + + local HOST="${1:-$HOSTNAME}" + local PS1 + local NOMATCH + local func_extension="__PS1_hostname_extended" + + # check selected hostnames + case "${HOST%%.*}" in + 'locksmith') PS1+="${Pur}\h${RCol}";; + 'bladesmith') PS1+="${Yel}\h${RCol}";; + 'gunsmith') PS1+="${Red}\h${RCol}";; + 'goldsmith') PS1+="${IYel}\h${RCol}";; + *) NOMATCH=1;; + esac + + if [ -n "${NOMATCH}" ]; then + if [ x$(type -t "$func_extension") = xfunction ]; then + NOMATCH=$($func_extension "$@") + fi + + # extended colouring + if [ -z "${NOMATCH}" ]; then + PS1+="${NOMATCH}" + # default colouring + else + PS1+="${Blu}${On_Whi}\h${RCol}"; + fi fi echo "$PS1" @@ -124,7 +145,7 @@ function __prompt_command() { PS1+="@" if color ; then - PS1+="$(__colored_hostname)" + PS1+="$(__PS1_hostname)" else PS1+="\h" fi From 28be1944fdf3a52eab43f9f8965b79a323349362 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 19:41:16 +0100 Subject: [PATCH 3/8] [bash] add a few aliases --- bash/bash.d/aliases | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bash/bash.d/aliases b/bash/bash.d/aliases index 88f5da7..b0cf7ca 100644 --- a/bash/bash.d/aliases +++ b/bash/bash.d/aliases @@ -8,6 +8,7 @@ if [ -x /usr/bin/dircolors ]; then alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' + alias ip='ip --color=auto' fi # some more ls aliases @@ -17,12 +18,19 @@ alias la='ls -A' alias lla='ll -A' alias l='ls -CF' +# make mkdir nicer +alias mkdir='mkdir -p -v' + # Use vim if possible instead of vi if [[ $(command -v vim) ]]; then alias vi='vim' else alias vim='vi' fi +alias e="${EDITOR:-vi}" + +# Alias expansion in sudo arguments +alias sudo='sudo ' # Reload bashrc alias bashreload="source ~/.bashrc" @@ -33,6 +41,7 @@ alias pc='python -ic "from __future__ import division; from math import *"' # Moving around alias ~='cd ~' alias ..='cd ..' +alias ...='cd ../../' # Computer control alias blank='sleep 1s && xset dpms force off' From f67517fdec83bd9f8a0f4d90dd63677073447db0 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 19:47:56 +0100 Subject: [PATCH 4/8] [bash] remove unused files --- bash/bash.d/aliases | 4 ++++ bash/bash.d/fortune | 10 ---------- bash/bash.d/lol | 3 --- 3 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 bash/bash.d/fortune delete mode 100644 bash/bash.d/lol diff --git a/bash/bash.d/aliases b/bash/bash.d/aliases index b0cf7ca..62ba717 100644 --- a/bash/bash.d/aliases +++ b/bash/bash.d/aliases @@ -46,3 +46,7 @@ alias ...='cd ../../' # Computer control alias blank='sleep 1s && xset dpms force off' alias lock='blank; xscreensaver-command --lock' + +# whatever +alias shrug="echo '¯\_(ツ)_/¯'" +alias pinguin="echo 🐧" diff --git a/bash/bash.d/fortune b/bash/bash.d/fortune deleted file mode 100644 index 21b8679..0000000 --- a/bash/bash.d/fortune +++ /dev/null @@ -1,10 +0,0 @@ -# Give a fortune cookie -if [[ $(command -v fortune) ]] -then - if [[ $(command -v cowsay) ]] - then - fortune -so | cowsay -n - else - fortune -so - fi -fi diff --git a/bash/bash.d/lol b/bash/bash.d/lol deleted file mode 100644 index 7b64c3e..0000000 --- a/bash/bash.d/lol +++ /dev/null @@ -1,3 +0,0 @@ -#LOL -alias shrug="echo '¯\_(ツ)_/¯'" -alias pinguin="echo 🐧" From 6b0d6af2f89fb2a0e0ddcfb6d85cf31a173af3d4 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 20:07:37 +0100 Subject: [PATCH 5/8] [bash] rename bash/rc and bash/bash.d --- .install.conf.yaml | 2 +- bash/{rc => bashrc} | 4 ++-- bash/{bash.d/aliases => bashrc.d/aliases.bash} | 2 +- bash/{bash.d/colours => bashrc.d/colours.bash} | 0 bash/{bash.d/gpg-agent => bashrc.d/gpg-agent.bash} | 0 bash/{bash.d/history => bashrc.d/history.bash} | 0 bash/{bash.d => bashrc.d}/network.bash | 0 .../{bash.d/password-store => bashrc.d/password-store.bash} | 0 .../{bash.d/prompt_command => bashrc.d/prompt_command.bash} | 0 profiles/main.sh | 6 ++++-- 10 files changed, 8 insertions(+), 6 deletions(-) rename bash/{rc => bashrc} (89%) rename bash/{bash.d/aliases => bashrc.d/aliases.bash} (97%) rename bash/{bash.d/colours => bashrc.d/colours.bash} (100%) rename bash/{bash.d/gpg-agent => bashrc.d/gpg-agent.bash} (100%) rename bash/{bash.d/history => bashrc.d/history.bash} (100%) rename bash/{bash.d => bashrc.d}/network.bash (100%) rename bash/{bash.d/password-store => bashrc.d/password-store.bash} (100%) rename bash/{bash.d/prompt_command => bashrc.d/prompt_command.bash} (100%) diff --git a/.install.conf.yaml b/.install.conf.yaml index 8a10d85..7ce9793 100644 --- a/.install.conf.yaml +++ b/.install.conf.yaml @@ -6,7 +6,7 @@ - clean: ['~'] - link: - ~/.bashrc: bash/rc + ~/.bashrc: bash/bashrc ~/.bash_profile: bash/profile ~/.config/git/config: git/config ~/.config/git/ignore_global: git/ignore diff --git a/bash/rc b/bash/bashrc similarity index 89% rename from bash/rc rename to bash/bashrc index 43f0b49..51169f4 100644 --- a/bash/rc +++ b/bash/bashrc @@ -30,8 +30,8 @@ if [ -f /etc/bash_completion ] && ! shopt -oq posix; then fi # Load main things -if [ -d "$DOTBASH/bash.d" ]; then - for f in colours aliases history prompt_command password-store +if [ -d "$DOTBASH/bashrc.d" ]; then + for f in colours.bash aliases.bash history.bash prompt_command.bash password-store.bash network.bash do if [ -r "$DOTBASH/bash.d/$f" ]; then source "$DOTBASH/bash.d/$f" diff --git a/bash/bash.d/aliases b/bash/bashrc.d/aliases.bash similarity index 97% rename from bash/bash.d/aliases rename to bash/bashrc.d/aliases.bash index 62ba717..44e024c 100644 --- a/bash/bash.d/aliases +++ b/bash/bashrc.d/aliases.bash @@ -22,7 +22,7 @@ alias l='ls -CF' alias mkdir='mkdir -p -v' # Use vim if possible instead of vi -if [[ $(command -v vim) ]]; then +if command -v vim > /dev/null; then alias vi='vim' else alias vim='vi' diff --git a/bash/bash.d/colours b/bash/bashrc.d/colours.bash similarity index 100% rename from bash/bash.d/colours rename to bash/bashrc.d/colours.bash diff --git a/bash/bash.d/gpg-agent b/bash/bashrc.d/gpg-agent.bash similarity index 100% rename from bash/bash.d/gpg-agent rename to bash/bashrc.d/gpg-agent.bash diff --git a/bash/bash.d/history b/bash/bashrc.d/history.bash similarity index 100% rename from bash/bash.d/history rename to bash/bashrc.d/history.bash diff --git a/bash/bash.d/network.bash b/bash/bashrc.d/network.bash similarity index 100% rename from bash/bash.d/network.bash rename to bash/bashrc.d/network.bash diff --git a/bash/bash.d/password-store b/bash/bashrc.d/password-store.bash similarity index 100% rename from bash/bash.d/password-store rename to bash/bashrc.d/password-store.bash diff --git a/bash/bash.d/prompt_command b/bash/bashrc.d/prompt_command.bash similarity index 100% rename from bash/bash.d/prompt_command rename to bash/bashrc.d/prompt_command.bash diff --git a/profiles/main.sh b/profiles/main.sh index 77a7cce..9544c7b 100644 --- a/profiles/main.sh +++ b/profiles/main.sh @@ -40,7 +40,9 @@ then fi # if this is BASH source BASHRC -if [ "$BASH" ] && [ -f $DOTFILES/bash/rc ] +DOTBASHRC="$DOTFILES/bash/bashrc" +if [ "$BASH" ] && [ -r "$DOTBASHRC" ] then - source $DOTFILES/bash/rc + source "$DOTBASHRC" fi +unset DOTBASHRC From ce9fc9d75256eb49af220fe7bc86d09c58af2073 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 20:11:12 +0100 Subject: [PATCH 6/8] [bash] read .local/bashrc if available --- bash/bashrc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bash/bashrc b/bash/bashrc index 51169f4..66d3186 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -33,8 +33,8 @@ fi if [ -d "$DOTBASH/bashrc.d" ]; then for f in colours.bash aliases.bash history.bash prompt_command.bash password-store.bash network.bash do - if [ -r "$DOTBASH/bash.d/$f" ]; then - source "$DOTBASH/bash.d/$f" + if [ -r "$DOTBASH/bashrc.d/$f" ]; then + source "$DOTBASH/bashrc.d/$f" fi done fi @@ -44,6 +44,8 @@ if [ -r "$DOTBASH/$HOSTNAME.bashrc" ]; then source "$DOTBASH/$HOSTNAME.bashrc" fi -if [ -r "$HOME/.bashrc.local" ]; then - source "$HOME/.bashrc.local" -fi +# Always source a local bashrc +[ -r "$HOME/.bashrc.local" ] && source "$HOME/.bashrc.local" + +# Also check in .local for a bashrc +[ -r "$HOME/.local/bashrc" ] && source "$HOME/.local/bashrc" From c923c385666c33a1f0cf260314056b1620856143 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 20:15:22 +0100 Subject: [PATCH 7/8] [bash] read .local/bash_profile if available --- bash/profile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bash/profile b/bash/profile index 071474b..05704bc 100644 --- a/bash/profile +++ b/bash/profile @@ -1,13 +1,18 @@ # ~/.bash_profile [ -z "$DOTFILES" ] && source "$HOME/.profile" +# Always source local bash_profiles [ -r "$HOME/.bash_profile.local" ] && source "$HOME/.bash_profile.local" +[ -r "$HOME/.local/bash_profile" ] && source "$HOME/.local/bash_profile" if shopt -q login_shell then # This is a bash login shell LOGINHISTORY=~/.login.history - LOGINSTRING="$(date) ${USER}@${HOSTNAME}" - echo $LOGINSTRING > $LOGINHISTORY + if [ -w "${LOGINHISTORY}" ]; then + echo "$(date) ${USER}@${HOSTNAME}" >> $LOGINHISTORY + fi + + unset LOGINHISTORY fi From 77195d5de3d5646a9dcb78fc9065c6299c8cdbd5 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 10 Feb 2022 23:17:33 +0100 Subject: [PATCH 8/8] [bash] Read .local/bashrc.private if available --- bash/bashrc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bash/bashrc b/bash/bashrc index 66d3186..9b2ff9f 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -47,5 +47,9 @@ fi # Always source a local bashrc [ -r "$HOME/.bashrc.local" ] && source "$HOME/.bashrc.local" +# Use the local(ly linked) bashrc.private +[ -r "$HOME/.local/bashrc.private" ] && source "$HOME/.local/bashrc.private" + + # Also check in .local for a bashrc [ -r "$HOME/.local/bashrc" ] && source "$HOME/.local/bashrc"