-
Notifications
You must be signed in to change notification settings - Fork 273
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
Request for bash-completion support #87
Comments
@tresf what shall be completed? Please add more details. |
I'm not yet familiar with To that point, this is just adding a command's bash-completion to user-space upon app registration not unlike what appimaged currently does for mimetypes, application icons, etc. Although this is most common for CLI applications, GUI applications may also choose to offer this as well. |
The question here will be if there is a way to extend the bash-completion functionalities without the need of being root. |
@azubieta good point. If the current user-space specification does not permit the use of an equivalent of the root If there are plans in the gnu.org specification to eventually add user-space |
@tresf currently we are focused on other topics, but we are open for "pull requests" 😄 |
This is a topic for libappimage's desktop integration code. CC @probonopd |
Yes. Question: I have 5 different versions of |
Good question. I have a counter-question and it may be too soon to answer but if this ever comes to fruition, is the standard place OK for bundling, e.g. |
As per the AppDir spec (made by the ROX filer team), it is not defined where stuff goes inside an AppDir. However, for So if on "normal" systems |
Bash completions for
However, before the completions can be used, the user must first load the completion script by running: source ~/.local/share/bash-completion/completions/myapp The completion will now work, but only until the user closes their shell. To make it permanent you could add that line to for script in ~/.local/share/bash-completion/completions/*; do
[[ -r "${script}" ]] && source "${script}"
done This only has to be done once and it will work for all past and future completion scripts installed in |
The completions script for # install this file to '/usr/share/bash-completion/completions/myapp' or similar
function _myapp() {
# completion logic
}
complete -F _myapp myapp Notice that this is just an ordinary bash script. It contains a function called If the binary was called something other than complete -F _myapp MyApp.AppImage In this case it is not necessary to rename the function or the script file itself. However, if multiple versions of # install this file to '/usr/share/bash-completion/completions/myapp-1.0' or similar
function _myapp-1.0() {
# completion logic
}
complete -F _myapp-1.0 MyApp-1.0.AppImage |
Can't this same question be asked for all AppImage registrations? It seems like no matter what the appimage daemon does, it stands to conflict in areas of multiple registrations. FIFO is probably best philosophy; last to register is priority (unless the daemon has some other priority logic I'm unaware of). Anyway... @shoogle thanks for chiming in. I feel strongly that the namespace avoidance won't be well received by application developers (they won't want to hard-code any versioning into the completion logic)... but to entertain the concept... Take the following examples which accommodates just-in-time namespace avoidance... eval "$(sed 's/_myapp/_myapp_a1b2c3d4e5/g' /usr/share/bash-completion/completions/myapp)"
# where "myapp" is the registered executable name*
# where "a1b2c3d4e5" is the appimage's unique hash prefix/suffix * Note, the above is only for example and does not take into consideration the mounted location. Test bash completion registration... complete |grep myapp
# outputs:
# complete -F _myapp_a1b2c3d4e5 myapp If the daemon could do something similar, it should work. What's unique about completion is it lives in memory only, so just-in-time variable replacement should be of no consequence.
I hadn't thought of the consequences. I guess a final - complete -F _myapp_a1b2c3d4e5 myapp
+ (e.g.) complete -F _myapp_a1b2c3d4e5 <path-to>/myapp_1.0.0.AppImage
+ (e.g.) complete -F _myapp_a1b2c3d4e5 ~/Downloads/myapp_1.0.0.AppImage Resulting in something like this... eval "$(sed 's/_myapp/_myapp_a1b2c3d4e5/g' /usr/share/bash-completion/completions/myapp | sed 's/complete -F _myapp_a1b2c3d4e5 myapp/complete -F _myapp_a1b2c3d4e5 \/$HOME\/Downloads\/myapp-1.0.0.AppImage/g')"
# FIXME: Doesn't guard for spaces in appimage path |
The question has indeed been asked for other registrations, and in most cases it has even been answered! There are usually ways to avoid conflicts, usually by renaming files, though it does occasionally involve patching upstream code. Bash completion is an interesting case. Since these completion scripts are just ordinary Bash scripts, they can be made to execute any arbitrary code. You could even have something like this: # install this file to '/usr/share/bash-completion/completions/appimages' or similar
function _appimage_completion() {
# 1. work out which appimage is being completed for
# 2. mount and extract that appimage
# 3. source its completion script
# 4. hand over to its completion function
}
complete -F _appimage_completion MyApp-1.0.AppImage
complete -F _appimage_completion MyApp-2.0.AppImage
complete -F _appimage_completion OtherApp-1.0.AppImage So in the specific case of Bash completion, there is actually no need to "install" the completion files at all, as they can be loaded dynamically from within the AppImage, thereby avoiding conflicts altogether! Of course this might not be such a great idea as it involves mounting and extracting the AppImage each time the user wants to complete something, but it is at least a possibility. |
@tresf, it's best not to give a full path to complete -F _myapp /home/user/Applications/MyApp.AppImage ... then completion will only work when the user types the full path to the command.
If you do... complete -F _myapp MyApp.AppImage ... then completion works in all cases. Admittedly this means it will be triggered for any binary called |
Since Bash completion scripts run actual terminal commands, patching them can get complicated and could even be considered dangerous! Consider this example: # install this file to '/usr/share/bash-completion/completions/myapp' or similar
function _myapp() {
# completion logic
var="$(_helper_function "${args}")"
# do something with ${var}
}
function _helper_function() {
# more completion logic
}
complete -F _myapp myapp In this case the # install this file to '/usr/share/bash-completion/completions/myapp-1.0' or similar
function _myapp-1.0() {
# completion logic
var="$(_myapp-1.0_helper_function "${args}")"
# do something with ${var}
}
function _myapp-1.0_helper_function() {
# more completion logic
}
complete -F _myapp-1.0 MyApp-1.0.AppImage This can quickly get complicated, so it is probably better to either:
|
The disambiguous use-case isn't an issue in my tests. Works fine so as long as the functions are properly prefixed with |
Oh, I see the bug... |
Seems like you're making some progress here. Haven't had the time to read it all yet, though. One thing I am concerned about is, do we really want to automatically install stuff that changes the users' shell behavior? Those scripts might break the shell even, and prevent logging in. I guess, if we realize this, it must be an opt-in feature, and there should be a preview feature or so. |
AppImage is about GUI applications first and foremost. macOS |
I wouldn't mind merging a PR into libappimage on this. |
@TheAssassin said
Quite right! The safest thing to do is scan for files in for script in ~/.local/share/bash-completion/completions/*; do
[[ -r "${script}" ]] && source "${script}"
done An opt-in system like this offers a nice preview of what users can expect to enjoy by default once the wider issues with desktop integration have been sorted out, but being opt-in also means that we don't need to worry about conflicts and bugs as much as we would have to if it were opt-out. @probonopd said
No, but then Homebrew Cask arose as a way to install |
Yet the two steps to run an appimage per the official website are still CLI instructions. ;) |
Excellent point. Although that's only an issue of the website, not of AppImage: [The reason the website is in its current state is that it is almost impossible for me to edit (without the fear of breaking everything) since it has been divided into individual sentences for translation with Weblate. I like Weblate but for a webpage it doesn't seem to be the most straightforward tool.] |
@shoogle what I meant was a "per AppImage" choice, not a "take it or leave it" one. Maybe with a checkbox in the integration dialog. |
It arguably is "per AppImage", because completion won't actually happen unless the binary is named like in: complete -F _script binary Since most will be named like ln -s ~/Applications/Binary-X.Y.Z-x86_64.AppImage ~/bin/binary I left this out to keep it simple. I think it is reasonable to assume that most people who want to use Bash completion with an AppImage also wants it to be in However, the completion scripts would still be sourced even though the functions inside them were never actually used. You can make it fully "per AppImage" by sourcing each script individually: source ~/.local/share/bash-completion/completions/myapp
source ~/.local/share/bash-completion/completions/myotherapp |
Which is kind of awkward especially when trying to support completions for different versions of the same app (you'd have some random MD5 data in the names then). Therefore the idea of making it like "easy" to do it per-AppImage, e.g., with a checkmark. Then you can just include anything in that directory instead. |
Enhancement request for the ability to add
bash-completion
support to the launcher registration.Not sure how technically feasible this is. The location is
~/.bash_completion
file per: https://serverfault.com/a/506707/34498Complementary discussion with @azubieta on #appimage on irc.freenode.net.
The text was updated successfully, but these errors were encountered: