-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add passwd completions #4209
Add passwd completions #4209
Conversation
share/completions/passwd.fish
Outdated
# Currently works only for Linux, written under Debian Stretch, shadow-utils 4.4 | ||
# TODO: add *BSD support | ||
|
||
if test (uname) = "Linux" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use uname
tests unless it absolutely cannot be helped (e.g. for killall
, since on Solaris we cannot invoke that ever because it kills all processes). This is mainly because you can install different versions of a tool on different OSs - @krader1961 installs gnu tools on macOS.
Usually, we try if $command --help >/dev/null ^&1
to detect gnu-ish versions of a command, which should also work here.
Me neither, but what I've found is that the man pages are usually accurate enough to write completions by, and that the tools are so simple that there isn't much to do. See http://www.unix.com/man-page/freebsd/1/passwd/, https://ss64.com/osx/passwd.html and http://www.unix.com/man-page/sunos/1/passwd/. Of note here is that, while they are quite different, I'd imagine the options they offer to be uncommonly used, and that all of them accept a username without option. So, if you want, you can add that part unconditionally and do the options if the "--help" check succeeds. The rest is nice to have but not necessary. |
In fact, I preferred not adding completions without being able to test them, but if it's OK to do so, then I will, with the help of your command; in that case, I noticed that different BSD flavors have different options for I might add that the |
Yes, for completions it's okay to do so. The worst that can happen is that executing that completion prints an error message, and that's unlikely in this case as you wouldn't be doing anything complicated.
It only uses that for Anyway, that function is in need of some love - I'd actually argue that it should be split up (or at least take an argument for which package it should use), since it's only ever called by completions for package management tools. If you ever install multiple of them (e.g. to create a container for a different distribution), it might print packages for the wrong package manager. It also has a comment about the |
Let's go, then. However, it looks like you missed my edit: I noticed that different BSD flavors have different options for passwd. I can't add all of them, so which ones should I add – FreeBSD and macOS, I assume – and which test to use to distinguish them? |
Humm... that's actually a good question... This might actually really need a uname check. We could So, how about this:
? |
So be it. Please note, though, that I'm developping that at work, as my boss allows me to improve open source software and publish that when the improvement is useful to my work. As we don't use BSD, I'm a bit outside scope, but I don't wan't to turn off your advices on improving my PR, so I'll split the difference and stick with what is AFAIK the top 3: FreeBSD, OpenBSD and macOS. Their man are easy to find and adding them won't be a big deal, while covering something like 90% of BSD users. |
Neat. You're probably the second person paid to work on fish (the creator of vi-mode got a bounty for it). |
Here comes the completions with the modifications you requested. |
Also merged, thanks! |
Description
This PR adds completions for the
passwd
command. It works for Linux, as I don't know BSD enough to reliably add completions.TODOs: