Skip to content

Calling a fish function from a git alias fails #1258

Closed

Description

@dideler

I have a fish function (~/.config/fish/functions/git-clean.fish) that I'm trying to call from a git alias set in my ~/.gitconfig.

The git alias is rm-untracked = !fish -c 'git-clean'.

The function works fine when called directly, calling it through the alias fails:

$ git rm-untracked  # Calling function through Git alias fails
fish: Couldn't grab control of terminal
tcsetpgrp: Interrupted system call

$ git-clean  # Calling function directly works
Would remove app/models/order.rb
Would remove db/migrate/20140121194853_create_orders.rb
Would remove test/factories/orders.rb
Would remove test/models/order_test.rb
Continue? [Yn]
> y
Removing app/models/order.rb
Removing db/migrate/20140121194853_create_orders.rb
Removing test/factories/orders.rb
Removing test/models/order_test.rb

Activity

  1. xiaogwu commented on Apr 25, 2014

    @xiaogwu

    I would like to see this supported too.

  2. added this to the fish-future milestone on Oct 6, 2014
  3. faho commented on Jul 17, 2015

    @faho
    Member

    I am guessing here you're trying to read user input in that function.

    Executing fish functions via git aliases works:

    In ~/.config/fish/functions/ni.fish

    function ni
        echo "NI"
    end
    

    alias is ni = !fish -c 'ni'.

    $ git ni
    NI
    

    Change ni to

    function ni
        echo "NI"
        read ni
        echo $ni
    end
    

    and suddenly git ni yields:

    NI
    fish: Couldn't grab control of terminal
    tcsetpgrp: Interrupted system call

    I'm not sure if this is a fish issue - seems like git doesn't connect stdin (or something).

  4. pickfire commented on Jul 19, 2015

    @pickfire
    Contributor

    And I hope alias in alias works too.

  5. faho commented on Jul 19, 2015

    @faho
    Member

    What do you mean? Using a fish-alias in a git-alias? That works too, since aliases are just functions.

  6. pickfire commented on Jul 21, 2015

    @pickfire
    Contributor
    alias a='asdf'
    alias q='qwerty'

    a q -> asdf qwerty

  7. faho commented on Jul 21, 2015

    @faho
    Member

    That's basically what zsh calls "global aliases", and it won't work with fish's current approach, which is to have alias as a shortcut to defining functions.

    I.e. that'd be a feature request, and not one that would be accepted, I think. Extending abbr might work, but that would then need a way to not expand.

  8. zanchey commented on Jul 24, 2015

    @zanchey
    Member

    Shortly after fish sets itself into its own process group, tcsetpgrp gets SIGTTOU, which causes a return with EINTR.

    The POSIX documentation says:

    Attempts to use tcsetpgrp() from a process which is a member of a background process group on a fildes associated with its controlling terminal shall cause the process group to be sent a SIGTTOU signal. If the calling thread is blocking SIGTTOU signals or the process is ignoring SIGTTOU signals, the process shall be allowed to perform the operation, and no signal is sent.

    That sounds bananas to me, but it might be worth a go.

    I can't really understand why fish is so insistent on being in its own process group; bash and zsh don't seem to bother in this situation.

  9. krader1961 commented on Mar 23, 2017

    @krader1961
    Contributor

    This still doesn't work but the symptoms are now different. Probably due to the reworking of signal management I did recently. The fish process now blocks in the ioctl done by the tcsetpgrp() call done from reader_push() from builtin_read(). The act of dumping the call stack using a process debugger results in the shell exiting with the following output when the debugger detaches from the process:

    <E> fish: Couldn't grab control of terminal
    tcsetpgrp: Interrupted system call
    
  10. faho commented on Jul 24, 2017

    @faho
    Member

    I'm gonna declare this a duplicate of #3805. Both feature fish being unable to read as a result of being started from something else. I find 3805 has a nicer test case.

  11. added and removed
    bug
    on Jul 24, 2017
  12. removed this from the fish-future milestone on Jul 24, 2017
  13. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions