Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion completions/patch
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ _comp_cmd_patch()
[[ $was_split ]] && return

if [[ $cur == -* ]]; then
_comp_compgen_help
if [[ $OSTYPE == *@(darwin|bsd)* ]]; then
_comp_compgen_usage
else
_comp_compgen_help
fi
Comment on lines +53 to +57
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, the preferred pattern for cases like these is

Suggested change
if [[ $OSTYPE == *@(darwin|bsd)* ]]; then
_comp_compgen_usage
else
_comp_compgen_help
fi
_comp_compgen_help || _comp_compgen_usage

This frees us from hardwiring "known" OS dependencies, as well as helps with cases for which detection isn't that feasible, such as Alpine systems where a command might be a GNU one supporting long options (_comp_compgen_help applies), or a busybox one that supports only short ones (_comp_compgen_usage applies).

[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
Expand Down
6 changes: 5 additions & 1 deletion completions/truncate
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ _comp_cmd_truncate()
[[ $was_split ]] && return

if [[ $cur == -* ]]; then
_comp_compgen_help
if [[ $OSTYPE == *@(darwin|bsd)* ]]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

_comp_compgen_usage
else
_comp_compgen_help
fi
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
Expand Down
Loading