mas/contrib/completion/mas-completion.bash
Justin Lecher 7fe27fc693 Use posix compliant tail syntax
homebrew allows using gnu coreutils on MacOS. Therefore we should
comply with posix standards

```bash
$ mas help | tail +3
tail: cannot open '+3' for reading: No such file or directory
$ type tail
tail is /usr/local/opt/coreutils/libexec/gnubin/tail
```

Switching to posix compliant `-n` syntax is compatible with UNIX and GNU tooling.

```bash
$ mas help | /usr/bin/tail -n +3 | wc -l
18
$ mas help | tail -n +3 | wc -l
18
```
2021-11-01 22:02:12 -07:00

17 lines
371 B
Bash

#!/usr/bin/env bash
_mas() {
local cur prev words cword
if declare -F _init_completions >/dev/null 2>&1; then
_init_completion
else
COMPREPLY=()
_get_comp_words_by_ref cur prev words cword
fi
if [[ $cword -eq 1 ]]; then
COMPREPLY=($(compgen -W "$(mas help | tail -n +3 | awk '{print $1}')" -- "$cur"))
return 0
fi
}
complete -F _mas mas