0

I am trying to make this alias working:

alias ciao="vim -p `git status --short | awk '{print $2}'; git show --pretty="format:" --name-only`

Basically I would like to open every files, printed by git status, as vim tab. The command works properly when I run it in the prompt directly but I cannot make an alias of it.

Looks like vim -p is applied to the first file printed but not to the others (when the files from git status are more than one).

I would love if somebody can tell me what I am doing wrong: in the alias I pasted there are obvious problems (like escaping), sorry about that.

lzzluca
  • 706
  • 5
  • 14
  • As demonstrated in the accepted answer, you should always prefer `$(...)` rather than backticks for command substitutions. – dimo414 Nov 02 '16 at 17:31
  • the consequent question for me was "why", so here the answer I found, in case can be of interest for somebody else too: http://stackoverflow.com/questions/4708549/whats-the-difference-between-command-and-command-in-shell-programming – lzzluca Nov 04 '16 at 16:22

2 Answers2

1
alias ciao='vim -p $(
    git status --short | awk "{print $2}";
    git show --pretty="format:" --name-only
)'
Kamil Slowikowski
  • 4,184
  • 3
  • 31
  • 39
1

Anything more complicated than ls -l should be a function, not an alias.

ciao () {
  vim -p $(git status --short | awk '{print $2}'
            git show --pretty="format:" --name-only)
}
chepner
  • 497,756
  • 71
  • 530
  • 681
  • Doesn't work for me. Vim opens up but no files are loaded – lzzluca Nov 02 '16 at 15:38
  • 1
    @lzzluca, Comments can be edited for 5 minutes. Another option to multiple comments when they haven't been addressed yet is to just delete them and put all info into one comment. – user3439894 Nov 02 '16 at 15:41
  • One problem is that I quoted the command substitution, which passes a single argument to `vim`. That won't work here, since the output of the two `git` commands is clearly supposed to be multiple file names. You can unquote the command substitution, but be aware that this subjects the result to word-splitting and globbing, which means it may not work for all legal file names. – chepner Nov 02 '16 at 15:54