From 843a66214975e8fe2103634842e71f8e02a60f7c Mon Sep 17 00:00:00 2001 From: Giuseppe Rota Date: Thu, 26 Apr 2012 00:11:42 +0300 Subject: [PATCH 1/4] avoid possible aliasing of grep --- lib/git/status_shortcuts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index 5d4bbe3..6a9c91d 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -30,7 +30,7 @@ git_status_shortcuts() { git status; return 1 fi # Fetch list of files from last line of script output - files="$(echo "$cmd_output" | grep '@@filelist@@::' | sed 's%@@filelist@@::%%g')" + files="$(echo "$cmd_output" | command grep '@@filelist@@::' | sed 's%@@filelist@@::%%g')" if [ "$scmbDebug" = "true" ]; then echo "filelist => $files"; fi # Export numbered env variables for each file IFS="|" From cc48bcb82f9b7a1ae5af57695188aa5b2d4f7046 Mon Sep 17 00:00:00 2001 From: Giuseppe Rota Date: Thu, 26 Apr 2012 17:27:50 +0200 Subject: [PATCH 2/4] Substitute all `grep` instances with `command grep` --- lib/git/repo_index.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/git/repo_index.sh b/lib/git/repo_index.sh index 8cf744b..50e789b 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -69,7 +69,7 @@ function git_index() { done | sort | column -t -s ':' elif [ "$1" = "--count-by-host" ]; then echo -e "=== Producing a report of the number of repos per host...\n" - _git_index_batch_cmd git remote -v | grep "origin.*(fetch)" | + _git_index_batch_cmd git remote -v | command grep "origin.*(fetch)" | sed -e "s/origin\s*//" -e "s/(fetch)//" | sed -e "s/\(\([^/]*\/\/\)\?\([^@]*@\)\?\([^:/]*\)\).*/\1/" | sort | uniq -c @@ -85,7 +85,7 @@ function git_index() { # Figure out which directory we need to change to. local project=$(echo $1 | cut -d "/" -f1) # Find base path of project - local base_path="$(grep -m1 "/$project$" "$GIT_REPO_DIR/.git_index")" + local base_path="$(command grep -m1 "/$project$" "$GIT_REPO_DIR/.git_index")" if [ -n "$base_path" ]; then sub_path=$(echo $1 | sed "s:^$project::") # Append subdirectories to base path @@ -93,9 +93,9 @@ function git_index() { fi # Try partial matches # - string at beginning of project - if [ -z "$base_path" ]; then base_path=$(_git_index_dirs_without_home | grep -m1 "/$project"); fi + if [ -z "$base_path" ]; then base_path=$(_git_index_dirs_without_home | command grep -m1 "/$project"); fi # - string anywhere in project - if [ -z "$base_path" ]; then base_path=$(_git_index_dirs_without_home | grep -m1 "$project"); fi + if [ -z "$base_path" ]; then base_path=$(_git_index_dirs_without_home | command grep -m1 "$project"); fi # -------------------- # Go to our base path if [ -n "$base_path" ]; then @@ -133,7 +133,7 @@ function _find_git_repos() { # List all submodules for a git repo, if any. function _find_git_submodules() { if [ -e "$1/../.gitmodules" ]; then - grep "\[submodule" "$1/../.gitmodules" | sed "s%\[submodule \"%${1%/.git}/%g" | sed "s/\"]//g" + command grep "\[submodule" "$1/../.gitmodules" | sed "s%\[submodule \"%${1%/.git}/%g" | sed "s/\"]//g" fi } @@ -162,7 +162,7 @@ function _check_git_index() { # Produces a count of repos in the tab completion index (excluding commands) function _git_index_count() { - echo $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | grep . | wc -l) + echo $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | command grep . | wc -l) } # Returns the current git branch (returns nothing if not a git repository) @@ -174,7 +174,7 @@ parse_git_branch() { function _git_index_status_if_dirty() { if ! [ `git status --porcelain | wc -l` -eq 0 ]; then # Fall back to 'git status' if git status alias isn't configured - if type $git_status_command 2>&1 | grep -qv "not found"; then + if type $git_status_command 2>&1 | command grep -qv "not found"; then eval $git_status_command else git status @@ -263,7 +263,7 @@ function _git_index_batch_cmd() { echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n" IFS=$' \t\n' local base_path - for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | grep . | sort); do + for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | command grep . | sort); do builtin cd "$base_path" $@ done @@ -285,7 +285,7 @@ function _git_index_tab_completion() { # If the first part of $curw matches a high-level directory, # then match on sub-directories for that project local project=$(echo "$curw" | cut -d "/" -f1) - local base_path=$(grep "/$project$" "$GIT_REPO_DIR/.git_index" | sed 's/ /\\ /g') + local base_path=$(command grep "/$project$" "$GIT_REPO_DIR/.git_index" | sed 's/ /\\ /g') # If matching project path was found and curr string contains a /, then complete project sub-directories if [[ -n "$base_path" && $curw == */* ]]; then From ff1a59ddb7d14bb70fa0cde0003f745a21a90ad7 Mon Sep 17 00:00:00 2001 From: Giuseppe Rota Date: Wed, 2 May 2012 21:45:03 +0200 Subject: [PATCH 3/4] forgot another one `command grep` --- lib/git/repo_index.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/repo_index.sh b/lib/git/repo_index.sh index 50e789b..d817fde 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -290,7 +290,7 @@ function _git_index_tab_completion() { # If matching project path was found and curr string contains a /, then complete project sub-directories if [[ -n "$base_path" && $curw == */* ]]; then local search_path=$(echo "$curw" | sed "s:^${project/\\/\\\\\\}::") - COMPREPLY=($(compgen -d "$base_path$search_path" | grep -v "/.git" | sed -e "s:$base_path:$project:" -e "s:$:/:" )) + COMPREPLY=($(compgen -d "$base_path$search_path" | command grep -v "/.git" | sed -e "s:$base_path:$project:" -e "s:$:/:" )) # If curr string starts with /, tab complete top-level directories in root project dir elif ([ $shell = "bash" ] && [ "${curw:0:1}" = "/" ]) || \ From f9f6da479eb57c9813b3e2ea730853f1e96cd9e2 Mon Sep 17 00:00:00 2001 From: Giuseppe Date: Wed, 2 May 2012 23:03:26 +0200 Subject: [PATCH 4/4] Forgot other `command grep` --- lib/git/status_shortcuts.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index 6a9c91d..ede84a6 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -44,7 +44,7 @@ git_status_shortcuts() { if [ "$scmbDebug" = "true" ]; then echo "------------------------"; fi # Print status - echo "$cmd_output" | grep -v '@@filelist@@::' + echo "$cmd_output" | command grep -v '@@filelist@@::' zsh_reset # Reset zsh environment to default } @@ -126,7 +126,7 @@ git_show_affected_files(){ f=0 # File count # Show colored revision and commit message echo -n "# "; git show --oneline --name-only $@ | head -n1; echo "# " - for file in $(git show --pretty="format:" --name-only $@ | grep -v '^$'); do + for file in $(git show --pretty="format:" --name-only $@ | command grep -v '^$'); do let f++ export $git_env_char$f=$file # Export numbered variable. echo -e "# \e[2;37m[\e[0m$f\e[2;37m]\e[0m $file"