From 09a810495f5a4be7a5d4a9d0e0460afa05687676 Mon Sep 17 00:00:00 2001 From: "Gal@Shefet" Date: Tue, 27 Sep 2022 06:32:00 -0400 Subject: [PATCH] Fixed omp prompt Fixed: .envrc shows up when `direnv` does not exists Fixed: history hook was running before _omp_hook, losing the latest error code. --- _home/dot_sz.shrc.d/10_path.env | 10 ++++++++++ _home/dot_sz.shrc.d/97_chezmoi_aliases | 4 ++-- _home/dot_sz.shrc.d/bash.post/10_oh-my-posh | 4 ++-- _home/dot_sz.shrc.d/bash.post/11_persistent.history | 3 ++- _home/dot_sz.shrc.d/bash.pre/21_aliases | 3 +++ _home/private_dot_poshtheme.omp.json | 12 ++++++------ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/_home/dot_sz.shrc.d/10_path.env b/_home/dot_sz.shrc.d/10_path.env index 6f95470..3adc226 100644 --- a/_home/dot_sz.shrc.d/10_path.env +++ b/_home/dot_sz.shrc.d/10_path.env @@ -1,3 +1,13 @@ +append_to_envvar() { + local __VAL_tmp_=$(eval "echo '$1'") + local __VAL_tmp_=$(echo "$__VAL_tmp_" | sed "s/${2}//" ) + $1=$__VAL_tmp_${2} +} +insert_to_envvar() { + local __VAL_tmp_=$(eval "echo '$1'") + local __VAL_tmp_=$(echo "$__VAL_tmp_" | sed "s/${2}//" ) + $1=${2}$__VAL_tmp_ +} get_clean_path() { sed 's/ *:\?$//g;s/`/``/g;s/:/`:`/g;s/\\`:`/\\:/g;' <<< $1 | \ awk -v RS='`:`' -v ORS='`:`' '!arr[$0]++' | \ diff --git a/_home/dot_sz.shrc.d/97_chezmoi_aliases b/_home/dot_sz.shrc.d/97_chezmoi_aliases index 71f35c0..a5b4650 100644 --- a/_home/dot_sz.shrc.d/97_chezmoi_aliases +++ b/_home/dot_sz.shrc.d/97_chezmoi_aliases @@ -1,7 +1,7 @@ if [[ -n "$(which-command chezmoi)" ]]; then export CHEZMOIROOT="$(chezmoi source-path)" - export CZ="$CHEZMOIROOT/_home" - export CZ_X="$CHEZMOIROOT/_externals" + export CZ="$CHEZMOIROOT" + export CZ_X="$(readlink -f $CHEZMOIROOT/../_externals)" alias czcd="cd $CZ" alias czxcd="cd $CZ_X" 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 a598361..cb1d1d6 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,6 +1,6 @@ if [[ -n "$(which-command oh-my-posh)" ]]; then OHMYPOSH_CONFIG='' - [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json" - eval "$(oh-my-posh init bash --config $OHMYPOSH_CONFIG)" + [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="--config ~/.poshtheme.omp.json" + eval "$(oh-my-posh init bash $OHMYPOSH_CONFIG)" unset OHMYPOSH_CONFIG fi diff --git a/_home/dot_sz.shrc.d/bash.post/11_persistent.history b/_home/dot_sz.shrc.d/bash.post/11_persistent.history index 0a5fcde..dbc87ef 100644 --- a/_home/dot_sz.shrc.d/bash.post/11_persistent.history +++ b/_home/dot_sz.shrc.d/bash.post/11_persistent.history @@ -4,4 +4,5 @@ export HISTFILESIZE=100000 # big big history shopt -s histappend # append to history, don't overwrite it # Save and reload the history after each command finishes -export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" +[[ -z "$(printenv PROMPT_COMMAND | grep 'history -')" ]] && \ + export PROMPT_COMMAND="$PROMPT_COMMAND; history -a; history -c; history -r" diff --git a/_home/dot_sz.shrc.d/bash.pre/21_aliases b/_home/dot_sz.shrc.d/bash.pre/21_aliases index f4bb23a..0fda67a 100644 --- a/_home/dot_sz.shrc.d/bash.pre/21_aliases +++ b/_home/dot_sz.shrc.d/bash.pre/21_aliases @@ -1,4 +1,7 @@ alias which-command="type -fP " +function which-command() { + type -fP "${@}" +} function add-alias-to-bash-completion-code() { local CMD=$(printf "%s" "sed '" 's/\(complete\W.*-F\W.*' "$1" '.*$\)/\1 ' "$2/g'") diff --git a/_home/private_dot_poshtheme.omp.json b/_home/private_dot_poshtheme.omp.json index 89d46a7..fe8bca3 100644 --- a/_home/private_dot_poshtheme.omp.json +++ b/_home/private_dot_poshtheme.omp.json @@ -81,9 +81,9 @@ "style": "powerline", "properties": { "shell": "bash", - "command": "type -t direnv *>/dev/null && { direnv status *>&1 || true; } | grep \"Found RC allowed\"; true" + "command": "type -t direnv 2>/dev/null && { direnv status 2>&1 || true; } | grep \"Found RC allowed\"; true" }, - "template": "." + "template": "{{ if .Output }}.{{ end }}" }, { "type": "command", @@ -100,9 +100,9 @@ "trailing_diamond": "▓", "properties": { "shell": "bash", - "command": "type -t direnv *>/dev/null && { direnv status *>&1 || true; } | grep \"Found RC allowed\"; true" + "command": "type -t direnv 2>/dev/null && { direnv status 2>&1 || true; } | grep \"Found RC allowed\"; true" }, - "template": "envrc" + "template": "{{ if .Output }}envrc{{ end }}" } ] }, @@ -281,7 +281,7 @@ "invert_powerline": true, "powerline_symbol": "", "properties": { - "always_enabled": true + "always_enabled": false }, "style": "powerline", "template": "{{ if gt .Code 0 }}{{ .Meaning }}{{ else }}✔{{ end }} ", @@ -333,7 +333,7 @@ "invert_powerline": true, "style": "powerline", "powerline_symbol": "", - "template": "sw{{ printf \"%.0f%%\" .SwapPercentUsed }}", + "template": "   {{ printf \"%.0f%%\" .SwapPercentUsed }}", "type": "sysinfo" }, {