-
-
Notifications
You must be signed in to change notification settings - Fork 302
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
Provide support for ncc bash completion #1303
Comments
this is cool, please provide a PR |
Thanks! Thinking a bit more about it, I think this solution is quite dirty and weak, as the generated completion file needs to be changed, if what's generated is changed, it could easily break. There is actually another option to To fix this one option would to make a copy of the I don't see any solution elegant enough to be comfortable to send a PR. I guess the only elegant solution would be to add an option to Anyway, I'd be glad to hear opinions about the trade-offs and what to do about this. |
I think, something like The above command results in: function _ncc_9cbb1906d0cf7a74_complete {
local CMDLINE_CONTENTS="$COMP_LINE";
local CMDLINE_CURSOR_INDEX="$COMP_POINT";
local CMDLINE_WORDBREAKS="$COMP_WORDBREAKS";
export CMDLINE_CONTENTS CMDLINE_CURSOR_INDEX CMDLINE_WORDBREAKS;
local RESULT STATUS;
local IFS=$'\n';
RESULT="$(ncc _completion --shell-type bash </dev/null)";
STATUS=$?;
local cur mail_check_backup;
mail_check_backup=$MAILCHECK;
MAILCHECK=-1;
_get_comp_words_by_ref -n : cur;
if [ $STATUS -eq 200 ]; then
compopt -o default;
return 0;
elif [ $STATUS -ne 0 ]; then
echo -e "$RESULT";
return $?;
fi;
COMPREPLY=(`compgen -W "$RESULT" -- $cur`);
__ltrim_colon_completions "$cur";
MAILCHECK=mail_check_backup;
};
if [ "$(type -t _get_comp_words_by_ref)" == "function" ]; then
complete -F _ncc_9cbb1906d0cf7a74_complete "ncc";
else
>&2 echo "Completion was not registered for ncc:";
>&2 echo "The 'bash-completion' package is required but doesn't appear to be installed.";
fi; |
this seems to work pretty well :) thanks |
Just stumbled on this issue page. I don't know if this PR for nextcloud/server will help anyone trying to get simple bash tab completion working: Two bash scripts:
|
Description
The
ncc
command should have a bash completion so it's easier to discover and auto-complete commands.Example
ncc <TAB>
should complete.Necessary changes
There are 3 main necessary changes needed for this:
ncc
idiosyncrasies./usr/local/bin/ncc
command sosudo
forwards (at least) these three environment variables:CMDLINE_CONTENTS
CMDLINE_CURSOR_INDEX
andCMDLINE_WORDBREAKS
The generated script by 1 seems pretty static and can probably generate once at install time and maybe, just in case, each time the nextcloud instance is updated. Step 2 can also be automated (to some degree, as if the generated script changes too much the update can fail). I'm doing this in the current version to adapt it:
(for a system install
~/.local/share/bash-completion/completions/ncc
can be replaced with/usr/share/bash-completion/completions
for example)Step 3 can be easily done by adding
--preserve-env=CMDLINE_CONTENTS,CMDLINE_CURSOR_INDEX,CMDLINE_WORDBREAKS
to/usr/local/bin/ncc
.The text was updated successfully, but these errors were encountered: