sebazelonka
sebazelonka

Reputation: 1018

Adding ZSH alias

I'm a complete beginner with this. I'm trying to add this command as ZSH alias (I guess that is what I'm trying).

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

I've tried adding this line:

alias delete-local-branches="git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d"

After I source the updated file in iTerm, I get this:

~ source ~/.zshrc
-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..
1='cd -'
2='cd -2'
3='cd -3'
4='cd -4'
5='cd -5'
6='cd -6'
7='cd -7'
8='cd -8'
9='cd -9'
_='sudo '
afind='ack -il'
...

rd=rmdir
run-help=man
which-command=whence

Clearly, is not the expected result. Any help on how to add that to have the ability to autocomplete and use it as an alias?

Thanks.

Upvotes: 1

Views: 655

Answers (2)

chepner
chepner

Reputation: 531808

Just put a function definition in your .zshrc file instead.

delete-local-branches () {
  git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
}

Upvotes: 3

phd
phd

Reputation: 94696

I'm sure the problem is with quoting. You have this part quoted:

alias delete-local-branches="git branch --merged | egrep -v "

then unquoted (^\*|master|dev), and then quoted tail

" | xargs git branch -d"

My advice is to try to use different quotes:

alias delete-local-branches='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'

or escape internal quotes:

alias delete-local-branches="git branch --merged | egrep -v \"(^\*|master|dev)\" | xargs git branch -d"

Upvotes: 1

Related Questions