[edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Update combo displayed in shell after checkout

Nate DeSimone posted 1 patch 4 years ago
Failed in applying to current master (apply log)
.../Vendor/win_edkrepo_prompt.sh              | 17 ++++++++-
edkrepo_installer/linux-scripts/install.py    | 38 +++++++++++++++++--
2 files changed, 50 insertions(+), 5 deletions(-)
[edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Update combo displayed in shell after checkout
Posted by Nate DeSimone 4 years ago
With the current version of the command completion script,
after running "edkrepo checkout" the branch combination
listed in the shell prompt is not updated to reflect the
new branch combination. The reason for this is because
the branch combination isn't checked for changes unless
the present working directory was changed by the previous
command.

To fix this bug, the scripts have been updated to check
for changes to the branch combination when the last
command run by the user was "edkrepo" OR the present
working directory was changed by the previous command.

Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Ashley DeSimone <ashley.e.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Erik Bjorge <erik.c.bjorge@intel.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Philippe Mathieu-Daude <philmd@redhat.com>
---
 .../Vendor/win_edkrepo_prompt.sh              | 17 ++++++++-
 edkrepo_installer/linux-scripts/install.py    | 38 +++++++++++++++++--
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/edkrepo_installer/Vendor/win_edkrepo_prompt.sh b/edkrepo_installer/Vendor/win_edkrepo_prompt.sh
index 5404175..91496a7 100644
--- a/edkrepo_installer/Vendor/win_edkrepo_prompt.sh
+++ b/edkrepo_installer/Vendor/win_edkrepo_prompt.sh
@@ -39,7 +39,16 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v $command_completion_edkr
   # manifest XML, which is a relatively expensive operation to do every time
   # the user presses <Enter>.
   # As a performance optimization, only do this if the present working directory
-  # changed
+  # changed or if the last command executed was edkrepo
+  do_combo_check="0"
+  edkrepo_check_last_command() {
+    if [[ "$BASH_COMMAND" == *"edkrepo"* ]] && [[ "$BASH_COMMAND" != *"_edkrepo"* ]]; then
+      if [[ "$BASH_COMMAND" != *"edkrepo_"* ]]; then
+        do_combo_check="1"
+      fi
+    fi
+  }
+  trap 'edkrepo_check_last_command' DEBUG
   if [[ ! -z ${PROMPT_COMMAND+x} ]] && [[ "$PROMPT_COMMAND" != "edkrepo_combo_chpwd" ]]; then
     old_prompt_command=$PROMPT_COMMAND
   fi
@@ -48,6 +57,10 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v $command_completion_edkr
       if [[ "$(pwd)" != "$old_pwd" ]]; then
         old_pwd=$(pwd)
         current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
+      elif [ "$do_combo_check" == "1" ]; then
+        current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
       fi
       if [[ ! -z ${PROMPT_COMMAND+x} ]]; then
         eval $old_prompt_command
@@ -57,4 +70,4 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v $command_completion_edkr
 fi
 
 PS1="$newps1$prompt_suffix"
-MSYS2_PS1="$PS1"  # for detection by MSYS2 SDK's bash.basrc
+MSYS2_PS1="$PS1"  # for detection by MSYS2 SDK's bash.bashrc
diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer/linux-scripts/install.py
index 099954d..f9f324a 100755
--- a/edkrepo_installer/linux-scripts/install.py
+++ b/edkrepo_installer/linux-scripts/install.py
@@ -296,7 +296,16 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v command_completion_edkre
   # manifest XML, which is a relatively expensive operation to do every time
   # the user presses <Enter>.
   # As a performance optimization, only do this if the present working directory
-  # changed
+  # changed or if the last command executed was edkrepo
+  do_combo_check="0"
+  edkrepo_check_last_command() {
+    if [[ "$BASH_COMMAND" == *"edkrepo"* ]] && [[ "$BASH_COMMAND" != *"_edkrepo"* ]]; then
+      if [[ "$BASH_COMMAND" != *"edkrepo_"* ]]; then
+        do_combo_check="1"
+      fi
+    fi
+  }
+  trap 'edkrepo_check_last_command' DEBUG
   if [[ ! -z ${PROMPT_COMMAND+x} ]] && [[ "$PROMPT_COMMAND" != "edkrepo_combo_chpwd" ]]; then
     old_prompt_command=$PROMPT_COMMAND
   fi
@@ -305,6 +314,10 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v command_completion_edkre
       if [[ "$(pwd)" != "$old_pwd" ]]; then
         old_pwd=$(pwd)
         current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
+      elif [ "$do_combo_check" == "1" ]; then
+        current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
       fi
       if [[ ! -z ${PROMPT_COMMAND+x} ]]; then
         eval $old_prompt_command
@@ -346,16 +359,34 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v command_completion_edkre
   # manifest XML, which is a relatively expensive operation to do every time
   # the user presses <Enter>.
   # As a performance optimization, only do this if the present working directory
-  # changed
+  # changed or if the last command executed was edkrepo
+  do_combo_check="0"
   function edkrepo_combo_chpwd() {
     current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+    do_combo_check="0"
   }
   chpwd_functions=(${chpwd_functions[@]} "edkrepo_combo_chpwd")
+  function edkrepo_combo_preexec() {
+    if [[ "$1" = *"edkrepo"* ]] && [[ "$1" != *"_edkrepo"* ]]; then
+      if [[ "$1" != *"edkrepo_"* ]]; then
+        do_combo_check="1"
+      fi
+    fi
+  }
+  preexec_functions=(${preexec_functions[@]} "edkrepo_combo_preexec")
+  function edkrepo_combo_precmd() {
+    if [ "$do_combo_check" = "1" ]; then
+      current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+      do_combo_check="0"
+    fi
+  }
+  precmd_functions=(${precmd_functions[@]} "edkrepo_combo_precmd")
 fi
 
 # Load version control information
 autoload -Uz vcs_info
-precmd() { vcs_info }
+git_precmd() { vcs_info }
+precmd_functions=(${precmd_functions[@]} "git_precmd")
 
 # Format the vcs_info_msg_0_ variable
 zstyle ':vcs_info:git:*' formats " %{$fg[cyan]%}(%b)%{$reset_color%}"
@@ -363,6 +394,7 @@ zstyle ':vcs_info:git:*' formats " %{$fg[cyan]%}(%b)%{$reset_color%}"
 # Set up the prompt (with git branch name)
 setopt PROMPT_SUBST
 eval "PROMPT='$new_prompt\${vcs_info_msg_0_}\$prompt_suffix'"
+
 '''
 
 def add_command_to_startup_script(script_file, regex, command, username):
-- 
2.26.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57263): https://edk2.groups.io/g/devel/message/57263
Mute This Topic: https://groups.io/mt/72956799/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Update combo displayed in shell after checkout
Posted by Ashley E Desimone 4 years ago
Reviewed-by: Ashley DeSimone <ashley.e.desimone@intel.com>

-----Original Message-----
From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com> 
Sent: Saturday, April 11, 2020 5:27 PM
To: devel@edk2.groups.io
Cc: Desimone, Ashley E <ashley.e.desimone@intel.com>; Pandya, Puja <puja.pandya@intel.com>; Bjorge, Erik C <erik.c.bjorge@intel.com>; Agyeman, Prince <prince.agyeman@intel.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>; Philippe Mathieu-Daude <philmd@redhat.com>
Subject: [edk2-staging/EdkRepo] [PATCH] EdkRepo: Update combo displayed in shell after checkout

With the current version of the command completion script, after running "edkrepo checkout" the branch combination listed in the shell prompt is not updated to reflect the new branch combination. The reason for this is because the branch combination isn't checked for changes unless the present working directory was changed by the previous command.

To fix this bug, the scripts have been updated to check for changes to the branch combination when the last command run by the user was "edkrepo" OR the present working directory was changed by the previous command.

Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Ashley DeSimone <ashley.e.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Erik Bjorge <erik.c.bjorge@intel.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Philippe Mathieu-Daude <philmd@redhat.com>
---
 .../Vendor/win_edkrepo_prompt.sh              | 17 ++++++++-
 edkrepo_installer/linux-scripts/install.py    | 38 +++++++++++++++++--
 2 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/edkrepo_installer/Vendor/win_edkrepo_prompt.sh b/edkrepo_installer/Vendor/win_edkrepo_prompt.sh
index 5404175..91496a7 100644
--- a/edkrepo_installer/Vendor/win_edkrepo_prompt.sh
+++ b/edkrepo_installer/Vendor/win_edkrepo_prompt.sh
@@ -39,7 +39,16 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v $command_completion_edkr
   # manifest XML, which is a relatively expensive operation to do every time
   # the user presses <Enter>.
   # As a performance optimization, only do this if the present working directory
-  # changed
+  # changed or if the last command executed was edkrepo  
+ do_combo_check="0"
+  edkrepo_check_last_command() {
+    if [[ "$BASH_COMMAND" == *"edkrepo"* ]] && [[ "$BASH_COMMAND" != *"_edkrepo"* ]]; then
+      if [[ "$BASH_COMMAND" != *"edkrepo_"* ]]; then
+        do_combo_check="1"
+      fi
+    fi
+  }
+  trap 'edkrepo_check_last_command' DEBUG
   if [[ ! -z ${PROMPT_COMMAND+x} ]] && [[ "$PROMPT_COMMAND" != "edkrepo_combo_chpwd" ]]; then
     old_prompt_command=$PROMPT_COMMAND
   fi
@@ -48,6 +57,10 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v $command_completion_edkr
       if [[ "$(pwd)" != "$old_pwd" ]]; then
         old_pwd=$(pwd)
         current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
+      elif [ "$do_combo_check" == "1" ]; then
+        current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
       fi
       if [[ ! -z ${PROMPT_COMMAND+x} ]]; then
         eval $old_prompt_command
@@ -57,4 +70,4 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v $command_completion_edkr  fi
 
 PS1="$newps1$prompt_suffix"
-MSYS2_PS1="$PS1"  # for detection by MSYS2 SDK's bash.basrc
+MSYS2_PS1="$PS1"  # for detection by MSYS2 SDK's bash.bashrc
diff --git a/edkrepo_installer/linux-scripts/install.py b/edkrepo_installer/linux-scripts/install.py
index 099954d..f9f324a 100755
--- a/edkrepo_installer/linux-scripts/install.py
+++ b/edkrepo_installer/linux-scripts/install.py
@@ -296,7 +296,16 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v command_completion_edkre
   # manifest XML, which is a relatively expensive operation to do every time
   # the user presses <Enter>.
   # As a performance optimization, only do this if the present working directory
-  # changed
+  # changed or if the last command executed was edkrepo  
+ do_combo_check="0"
+  edkrepo_check_last_command() {
+    if [[ "$BASH_COMMAND" == *"edkrepo"* ]] && [[ "$BASH_COMMAND" != *"_edkrepo"* ]]; then
+      if [[ "$BASH_COMMAND" != *"edkrepo_"* ]]; then
+        do_combo_check="1"
+      fi
+    fi
+  }
+  trap 'edkrepo_check_last_command' DEBUG
   if [[ ! -z ${PROMPT_COMMAND+x} ]] && [[ "$PROMPT_COMMAND" != "edkrepo_combo_chpwd" ]]; then
     old_prompt_command=$PROMPT_COMMAND
   fi
@@ -305,6 +314,10 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v command_completion_edkre
       if [[ "$(pwd)" != "$old_pwd" ]]; then
         old_pwd=$(pwd)
         current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
+      elif [ "$do_combo_check" == "1" ]; then
+        current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+        do_combo_check="0"
       fi
       if [[ ! -z ${PROMPT_COMMAND+x} ]]; then
         eval $old_prompt_command
@@ -346,16 +359,34 @@ if [ -x "$(command -v edkrepo)" ] && [ -x "$(command -v command_completion_edkre
   # manifest XML, which is a relatively expensive operation to do every time
   # the user presses <Enter>.
   # As a performance optimization, only do this if the present working directory
-  # changed
+  # changed or if the last command executed was edkrepo  
+ do_combo_check="0"
   function edkrepo_combo_chpwd() {
     current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+    do_combo_check="0"
   }
   chpwd_functions=(${chpwd_functions[@]} "edkrepo_combo_chpwd")
+  function edkrepo_combo_preexec() {
+    if [[ "$1" = *"edkrepo"* ]] && [[ "$1" != *"_edkrepo"* ]]; then
+      if [[ "$1" != *"edkrepo_"* ]]; then
+        do_combo_check="1"
+      fi
+    fi
+  }
+  preexec_functions=(${preexec_functions[@]} "edkrepo_combo_preexec")  
+ function edkrepo_combo_precmd() {
+    if [ "$do_combo_check" = "1" ]; then
+      current_edkrepo_combo=$(command_completion_edkrepo current-combo)
+      do_combo_check="0"
+    fi
+  }
+  precmd_functions=(${precmd_functions[@]} "edkrepo_combo_precmd")
 fi
 
 # Load version control information
 autoload -Uz vcs_info
-precmd() { vcs_info }
+git_precmd() { vcs_info }
+precmd_functions=(${precmd_functions[@]} "git_precmd")
 
 # Format the vcs_info_msg_0_ variable
 zstyle ':vcs_info:git:*' formats " %{$fg[cyan]%}(%b)%{$reset_color%}"
@@ -363,6 +394,7 @@ zstyle ':vcs_info:git:*' formats " %{$fg[cyan]%}(%b)%{$reset_color%}"
 # Set up the prompt (with git branch name)  setopt PROMPT_SUBST  eval "PROMPT='$new_prompt\${vcs_info_msg_0_}\$prompt_suffix'"
+
 '''
 
 def add_command_to_startup_script(script_file, regex, command, username):
--
2.26.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57285): https://edk2.groups.io/g/devel/message/57285
Mute This Topic: https://groups.io/mt/72956799/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-