Skip to content

Remove & background syntax #1381

Closed
Closed

Description

@sugar700

I'm probably going to propose one of biggest changes of fish grammar yet, but I believe it should be done sooner or later. The & allows you to run programs in background.

xfix@pear ~> process stuff &
Job 1, “process stuff &” has ended
xfix@pear ~>

Now, what are issues of this syntax? Well... it's not discoverable. There is a reason why fish syntax doesn't have && and ||. It has a strange syntax with many quirks, and there is no reason to implement it. The following fish shell function does everything that & syntax could do (aside of running blocks, but current fish doesn't support this anyway). Of course, the actual implementation would have to be a builtin, as & syntax would be removed.

function runbg
    # Extract the first command.
    set -l command $argv[1]
    # Remove first argument from argv.
    set -e argv[1]
    # Run the command in background.
    eval $command \$argv \&
end

The & syntax after removing background syntax could be used for other purposes.

Activity

  1. added this to the milestone on Jul 11, 2014
  2. krader1961 commented on Dec 31, 2015

    @krader1961
    Contributor

    I like this idea. My question is: Do we need a new builtin? Why not enhance the existing bg command to accept a PID (or job identifier) or a command?

  3. krader1961 commented on Dec 17, 2016

    @krader1961
    Contributor

    While reviewing issues labeled "RFC" I noticed this issue. I am still inclined to recommend we do this for a future major release where we can begin to break backward compatibility. In other words, the next major release would allow someone to use the bg command (or perhaps a new command) to launch a command in the background instead of using the traditional & modifier. A subsequent release would then remove support for the & modifier. This change would be much more consistent with other aspects of fish behavior.

  4. krader1961 commented on Mar 4, 2017

    @krader1961
    Contributor

    Below is the comment I added to issue #3878 regarding this proposal. Frankly, I don't see us ever removing & as syntactical sugar to put a job in the background. We could augment bg to accept an arbitrary command (much like command or builtin) at the small risk that an external command happens to look like a PID. Simply checking whether the token refers to a known job to disambiguate the two cases is probably sufficient.

    While I would welcome enhancing bg so it can be used to directly launch an external command in the background (issue #1381) I doubt we'll ever get rid of & as syntax for doing so. At least not in the next few years. That is the sort of change that requires at least one, possibly two, major releases to remove.

  5. jorgebucaran commented on Sep 12, 2018

    @jorgebucaran

    Please don't remove syntax. Add new syntax if you really feel & is too obscure (I don't feel that way about & though). Why? It makes it impossible to write scripts compatible across 2.x, 3.x and future 4.x versions.

  6. faho commented on Jul 30, 2021

    @faho
    Member

    Sorry, this isn't happening.

  7. locked as resolved and limited conversation to collaborators on Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions