0
votes

I'm using git-ftp and I'm trying to execute awk to only include the first lines:

git ftp show | awk 'NR<7'

It works perfect in terminal. However executing it as an alias returns an error.

This is how my git config file looks like:

[alias]
sh = ftp show | awk 'NR<7'

If I run git sh it returns: fatal: Unrecognised option: awk

I also tried just using show, but it also returns an error:

[alias]
sh = show | awk 'NR<7'

fatal: ambiguous argument '|': unknown revision or path not in the working tree.

Can this command be formated in some way to make it work as a git alias?

1
Try sh = "! git ftp show | awk 'NR<7' ".ElpieKay
removed the awk tag as this has nothing to do with awk, you could have any command on the right side of the pipe and have the same problem.Ed Morton

1 Answers

0
votes

The first thing to note is that git aliases only work with shell commands when prefixed with a bang (exclamation mark). I'm not using git-ftp so I can't test your precise command, but I used git remote show origin instead because it's very verbose on one of my repos. I found the following git alias worked fine: sh = "!git remote show origin | awk 'NR<7'" I therefore expect this git alias to be a solution for you:

sh = "!git ftp show | awk 'NR<7'"

Realise that some bang/pipe/quote combinations work as git aliases, while others will fail, possibly with "fatal bad config line". Most often the real problem is how quotes are used. The trick can be to just change your particular git alias shell command line to eliminate or change quote usage. For instance one requirement for a git alias that I had, I worked around the quote problem by changing a sed command to tr. I then had to double escape a backslash using: ...| tr \\\\n.

For this particular question, although I don't think git-alias has a problem with the quotes, a more quote-safe solution would be:

sh = ! git ftp show | head -6

While most readers may already know about the requirement to shell out with a bang, they may not realise that quoting is a more difficult issue. Although not entirely correct, I found this article was useful for ideas: https://www.atlassian.com/blog/git/advanced-git-aliases