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.
This commit is contained in:
Gal@Shefet 2022-09-27 06:32:00 -04:00
parent d6687d8fa4
commit 09a810495f
6 changed files with 25 additions and 11 deletions

View File

@ -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() { get_clean_path() {
sed 's/ *:\?$//g;s/`/``/g;s/:/`:`/g;s/\\`:`/\\:/g;' <<< $1 | \ sed 's/ *:\?$//g;s/`/``/g;s/:/`:`/g;s/\\`:`/\\:/g;' <<< $1 | \
awk -v RS='`:`' -v ORS='`:`' '!arr[$0]++' | \ awk -v RS='`:`' -v ORS='`:`' '!arr[$0]++' | \

View File

@ -1,7 +1,7 @@
if [[ -n "$(which-command chezmoi)" ]]; then if [[ -n "$(which-command chezmoi)" ]]; then
export CHEZMOIROOT="$(chezmoi source-path)" export CHEZMOIROOT="$(chezmoi source-path)"
export CZ="$CHEZMOIROOT/_home" export CZ="$CHEZMOIROOT"
export CZ_X="$CHEZMOIROOT/_externals" export CZ_X="$(readlink -f $CHEZMOIROOT/../_externals)"
alias czcd="cd $CZ" alias czcd="cd $CZ"
alias czxcd="cd $CZ_X" alias czxcd="cd $CZ_X"

View File

@ -1,6 +1,6 @@
if [[ -n "$(which-command oh-my-posh)" ]]; then if [[ -n "$(which-command oh-my-posh)" ]]; then
OHMYPOSH_CONFIG='' OHMYPOSH_CONFIG=''
[[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json" [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="--config ~/.poshtheme.omp.json"
eval "$(oh-my-posh init bash --config $OHMYPOSH_CONFIG)" eval "$(oh-my-posh init bash $OHMYPOSH_CONFIG)"
unset OHMYPOSH_CONFIG unset OHMYPOSH_CONFIG
fi fi

View File

@ -4,4 +4,5 @@ export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it shopt -s histappend # append to history, don't overwrite it
# Save and reload the history after each command finishes # 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"

View File

@ -1,4 +1,7 @@
alias which-command="type -fP " alias which-command="type -fP "
function which-command() {
type -fP "${@}"
}
function add-alias-to-bash-completion-code() { function add-alias-to-bash-completion-code() {
local CMD=$(printf "%s" "sed '" 's/\(complete\W.*-F\W.*' "$1" '.*$\)/\1 ' "$2/g'") local CMD=$(printf "%s" "sed '" 's/\(complete\W.*-F\W.*' "$1" '.*$\)/\1 ' "$2/g'")

View File

@ -81,9 +81,9 @@
"style": "powerline", "style": "powerline",
"properties": { "properties": {
"shell": "bash", "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", "type": "command",
@ -100,9 +100,9 @@
"trailing_diamond": "▓", "trailing_diamond": "▓",
"properties": { "properties": {
"shell": "bash", "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, "invert_powerline": true,
"powerline_symbol": "", "powerline_symbol": "",
"properties": { "properties": {
"always_enabled": true "always_enabled": false
}, },
"style": "powerline", "style": "powerline",
"template": "{{ if gt .Code 0 }}{{ .Meaning }}{{ else }}✔{{ end }} ", "template": "{{ if gt .Code 0 }}{{ .Meaning }}{{ else }}✔{{ end }} ",
@ -333,7 +333,7 @@
"invert_powerline": true, "invert_powerline": true,
"style": "powerline", "style": "powerline",
"powerline_symbol": "", "powerline_symbol": "",
"template": "sw{{ printf \"%.0f%%\" .SwapPercentUsed }}", "template": "   {{ printf \"%.0f%%\" .SwapPercentUsed }}",
"type": "sysinfo" "type": "sysinfo"
}, },
{ {