-
Notifications
You must be signed in to change notification settings - Fork 379
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
Support for setfacl #639
Open
Roy-Orbison
wants to merge
2
commits into
scop:main
Choose a base branch
from
Roy-Orbison:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Support for setfacl #639
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# setfacl(1) completion -*- shell-script -*- | ||
|
||
_comp_cmd_setfacl() | ||
{ | ||
local cur prev words cword split | ||
# Don't treat user:group as separate words. | ||
_init_completion -s -n : || return | ||
|
||
if (( cword >= 2 )); then | ||
local word | ||
for word in "${words[@]:1:cword - 1}"; do | ||
if [[ "$word" == '--' ]]; then | ||
_filedir | ||
return 0 | ||
fi | ||
done | ||
fi | ||
|
||
case "$prev" in | ||
--restore) | ||
_filedir | ||
return 0 | ||
;; | ||
|
||
-m|--modify|-x|--remove|--set) | ||
local other_rules prefix_default mycur | ||
other_rules="${cur%"${cur##*,}"}" | ||
cur="${cur##*,}" | ||
if [[ $cur = d:* || $cur = default:* ]]; then | ||
prefix_default=${cur%%"${cur#*:}"} | ||
cur="${cur#*:}" | ||
else | ||
prefix_default= | ||
fi | ||
mycur="${cur##*:}" | ||
if [[ $cur == *:*:*:* ]]; then | ||
return | ||
elif [[ $cur == *:*:* || $cur == [mo]*:* ]]; then | ||
local opts | ||
opts='- r w x X rw rx rX wx wX rwx rwX' | ||
COMPREPLY=( $( compgen -S ',' -W "$opts" -- "$mycur" ) ) | ||
elif [[ $cur == u*:* ]]; then | ||
local IFS | ||
IFS=$'\n' | ||
COMPREPLY=( $( compgen -u -S ':' -- "$mycur" ) ) | ||
elif [[ $cur == g*:* ]]; then | ||
local IFS | ||
IFS=$'\n' | ||
COMPREPLY=( $( compgen -g -S ':' -- "$mycur" ) ) | ||
else | ||
local prefixes | ||
prefixes='user: group: mask: other:' | ||
if [[ -z $prefix_default ]]; then | ||
prefixes+=' default:' | ||
fi | ||
COMPREPLY=( $( compgen -W "$prefixes" -- "$mycur" ) ) | ||
fi | ||
if [[ $cur != *:* && -z $prefix_default && "$other_rules" && ${#COMPREPLY[@]} -eq 1 ]]; then | ||
COMPREPLY=("${other_rules##*:}${COMPREPLY[0]}") | ||
fi | ||
[[ $COMPREPLY == *[:,] ]] && compopt -o nospace | ||
return 0 | ||
;; | ||
|
||
-M|--modify-file|-X|--remove-file|--set-file) | ||
_filedir | ||
return 0 | ||
;; | ||
|
||
esac | ||
|
||
$split && return 0 | ||
|
||
if [[ "$cur" == -* || $cword -eq 1 ]]; then | ||
local opts | ||
opts='--modify-file= --modify --remove-file= --remove --set-file= --set | ||
--remove-all --remove-default --no-mask --mask --default --test | ||
--recursive --logical --physical --' | ||
if [[ ${#words[@]} -eq 2 ]]; then | ||
opts+=' --version --help --restore=' | ||
elif [[ ${#words[@]} -eq 3 && "$prev" == --test ]]; then | ||
opts+=' --restore=' | ||
fi | ||
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) ) | ||
[[ $COMPREPLY == *= ]] && compopt -o nospace | ||
else | ||
_filedir | ||
fi | ||
} && | ||
complete -F _comp_cmd_setfacl setfacl | ||
|
||
# ex: ts=4 sw=4 et filetype=sh |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I haven't checked the actual behavior, but I guess this has the same problem as #913 (comment) when
bind 'set show-all-if-ambiguous on'
is set.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.
This probably wouldn't have been picked up by the
setfacl
team, and you'd know better than I how to fix it.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.
There is no robust way to make the displayed list compact. You'll need to always prefix the
other_rules
in the same way as PR #913. For example,But I haven't tried to understand the partOK, I think I now understand it.[[ $cur != *:* && -z $prefix_default ]]
, so it might not result in an expected result. Could you explain the condition[[ $cur != *:* && -z $prefix_default ]]
?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.
Re #913:
My understanding was that omitting the prefix when there are multiple candidates makes the list more concise, thus easier to visually scan & less likely to cause pagination. It also provides the ability to create richer results, as demonstrated in this article.
Without your suggestion the behaviour is like this:
With it, the previous definition's mode is prepended to the next definition, which is a drop in readability:
I tried to replicate the prefix loss per the last snippet of your comment, but it did not seem to occur. Perhaps this function is not affected due to the slightly different behviour around colons?