felixhageloh / uebersicht

ˈyːbɐˌzɪçt
GNU General Public License v3.0
4.56k stars 166 forks source link

Feature request: support running commands without a shell #527

Open 00dani opened 3 months ago

00dani commented 3 months ago

Currently Übersicht supports defining widget behaviour as either a shell command written out as a string, or a JavaScript function that takes a dispatch function and calls it. You can also invoke shell commands from the latter by importing and calling the run function exported by uebersicht. Both of these approaches to running commands are handled by command_server.coffee, which spawns a bash process and streams the requested command into it over standard input.

What you can't currently do is spawn your desired command directly, passing its arguments as an array. This approach is slightly more efficient since it doesn't need to spawn a shell first and, more importantly, means your command won't go through Bash argument parsing and expansion before being executed, which can be helpful if your command contains spaces or other special characters. It's also easy to do this in Node - the command server already works by calling child_process.spawn("bash", args, {cwd: workingDir}), which is exactly the form it would need to use to call a pre-split command with arguments as well.

Could this be made a possibility? It wouldn't introduce a backwards compatibility break to support export const command = ["ls", "-l"]; and run(["ls", "-l"]), since neither API currently permits an array to be passed, and it'd make calling commands with a variety of options a bit cleaner. To implement this, the command server could expose an additional endpoint (say, /run/argv), which expects the array of arguments as JSON or some other structured format rather than as a plain string.

felixhageloh commented 3 months ago

interesting! I will keep this one in mind for the next release