Skip to content

Commit e8c677e

Browse files
committed
fix: when grep is alias (like alias grep='grep --color -Hn'), completions fails;
also, don't invoke sed twice, when one time can be done (sed -e .. -e .. ...)
1 parent 42e754f commit e8c677e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

bash_completion.bash

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ __pom_hierarchy()
9292
{
9393
local pom=`_realpath "pom.xml"`
9494
POM_HIERARCHY+=("$pom")
95-
while [ -n "$pom" ] && grep -q "<parent>" "$pom"; do
95+
while [ -n "$pom" ] && \grep -q "<parent>" "$pom"; do
9696
## look for a new relativePath for parent pom.xml
97-
local parent_pom_relative=`grep -e "<relativePath>.*</relativePath>" "$pom" | sed 's/.*<relativePath>//' | sed 's/<\/relativePath>.*//g'`
97+
local parent_pom_relative=`\grep -e "<relativePath>.*</relativePath>" "$pom" | sed -e 's/.*<relativePath>//' -e 's/<\/relativePath>.*//g'`
9898

9999
## <parent> is present but not defined, assume ../pom.xml
100100
if [ -z "$parent_pom_relative" ]; then
@@ -103,7 +103,7 @@ __pom_hierarchy()
103103

104104
## if pom exists continue else break
105105
parent_pom=`_realpath "${pom%/*}/$parent_pom_relative"`
106-
if [ -n "$parent_pom" ]; then
106+
if [ -n "$parent_pom" ]; then
107107
pom=$parent_pom
108108
else
109109
break
@@ -185,16 +185,16 @@ _mvn()
185185
local plugin_goals_wildfly="wildfly:add-resource|wildfly:deploy|wildfly:deploy-only|wildfly:deploy-artifact|wildfly:redeploy|wildfly:redeploy-only|wildfly:undeploy|wildfly:undeploy-artifact|wildfly:run|wildfly:start|wildfly:shutdown|wildfly:execute-commands"
186186

187187
## some plugin (like jboss-as) has '-' which is not allowed in shell var name, to use '_' then replace
188-
local common_plugins=`compgen -v | grep "^plugin_goals_.*" | sed 's/plugin_goals_//g' | tr '_' '-' | tr '\n' '|'`
188+
local common_plugins=`compgen -v | \grep "^plugin_goals_.*" | sed -e 's/plugin_goals_//g' -e 's/_/-/g' | tr '\n' '|'`
189189

190190
local options="-Dmaven.test.skip=true|-DskipTests|-DskipITs|-Dtest|-Dit.test|-DfailIfNoTests|-Dmaven.surefire.debug|-DenableCiProfile|-Dpmd.skip=true|-Dcheckstyle.skip=true|-Dtycho.mode=maven|-Dmaven.javadoc.skip=true|-Dgwt.compiler.skip|-Dcobertura.skip=true|-Dfindbugs.skip=true||-DperformRelease=true|-Dgpg.skip=true|-DforkCount"
191191

192-
local profile_settings=`[ -e ~/.m2/settings.xml ] && grep -e "<profile>" -A 1 ~/.m2/settings.xml | grep -e "<id>.*</id>" | sed 's/.*<id>//' | sed 's/<\/id>.*//g' | tr '\n' '|' `
192+
local profile_settings=`[ -e ~/.m2/settings.xml ] && \grep -e "<profile>" -A 1 ~/.m2/settings.xml | \grep -e "<id>.*</id>" | sed -e 's/.*<id>//' -e 's/<\/id>.*//g' | tr '\n' '|' `
193193

194194
local profiles="${profile_settings}|"
195195
for item in ${POM_HIERARCHY[*]}
196196
do
197-
local profile_pom=`[ -e $item ] && grep -e "<profile>" -A 1 $item | grep -e "<id>.*</id>" | sed 's/.*<id>//' | sed 's/<\/id>.*//g' | tr '\n' '|' `
197+
local profile_pom=`[ -e $item ] && \grep -e "<profile>" -A 1 $item | \grep -e "<id>.*</id>" | sed -e 's/.*<id>//' -e 's/<\/id>.*//g' | tr '\n' '|' `
198198
local profiles="${profiles}|${profile_pom}"
199199
done
200200

@@ -237,9 +237,9 @@ _mvn()
237237
done
238238

239239
else
240-
if echo "${common_lifecycle_phases}" | tr '|' '\n' | grep -q -e "^${cur}" ; then
240+
if echo "${common_lifecycle_phases}" | tr '|' '\n' | \grep -q -e "^${cur}" ; then
241241
COMPREPLY=( $(compgen -S ' ' -W "${common_lifecycle_phases}" -- ${cur}) )
242-
elif echo "${common_plugins}" | tr '|' '\n' | grep -q -e "^${cur}"; then
242+
elif echo "${common_plugins}" | tr '|' '\n' | \grep -q -e "^${cur}"; then
243243
COMPREPLY=( $(compgen -S ':' -W "${common_plugins}" -- ${cur}) )
244244
fi
245245
fi

0 commit comments

Comments
 (0)