From 12e3c5a470b0dcf66d142ccc0cd8e7f548623b35 Mon Sep 17 00:00:00 2001 From: Lockszmith Date: Sun, 29 May 2022 00:08:37 +0000 Subject: [PATCH] Cleanup behavior to function when things are missing --- _home/dot_sz.shrc.d/00_byobu | 3 +-- _home/dot_sz.shrc.d/10_bin.path | 4 ++-- _home/dot_sz.shrc.d/21_aliases | 9 ++++++--- _home/dot_sz.shrc.d/97_keyboard_mappings | 5 +++++ _home/dot_sz.shrc.d/98_chezmoi.changes | 5 +++++ _home/dot_sz.shrc.d/99_chezmoi.changes | 1 - _home/dot_sz.shrc.d/99_final_newline | 1 + _home/dot_sz.shrc.d/99_keyboard_mappings | 3 --- _home/dot_sz.shrc.d/bash.post/10_oh-my-posh | 7 ++++++- _home/dot_sz.shrc.d/bash.post/99_chezmoi.complete | 2 +- _home/dot_sz.shrc.d/bash.post/99_gcloud.complete | 6 +++--- _home/dot_sz.shrc.d/bash.post/99_pip.completion | 2 +- _home/dot_sz.shrc.d/bash.post/99_terraform.complete | 5 +++-- _home/dot_sz.shrc.d/bash.pre/10_check_completion | 1 + 14 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 _home/dot_sz.shrc.d/97_keyboard_mappings create mode 100644 _home/dot_sz.shrc.d/98_chezmoi.changes delete mode 100644 _home/dot_sz.shrc.d/99_chezmoi.changes create mode 100644 _home/dot_sz.shrc.d/99_final_newline delete mode 100644 _home/dot_sz.shrc.d/99_keyboard_mappings create mode 100644 _home/dot_sz.shrc.d/bash.pre/10_check_completion diff --git a/_home/dot_sz.shrc.d/00_byobu b/_home/dot_sz.shrc.d/00_byobu index 7319dcc..a8fe220 100644 --- a/_home/dot_sz.shrc.d/00_byobu +++ b/_home/dot_sz.shrc.d/00_byobu @@ -1,5 +1,4 @@ -if [ -z $_byobu_sourced ]; then +if [[ -z "$_byobu_sourced" && -x /usr/bin/byobu-launch ]]; then _byobu_sourced=1 . /usr/bin/byobu-launch 2>/dev/null || true - exit fi diff --git a/_home/dot_sz.shrc.d/10_bin.path b/_home/dot_sz.shrc.d/10_bin.path index 7789ed5..d75f257 100644 --- a/_home/dot_sz.shrc.d/10_bin.path +++ b/_home/dot_sz.shrc.d/10_bin.path @@ -1,9 +1,9 @@ # set PATH so it includes user's private bin if it exists -if [ -d "$HOME/bin" ] ; then +if [[ -d "$HOME/bin" ]] ; then export PATH="~/bin:$PATH" fi # set PATH so it includes user's private bin if it exists -if [ -d "$HOME/.local/bin" ] ; then +if [[ -d "$HOME/.local/bin" ]] ; then export PATH="~/.local/bin:$PATH" fi diff --git a/_home/dot_sz.shrc.d/21_aliases b/_home/dot_sz.shrc.d/21_aliases index ca10121..b67c309 100644 --- a/_home/dot_sz.shrc.d/21_aliases +++ b/_home/dot_sz.shrc.d/21_aliases @@ -1,7 +1,10 @@ alias sudo="/usr/bin/sudo " -alias nvim="/usr/bin/nvim -p " -alias vim="nvim " -alias vi="nvim " +PREFERED_VI=$(type -fP nvim vim | head -1) +[[ -z "$PREFERED_VI" ]] && PREFERED_VI=$(type -fP vi | head -1) || alias vi_editor="$PREFERED_VI -p " +[[ -z "$PREFERED_VI" ]] && alias vi_editor='eval $EDITOR ' || alias vi_editor="$PREFERED_VI " +alias nvim="vi_editor " +alias vim="vi_editor " +alias vi="vi_editor " alias lessr="less --raw-control-chars " diff --git a/_home/dot_sz.shrc.d/97_keyboard_mappings b/_home/dot_sz.shrc.d/97_keyboard_mappings new file mode 100644 index 0000000..6a475e6 --- /dev/null +++ b/_home/dot_sz.shrc.d/97_keyboard_mappings @@ -0,0 +1,5 @@ +if [[ -n "$(type -fP setxkbmap)" ]]; then + setxkbmap -option + setxkbmap -option caps:escape + setxkbmap -option caps:ctrl_modifier +fi diff --git a/_home/dot_sz.shrc.d/98_chezmoi.changes b/_home/dot_sz.shrc.d/98_chezmoi.changes new file mode 100644 index 0000000..a1daf97 --- /dev/null +++ b/_home/dot_sz.shrc.d/98_chezmoi.changes @@ -0,0 +1,5 @@ +if [[ -n "$(type -fP chezmoi)" ]]; then + CHEZMOI_OUT="$(chezmoi status || true)x" + [[ -n "$CHEZMOI_OUT" ]] && printf "\nChezmoi changes:\n" && echo "${CHEZMOI_OUT%?}" + unset CHEZMOI_OUT +fi diff --git a/_home/dot_sz.shrc.d/99_chezmoi.changes b/_home/dot_sz.shrc.d/99_chezmoi.changes deleted file mode 100644 index d684aa9..0000000 --- a/_home/dot_sz.shrc.d/99_chezmoi.changes +++ /dev/null @@ -1 +0,0 @@ -chezmoi status || true diff --git a/_home/dot_sz.shrc.d/99_final_newline b/_home/dot_sz.shrc.d/99_final_newline new file mode 100644 index 0000000..993d3d3 --- /dev/null +++ b/_home/dot_sz.shrc.d/99_final_newline @@ -0,0 +1 @@ +echo "" diff --git a/_home/dot_sz.shrc.d/99_keyboard_mappings b/_home/dot_sz.shrc.d/99_keyboard_mappings deleted file mode 100644 index 4790b4e..0000000 --- a/_home/dot_sz.shrc.d/99_keyboard_mappings +++ /dev/null @@ -1,3 +0,0 @@ -setxkbmap -option -setxkbmap -option caps:escape -setxkbmap -option caps:ctrl_modifier diff --git a/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh b/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh index 8b1c092..597d64c 100644 --- a/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh +++ b/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh @@ -1 +1,6 @@ -eval "$(oh-my-posh init bash --config ~/.poshtheme.omp.json)" +if [[ -n "$(type -fP oh-my-posh)" ]]; then + OHMYPOSH_CONFIG='' + [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json" + eval "$(oh-my-posh init bash --config $OHMYPOSH_CONFIG)" + unset OHMYPOSH_CONFIG +fi diff --git a/_home/dot_sz.shrc.d/bash.post/99_chezmoi.complete b/_home/dot_sz.shrc.d/bash.post/99_chezmoi.complete index 95c04bd..14153a4 100644 --- a/_home/dot_sz.shrc.d/bash.post/99_chezmoi.complete +++ b/_home/dot_sz.shrc.d/bash.post/99_chezmoi.complete @@ -1 +1 @@ -source <(chezmoi completion bash) +[[ -n "$BASH_COMPLETION_EXIST" && -n $(type -fP chezmoi) ]] && source <(chezmoi completion bash) diff --git a/_home/dot_sz.shrc.d/bash.post/99_gcloud.complete b/_home/dot_sz.shrc.d/bash.post/99_gcloud.complete index 52c7a2c..85e1bb4 100644 --- a/_home/dot_sz.shrc.d/bash.post/99_gcloud.complete +++ b/_home/dot_sz.shrc.d/bash.post/99_gcloud.complete @@ -1,4 +1,4 @@ # The next line updates PATH for the Google Cloud SDK. -if [ -f '/usr/lib/google-cloud-sdk/path.bash.inc' ]; then source '/usr/lib/google-cloud-sdk/path.bash.inc'; fi -# The next line enables shell command completion for gcloud. -if [ -f '/usr/lib/google-cloud-sdk/completion.bash.inc' ]; then source '/usr/lib/google-cloud-sdk/completion.bash.inc'; fi +[[ -f '/usr/lib/google-cloud-sdk/path.bash.inc' ]] && source '/usr/lib/google-cloud-sdk/path.bash.inc' +# The next line enables shell command completion for gcloud (as long as gcloud is IN the path). +[[ -n "$(type -fP gcloud)" && -f '/usr/lib/google-cloud-sdk/completion.bash.inc' ]] && source '/usr/lib/google-cloud-sdk/completion.bash.inc' diff --git a/_home/dot_sz.shrc.d/bash.post/99_pip.completion b/_home/dot_sz.shrc.d/bash.post/99_pip.completion index b34f2ef..6b4ca05 100644 --- a/_home/dot_sz.shrc.d/bash.post/99_pip.completion +++ b/_home/dot_sz.shrc.d/bash.post/99_pip.completion @@ -1,2 +1,2 @@ -source <(pip completion --bash) +[[ -n $(type -fP pip) ]] && source <(pip completion --bash) diff --git a/_home/dot_sz.shrc.d/bash.post/99_terraform.complete b/_home/dot_sz.shrc.d/bash.post/99_terraform.complete index c6d3921..33b8b21 100644 --- a/_home/dot_sz.shrc.d/bash.post/99_terraform.complete +++ b/_home/dot_sz.shrc.d/bash.post/99_terraform.complete @@ -1,3 +1,4 @@ -if [ -r /usr/bin/terraform ]; then - complete -C /usr/bin/terraform terraform +TERRAFORM_BIN=$(type -fP terraform | head -1) +if [[ -n $TERRAFORM_BIN ]]; then + complete -C $TERRAFORM_BIN terraform fi diff --git a/_home/dot_sz.shrc.d/bash.pre/10_check_completion b/_home/dot_sz.shrc.d/bash.pre/10_check_completion new file mode 100644 index 0000000..f2427f9 --- /dev/null +++ b/_home/dot_sz.shrc.d/bash.pre/10_check_completion @@ -0,0 +1 @@ +[[ -x /usr/share/bash-completion/bash_completion ]] && BASH_COMPLETION_EXIST=1