Drew
Drew

Reputation: 4691

Git config using shell command

I have a alias that does a short status, parses it with sed then adds the files to the 'assume-unchanged' index of git.

However, the issue seems to be a simple problem with my understanding of escaping single quotes in OS X bash.

irm = !sh -c 'git ignore $(git st --short -u | sed '\''/^ D/s/^ D//g'\'')'  

This is the full line in gitconfig. I can issue the command in the shell (with sh and the quote), but I get bad git config when I try to run it via git irm

based on advice below, I have configured this a little differently. However, it still doesn't work in gitconfig. So I added this to my ~/.profile

alias irm="git ignore $(git st --short | grep '^ D' | sed 's/^ D //')"

Upvotes: 1

Views: 1212

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 359855

You should be able to use double quotes, but you'll have to escape them:

irm = !sh -c 'git ignore $(git st --short -u | sed \"s/^ D//\")'

You don't need to select the line since the operation is the same as the selection. You may want to use -n and p with sed as Chris suggests in the comment if you only want to output the lines that match and exclude any others.

Also, since the pattern is anchored you don't need the global option.

Upvotes: 2

Related Questions