From 09fcaf22fc4593af1c3e048b39548aab4cd87f0d Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 18:23:05 +0200 Subject: [PATCH 1/4] Optimized theme reading to not use external commands, but only bash --- gitprompt.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 17568d6..2f1a90e 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -49,8 +49,9 @@ function get_theme() { local theme="" # use default theme, if theme was not found - for themefile in $(cd "$__GIT_PROMPT_DIR/themes" && echo *); do - if [[ "${themefile}" = "${GIT_PROMPT_THEME}.bgptheme" ]]; then + for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + local basename=${themefile##*/} + if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then theme=$GIT_PROMPT_THEME fi done @@ -78,9 +79,9 @@ function git_prompt_list_themes() { git_prompt_dir get_theme - for themefile in `ls "$__GIT_PROMPT_DIR/themes"`; do - local theme="$(basename $themefile .bgptheme)" - + for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + local basename=${themefile##*/} + local theme="${basename%.bgptheme}" if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then echoc ${Red} "*${theme}" else @@ -319,7 +320,7 @@ function update_old_git_prompt() { function setGitPrompt() { update_old_git_prompt - local repo=`git rev-parse --show-toplevel 2> /dev/null` + local repo=$(git rev-parse --show-toplevel 2> /dev/null) if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then # we do not permit bash-git-prompt outside git repos, so nothing to do PS1="$OLD_GITPROMPT" @@ -375,7 +376,7 @@ function olderThanMinutes() { fi if [[ "$_have_find_mmin" = 1 ]]; then - matches=`"$_find_command" "$1" -mmin +"$2" 2> /dev/null` + matches=$("$_find_command" "$1" -mmin +"$2" 2> /dev/null) find_exit_code="$?" if [[ -n "$matches" ]]; then return 0 From 2e0180f93a9ad3fc0444aae5c8de706c11c7ad3b Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 18:33:11 +0200 Subject: [PATCH 2/4] Removed backtick from comment --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 2f1a90e..99c2d21 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -206,7 +206,7 @@ function git_prompt_config() { # There are two files related to colors: # - # prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt + # prompt-colors.sh -- sets generic color names suitable for bash 'PS1' prompt # git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then From f319f3acc1d9d207f537e868fbad27f5652fcc25 Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 21:29:39 +0200 Subject: [PATCH 3/4] Added break in loop after we find the current theme --- gitprompt.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitprompt.sh b/gitprompt.sh index 99c2d21..b106db9 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -53,6 +53,7 @@ function get_theme() { local basename=${themefile##*/} if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then theme=$GIT_PROMPT_THEME + break fi done From f1940dfe8bf7afea862e7d69f082022a975b1dfa Mon Sep 17 00:00:00 2001 From: oGre Date: Mon, 28 Sep 2015 22:14:48 +0200 Subject: [PATCH 4/4] Quoted paths to handle spaces in them --- gitprompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index b106db9..00a79c2 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -49,7 +49,7 @@ function get_theme() { local theme="" # use default theme, if theme was not found - for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do local basename=${themefile##*/} if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then theme=$GIT_PROMPT_THEME @@ -80,7 +80,7 @@ function git_prompt_list_themes() { git_prompt_dir get_theme - for themefile in ${__GIT_PROMPT_DIR}/themes/*.bgptheme; do + for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do local basename=${themefile##*/} local theme="${basename%.bgptheme}" if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then