refactor(shell): use local variables in init scripts for Bash/Zsh

This commit is contained in:
L. Yeung 2023-01-31 12:32:40 +08:00 committed by Jan De Dobbeleer
parent 49330fa26d
commit ceb869671e
2 changed files with 3 additions and 2 deletions

View file

@ -15,6 +15,7 @@ function _set_posh_cursor_position() {
if [[ -v MC_SID ]];then
return
fi
local pos
echo -ne "\033[6n" # ask the terminal for the position
read -s -d\[ garbage # discard the first part of the response
read -s -d R pos # store the position in bash variable 'pos'

View file

@ -13,6 +13,7 @@ function _set_posh_cursor_position() {
if [[ -v MC_SID ]];then
return
fi
local pos
echo -ne "\033[6n" # ask the terminal for the position
read -s -d\[ garbage # discard the first part of the response
read -s -d R pos # store the position in bash variable 'pos'
@ -34,7 +35,7 @@ function prompt_ohmyposh_precmd() {
omp_stack_count=${#dirstack[@]}
omp_elapsed=-1
if [ $omp_start_time ]; then
omp_now=$(::OMP:: get millis --shell=zsh)
local omp_now=$(::OMP:: get millis --shell=zsh)
omp_elapsed=$(($omp_now-$omp_start_time))
fi
count=$((POSH_PROMPT_COUNT+1))
@ -43,7 +44,6 @@ function prompt_ohmyposh_precmd() {
_set_posh_cursor_position
eval "$(::OMP:: print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION")"
unset omp_start_time
unset omp_now
}
function _install-omp-hooks() {