lmorg / murex

A smarter shell and scripting environment with advanced features designed for usability, safety and productivity (eg smarter DevOps tooling)
https://murex.rocks
GNU General Public License v2.0
1.47k stars 27 forks source link

Default `fg` when only one job is backgrounded #889

Open atagen opened 5 days ago

atagen commented 5 days ago

Describe the problem: When only one job is in the background, it seems excessive to require the PID/FID to reactivate it - the user can only really mean one thing by typing fg.

Possible ways to implement: Automatically foreground process on fg when there is only a single job.

Documentation: Please rate your success with referring to the docs @ https://murex.rocks

lmorg commented 5 days ago

Coincidentally, I've been thinking about adding a few enhancements to fg too. Such as supporting % prefixes like Bash (et al) do.

So it wouldn't take any extra effort to make fg default to %1 if no parameters are supplied.

atagen commented 4 days ago

Nice! Perhaps a touch bikesheddy but IMO Bash-esque % prefixes can induce extra cognitive load when you're juggling more than 1-2 processes. If you're already going that route, would you consider perhaps %partialprocessname, ie. fg %py could foreground the process called by python my_web_server.py? (Of course, preferring errors to ambiguity, so if there are two bg python processes we don't act.)

lmorg commented 4 days ago

I could easily add support for partial process names without the % prefix. Basically the logic would go:

  1. is it an integer? If so, it's a FID
  2. is it a % prefixed integer? If so, follow Bash's format (for people with Bash muscle memory)
  3. otherwise, assume its a partial process name