loading...

Discussion on: My Personal Git Tricks Cheatsheet

antjanus profile image
Antonin Januska Author

it kind of tripped me up! I was expecting it to evaluate when invoked, just like a function.

Thread Thread
ivanalejandro0 profile image
Ivan Alejandro

Yeah, it may not be intuitive at first... but is really useful to be able to rely on both behaviors (evaluate on definition or when run).
If you wanted to use other aliases within an alias you have to start playing around with eval (which I don't really recommend). Like:

alias testingEval="eval 'git-branch'"

But things get messy pretty quickly... I pretty much use alias for super simple things or functions when I need something a bit longer that could use some extra variables, or to use parameters, or runtime expansion.

btw, I use zsh too :) ... I use prezto and got some configs online if you want to take a look
github.com/ivanalejandro0/prezto/b...

Thread Thread
antjanus profile image
Antonin Januska Author

I get why it works like that and I'm ok with it :) It really just surprised me but then again, I don't do a lot of bash scripting.

Thread Thread
darlanalves profile image
Darlan Alves

The key to it is just escape the $ char in an alias.

alias git-up="git push -u origin \$(git-branch)"

Thread Thread
ivanalejandro0 profile image
Ivan Alejandro

Oh, cool. I didn't know about that, thanks.
I've edited my comment escaping the $.