Echoing from a variable in a specific part of a string
2
votes
3
answers
598
views
I am trying to make a command for having a nice-looking
git log
. Say I have the following:
git log --color --pretty=format:"%C(cyan)" --abbrev-commit
What I would like to do is to make a variable that takes %an
and decides what colour it will be based on the output string.
So far, I have
USER=$(if [ ! %an = "my own user name" ]
then
echo "%C(cyan)"
else
echo %C(bold blue)
fi)
So then I put the variable into the git log such that I have
git log --color --pretty=format:"$USER" --abbrev-commit
Which should make is so that if a commit has been done by *me*, it will print my username in cyan; else, it will print the collaborator's username in bold blue. However, it doesn't.
I'm just wondering if someone knows what I'm doing wrong here? I suspect it is something to do with printing the variable into an environment that is already a string, but I don't know how to fix it. Any help is appreciated!
Asked by Jake Ireland
(225 rep)
Sep 22, 2019, 01:45 AM
Last activity: Sep 22, 2019, 01:32 PM
Last activity: Sep 22, 2019, 01:32 PM