From ceb869671ed0d2f20abd327cd793c8d688acd01a Mon Sep 17 00:00:00 2001 From: "L. Yeung" Date: Tue, 31 Jan 2023 12:32:40 +0800 Subject: [PATCH] refactor(shell): use local variables in init scripts for Bash/Zsh --- src/shell/scripts/omp.bash | 1 + src/shell/scripts/omp.zsh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shell/scripts/omp.bash b/src/shell/scripts/omp.bash index 6bc4d335..8c5c5ba4 100644 --- a/src/shell/scripts/omp.bash +++ b/src/shell/scripts/omp.bash @@ -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' diff --git a/src/shell/scripts/omp.zsh b/src/shell/scripts/omp.zsh index 04004fb1..f961a9e2 100644 --- a/src/shell/scripts/omp.zsh +++ b/src/shell/scripts/omp.zsh @@ -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() {