public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-staging/EdkRepo] [PATCH] EdkRepo: Update combo displayed in shell after checkout
@ 2020-04-12  0:26 Nate DeSimone
  2020-04-13 17:54 ` Ashley E Desimone
  0 siblings, 1 reply; 2+ messages in thread
From: Nate DeSimone @ 2020-04-12  0:26 UTC (permalink / raw)
  To: devel
  Cc: Ashley DeSimone, Puja Pandya, Erik Bjorge, Prince Agyeman,
	Bret Barkelew, Philippe Mathieu-Daude

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-13 17:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-12  0:26 [edk2-staging/EdkRepo] [PATCH] EdkRepo: Update combo displayed in shell after checkout Nate DeSimone
2020-04-13 17:54 ` Ashley E Desimone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox