You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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.
Activity
krader1961 commentedon Dec 31, 2015
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?
krader1961 commentedon Dec 17, 2016
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
bgcommand (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.krader1961 commentedon Mar 4, 2017
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 augmentbgto accept an arbitrary command (much likecommandorbuiltin) 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.jorgebucaran commentedon Sep 12, 2018
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.faho commentedon Jul 30, 2021
Sorry, this isn't happening.