Skip to content

Commit

Permalink
Update the Bash completion to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0mp committed Mar 9, 2018
1 parent a703304 commit 7604fb0
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions completions/bash/poudriere
Expand Up @@ -27,15 +27,16 @@
# SUCH DAMAGE. # SUCH DAMAGE.
# #
# --- # ---
# Version: 0.1.0 # Version: 0.2.0
# Upstream: https://github.com/0mp/poudriere-bash-completion/


_poudriere_absolute_path() { _poudriere_absolute_path() {
COMPREPLY=($(compgen -f "${cur:-/}" -- "$cur")) COMPREPLY=($(compgen -f "${cur:-/}" -- "$cur"))
} }


# XXX: It might be non exhaustive. # XXX: It does not complete the architectures available thanks to the QEMU option.
_poudriere_architecture() { _poudriere_architecture() {
COMPREPLY=($(compgen -W 'amd64 i386' -- "$cur")) COMPREPLY=($(compgen -W "$(sysctl -n kern.supported_archs)" -- "$cur"))
} }


# TODO: Parse poudriere status. # TODO: Parse poudriere status.
Expand All @@ -47,6 +48,7 @@ _poudriere_direct_port() {
# Find a ports tree to search for ports. # Find a ports tree to search for ports.
local prev_word= local prev_word=
local ports_tree= local ports_tree=
local w
# Find out if a ports tree is already specified with -p. # Find out if a ports tree is already specified with -p.
for w in ${words[@]}; do for w in ${words[@]}; do
if [[ $w == -p ]]; then if [[ $w == -p ]]; then
Expand Down Expand Up @@ -81,13 +83,37 @@ _poudriere_filesystem() {
fi fi
} }


# In order to avoid an obvious bitrot, this function depends on the contents of
# /usr/share/misc/bsd-family-tree. The list of generated versions depends on
# the FreeBSD version running on the host machine. If it's running CURRENT then
# the list includes two latest RELEASE branches of two previous major versions
# as well as their STABLE branches. Otherwise, only one previous major version
# is included. SVN branches are included accordingly. This way the list
# contains versions, which should run without any problems.
# For example, when the host is running 12.0-CURRENT the list will contain the
# following targets (as of 2018.03.09): 10-STABLE, 10.3-RELEASE, 10.4-RELEASE,
# 11-STABLE, 11.0-RELEASE, 11.1-RELEASE, 12.0-CURRENT, head, release/10.3,
# release/10.4, release/11.0, release/11.1, stable/10, stable/11.
_poudriere_freebsd_version() { _poudriere_freebsd_version() {
# XXX: It might be non exhaustive. local machine_version="$(freebsd-version)" # E.g. 12.0-CURRENT
# For example it does not include options like: local machine_major="${machine_version/[.-]*/}" # E.g. 12
# stable/11, stable/10@123456 local machine_branch="${machine_version##*-}" # E.g. CURRENT
COMPREPLY+=($(compgen -W "10.3 10.4 11.1" -S '-RELEASE' -- "$cur")) local supported_branches=() # E.g. 12.0-CURRENT 11-STABLE 11.1-RELEASE
COMPREPLY+=($(compgen -W "10.4 11.1" -S '-STABLE' -- "$cur")) local supported_majors=($((machine_major - 1))) # E.g. 12 11 10
COMPREPLY+=($(compgen -W "12.0" -S '-CURRENT' -- "$cur")) local release_versions=() # E.g. 11.1 11.0 10.4
if [[ $machine_branch == CURRENT ]]; then
supported_branches+=("$machine_version")
supported_majors+=($((machine_major - 2)))
else
supported_majors+=($machine_major)
fi
local major
for major in ${supported_majors[@]}; do
supported_branches+=($major-STABLE stable/$major)
release_versions+=($(awk "/FreeBSD $major/{print \$2}" /usr/share/misc/bsd-family-tree | tail -n 2))
supported_branches+=("${release_versions[@]/%/-RELEASE}" "${release_versions[@]/#/release/}")
done
COMPREPLY=($(compgen -W "head ${supported_branches[*]}" -- "$cur"))
} }


# XXX: A little bit slow due to poudriere jail -l. # XXX: A little bit slow due to poudriere jail -l.
Expand Down Expand Up @@ -120,6 +146,7 @@ _poudriere()
# Is the command already selected? # Is the command already selected?
local pipe_separated_command_list="$(tr ' ' '|' <<< "${command_list[@]}")" local pipe_separated_command_list="$(tr ' ' '|' <<< "${command_list[@]}")"
local selected_command= local selected_command=
local i
for (( i=0 ; i < "${#words[@]}" ; i++ )); do for (( i=0 ; i < "${#words[@]}" ; i++ )); do
word="${words[$i]}" word="${words[$i]}"
if [[ $word =~ $pipe_separated_command_list ]]; then if [[ $word =~ $pipe_separated_command_list ]]; then
Expand Down Expand Up @@ -165,7 +192,7 @@ _poudriere()
if [[ $cur != -* ]]; then if [[ $cur != -* ]]; then
_poudriere_direct_port _poudriere_direct_port
fi fi
if [[ ${COMPREPLY[@]} -eq 0 ]]; then if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur")) COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur"))
fi fi
;; ;;
Expand All @@ -187,7 +214,7 @@ _poudriere()
if [[ $cur != -* ]]; then if [[ $cur != -* ]]; then
_poudriere_direct_port _poudriere_direct_port
fi fi
if [[ ${COMPREPLY[@]} -eq 0 ]]; then if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur")) COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur"))
fi fi
;; ;;
Expand Down Expand Up @@ -341,7 +368,7 @@ _poudriere()
if [[ $cur != -* ]]; then if [[ $cur != -* ]]; then
_poudriere_direct_port _poudriere_direct_port
fi fi
if [[ ${COMPREPLY[@]} -eq 0 ]]; then if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur")) COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur"))
fi fi
;; ;;
Expand Down Expand Up @@ -369,15 +396,13 @@ _poudriere()
if [[ $cur != -* ]]; then if [[ $cur != -* ]]; then
_poudriere_direct_port _poudriere_direct_port
fi fi
if [[ ${COMPREPLY[@]} -eq 0 ]]; then if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur")) COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command)" -- "$cur"))
fi fi
;; ;;
esac esac
;; ;;


# TODO: queue) ;;

status) status)
case "$prev" in case "$prev" in
-B) -B)
Expand Down Expand Up @@ -423,7 +448,7 @@ _poudriere()
if [[ $cur != -* ]]; then if [[ $cur != -* ]]; then
_poudriere_direct_port _poudriere_direct_port
fi fi
if [[ ${COMPREPLY[@]} -eq 0 ]]; then if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command) -o" -- "$cur")) COMPREPLY=($(compgen -W "$(_parse_help poudriere $selected_command) -o" -- "$cur"))
fi fi
;; ;;
Expand Down

0 comments on commit 7604fb0

Please sign in to comment.