1

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 //')"
2
  • That sed line is causing me a bit of trouble. I think you are looking for this : sed -n -e "s/^D//gp" Commented Jan 27, 2012 at 22:08
  • I want to make sure it only hits deleted files though. M A should be excluded. Commented Jan 27, 2012 at 23:10

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

are you on gnu? I'm getting this error on os x bash: sh -c 'git st --short -u | sed \"s/^ D//\"' sed: 1: ""s/^": invalid command code "
@Drew: Yes, I'm on GNU. Try it without escaping the double quotes. Another thing to try is wrapping the whole alias in double quotes: irm = "!sh -c 'git ignore $(git st --short -u | sed \"s/^ D//\")'". You can also try omitting the sh -c: git ignore $(git st --short -u | sed \"s/^ D//\"). Each of these works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.