[systemd-devel] [PATCH] add bash completion for systemctl --system
Lennart Poettering
lennart at poettering.net
Wed Nov 10 14:31:29 PST 2010
On Tue, 09.11.10 01:03, Ran Benita (ran234 at gmail.com) wrote:
> I've been playing recently with systemd on Arch, and had much fun. But
> soon, alas, my fingers started to ache from repeatedly writing
> systemctl restart some-long-service.service. So, I wrote a completion
> script. I figured other people may want to use it, so I prepared a
> patch against systemd-git (attached).
Awesome stuff! Commited!
> There are some notes/disclaimers, however:
>
> - It requires bash>=4.0, sed, grep and awk. A bash-completion package
> is not strictly needed; sourcing the file is enough.
> - It wouldn't work properly with --session, as I had no way to test
> it.
You should be able to simply run it by typing "systemd" in a normal shell.
> - It uses the output of systemctl list-units directly when that's
> enough, but also runs systemctl show when completing on some verbs
> (for example, to check for AllowIsolate=yes). This /may/ be somewhat
> slow once there are many units, since it calls a dbus method on each
> one. Is there a faster way to have that information?
Hmm, not really.
Note however, that to do everything 100% correctly you actually have to
manually iterate through /lib/systemd/system and /etc/systemd/system to
get the complete list of services since systemctl list-units will only
tell you about units it currently has loaded data about, i.e. because
they are running, or because they are referenced by one that is
running. (Oh, and to make it 101% correct you actually should enumerate
the dirs in the UnitPath property of the manager object as printed by
"systemctl show".
> - The code is perhaps a bit long and messy; honestly, I blame the tool
> - ;)
I actually find it quite readable for the fact that it is bash...
> One way to improve on the situation is to integrate some completion
> code in systemctl itself, the way e.g. gdbus, gsettings and django do
> it. This will allow for finer grained and faster completions, and it
> won't be necessary to keep the verb/option tables in sync with some
> other file. But it does mean adding all of this code in C. If this is
> acceptable, I'll try to have a go at it.
Yes, this sounds like a good idea to me.
Thanks a lot for your work.
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list