Search code examples
gitfish

Fish function creates random file


I created a fish shell function to shorten the "git add" process for me (cause it's so long):

function ga
    if count $argv > 0
        git add $argv
    else
        git add .
    end
end

It works just fine, adding the whole directory if I call it without arguments, and adding only specific files if I name those, with one very weird exception:

Using "ga" instead of "git add", with or without arguments, creates a file name "0" in the directory. Its contents are generally a single number (0 or 2).

Any idea what's going on here? It's totally bizarre, and a real pain, because I like the function, but don't want to keep pushing up empty "0" files to repos to which I contribute.


Solution

  • That > isn't doing a comparison, it's output redirection. That is, it's taking the output of

    count $argv
    

    and writing it into a file called 0. You probably want something like:

    function ga
        if [ (count $argv) -gt 0 ]
            git add $argv
        else
            git add .
        end
    end