When I'm working with Kubernetes, I want to run commands that depend on my active branch. For that reason, having aliases would help me with other aliases that automatically run commands, given the current branch.
I'm trying to store the name of the current active local branch into a bash alias using a function, so that I can run other scripts without worrying about specifying the active branch, but I keep encountering an error on this.
function branch ()
{
local result='git branch | grep ^\* | cut -c 3-';
echo "$result"
}
alias get_branch=$(branch)
But when I try to run this, I get:
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>
.... (Same output as just entering 'git')
(cut -c 3-
removes the *
and space following it when active git branch gets listed)
e.g.
* feature/ch20372
ch20372
ch12345
The strange part is both of these work:
alias IMLAZY='git branch |grep \* | cut -d " " -f2'
alias TEST='git branch | grep ^\* | cut -c 3-'
Which makes me think
Could be syntax issues with my
~/.bash_aliases
elsewhere?Issue with ZSH somehow?
Syntax error somewhere in the function definition?