0

I'm trying to make an alias for adding my changes, and committing them after. The commit message must be prefixed with the branch name. The message should look something like:

"[BRANCH-123] Message here"

My branches are prefixed with a subtree like 'bugfix/' or 'feature/', and I want those to be removed from the message. So far I have:

branch-name = "!git rev-parse --abbrev-ref HEAD"

something = "!f() { git add -A && git commit -m \"[${$(git branch-name)#*/}] $1\"; }; f"

However, the 'something' command says 'Bad substitution'.

Cake
  • 318
  • 6
  • 20

1 Answers1

1

A parameter substitution takes a variable name to operate on, not a value.

Thus, you cannot run:

echo "${$(somecommand)##*/}"

instead, you need to run:

var=$(somecommand)
echo "${var##*/}"

Thus:

something = "!f() { local branch; branch=$(git branch-name); git add -A && git commit -m \"[${branch#*/}] $1\"; }; f"
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441