Skip to content

Instantly share code, notes, and snippets.

@mbauman
Created February 23, 2011 02:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbauman/839902 to your computer and use it in GitHub Desktop.
Save mbauman/839902 to your computer and use it in GitHub Desktop.
A patch to bash-completion version 1.3 (http://bash-completion.alioth.debian.org/). Adds completions for Mac OS X specific utilities: defaults, launchctl, open, and xcodebuild. Additionally, it properly enables killall.
diff -Naur bash-completion-1.3/completions/Makefile.am bash-completion-1.3-mac/completions/Makefile.am
--- bash-completion-1.3/completions/Makefile.am 2011-01-21 04:36:11.000000000 -0500
+++ bash-completion-1.3-mac/completions/Makefile.am 2011-02-22 22:02:25.000000000 -0500
@@ -33,6 +33,7 @@
cvs \
cvsps \
dd \
+ defaults \
dhclient \
dict \
dpkg \
@@ -72,6 +73,7 @@
k3b \
kldload \
larch \
+ launchctl \
ldapvi \
lftp \
lilo \
@@ -105,6 +107,7 @@
net-tools \
nmap \
ntpdate \
+ open \
openldap \
openssl \
open-iscsi \
@@ -177,7 +180,8 @@
xsltproc \
xz \
yp-tools \
- yum-arch
+ yum-arch \
+ xcodebuild
EXTRA_DIST = $(bashcomp_DATA) \
_mock _modules _subversion _yum _yum-utils
diff -Naur bash-completion-1.3/completions/Makefile.in bash-completion-1.3-mac/completions/Makefile.in
--- bash-completion-1.3/completions/Makefile.in 2011-02-06 14:16:21.000000000 -0500
+++ bash-completion-1.3-mac/completions/Makefile.in 2011-02-22 22:01:48.000000000 -0500
@@ -216,6 +216,7 @@
cvs \
cvsps \
dd \
+ defaults \
dhclient \
dict \
dpkg \
@@ -255,6 +256,7 @@
k3b \
kldload \
larch \
+ launchctl \
ldapvi \
lftp \
lilo \
@@ -288,6 +290,7 @@
net-tools \
nmap \
ntpdate \
+ open \
openldap \
openssl \
open-iscsi \
@@ -360,7 +363,8 @@
xsltproc \
xz \
yp-tools \
- yum-arch
+ yum-arch \
+ xcodebuild
EXTRA_DIST = $(bashcomp_DATA) \
_mock _modules _subversion _yum _yum-utils
diff -Naur bash-completion-1.3/completions/defaults bash-completion-1.3-mac/completions/defaults
--- bash-completion-1.3/completions/defaults 1969-12-31 19:00:00.000000000 -0500
+++ bash-completion-1.3-mac/completions/defaults 2011-02-22 20:27:31.000000000 -0500
@@ -0,0 +1,175 @@
+# defaults
+# Bash command line completion for defaults
+#
+# Created by Jonathon Mah on 2006-11-08.
+# Copyright 2006 Playhaus. All rights reserved.
+#
+# This file is licensed under the BSD license, as follows:
+#
+# Copyright (c) 2006, Playhaus
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of the Playhaus nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# This software is provided by the copyright holders and contributors "as is"
+# and any express or implied warranties, including, but not limited to, the
+# implied warranties of merchantability and fitness for a particular purpose are
+# disclaimed. In no event shall the copyright owner or contributors be liable
+# for any direct, indirect, incidental, special, exemplary, or consequential
+# damages (including, but not limited to, procurement of substitute goods or
+# services; loss of use, data, or profits; or business interruption) however
+# caused and on any theory of liability, whether in contract, strict liability,
+# or tort (including negligence or otherwise) arising in any way out of the use
+# of this software, even if advised of the possibility of such damage.
+#
+# Version 1.0 (2006-11-08)
+
+[ $UNAME = Darwin ] && have defaults &&
+{
+_defaults_domains()
+{
+ local cur
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+
+ local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur" )
+ local IFS=$'\n'
+ COMPREPLY=( $domains )
+ if [[ $( echo '-app' | grep "^$cur" ) ]]; then
+ COMPREPLY[${#COMPREPLY[@]}]="-app"
+ fi
+
+ return 0
+}
+
+
+_defaults()
+{
+ local cur prev host_opts cmds cmd domain keys key_index
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ host_opts='-currentHost -host'
+ cmds='read read-type write rename delete domains find help'
+
+ if [[ $COMP_CWORD -eq 1 ]]; then
+ COMPREPLY=( $( compgen -W "$host_opts $cmds" -- $cur ) )
+ return 0
+ elif [[ $COMP_CWORD -eq 2 ]]; then
+ if [[ "$prev" == "-currentHost" ]]; then
+ COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
+ return 0
+ elif [[ "$prev" == "-host" ]]; then
+ return 0
+ _known_hosts -a
+ else
+ _defaults_domains
+ return 0
+ fi
+ elif [[ $COMP_CWORD -eq 3 ]]; then
+ if [[ ${COMP_WORDS[1]} == "-host" ]]; then
+ _defaults_domains
+ return 0
+ fi
+ fi
+
+ # Both a domain and command have been specified
+
+ if [[ ${COMP_WORDS[1]} == @(${cmds// /|}) ]]; then
+ cmd=${COMP_WORDS[1]}
+ domain=${COMP_WORDS[2]}
+ key_index=3
+ if [[ "$domain" == "-app" ]]; then
+ if [[ $COMP_CWORD -eq 3 ]]; then
+ # Completing application name. Can't help here, sorry
+ return 0
+ fi
+ domain="-app ${COMP_WORDS[3]}"
+ key_index=4
+ fi
+ elif [[ ${COMP_WORDS[2]} == "-currentHost" ]] && [[ ${COMP_WORDS[2]} == @(${cmds// /|}) ]]; then
+ cmd=${COMP_WORDS[2]}
+ domain=${COMP_WORDS[3]}
+ key_index=4
+ if [[ "$domain" == "-app" ]]; then
+ if [[ $COMP_CWORD -eq 4 ]]; then
+ # Completing application name. Can't help here, sorry
+ return 0
+ fi
+ domain="-app ${COMP_WORDS[4]}"
+ key_index=5
+ fi
+ elif [[ ${COMP_WORDS[3]} == "-host" ]] && [[ ${COMP_WORDS[3]} == @(${cmds// /|}) ]]; then
+ cmd=${COMP_WORDS[3]}
+ domain=${COMP_WORDS[4]}
+ key_index=5
+ if [[ "$domain" == "-app" ]]; then
+ if [[ $COMP_CWORD -eq 5 ]]; then
+ # Completing application name. Can't help here, sorry
+ return 0
+ fi
+ domain="-app ${COMP_WORDS[5]}"
+ key_index=6
+ fi
+ fi
+
+ keys=$( defaults read $domain 2>/dev/null | sed -n -e '/^ [^}) ]/p' | sed -e 's/^ \([^" ]\{1,\}\) = .*$/\1/g' -e 's/^ "\([^"]\{1,\}\)" = .*$/\1/g' | sed -e 's/ /\\ /g' )
+
+ case $cmd in
+ read|read-type)
+ # Complete key
+ local IFS=$'\n'
+ COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
+ ;;
+ write)
+ if [[ $key_index -eq $COMP_CWORD ]]; then
+ # Complete key
+ local IFS=$'\n'
+ COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
+ elif [[ $((key_index+1)) -eq $COMP_CWORD ]]; then
+ # Complete value type
+ # Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
+ local value_types='-string -data -integer -float -boolean -date -array -array-add -dict -dict-add'
+ local cur_type=$( defaults read-type $domain ${COMP_WORDS[key_index]} 2>/dev/null | sed -e 's/^Type is \(.*\)/-\1/' -e's/dictionary/dict/' | grep "^$cur" )
+ if [[ $cur_type ]]; then
+ COMPREPLY=( $cur_type )
+ else
+ COMPREPLY=( $( compgen -W "$value_types" -- $cur ) )
+ fi
+ elif [[ $((key_index+2)) -eq $COMP_CWORD ]]; then
+ # Complete value
+ # Unfortunately ${COMP_WORDS[key_index]} fails on keys with spaces
+ COMPREPLY=( $( defaults read $domain ${COMP_WORDS[key_index]} 2>/dev/null | grep -i "^${cur//\\/\\\\}" ) )
+ fi
+ ;;
+ rename)
+ if [[ $key_index -eq $COMP_CWORD ]] ||
+ [[ $((key_index+1)) -eq $COMP_CWORD ]]; then
+ # Complete source and destination keys
+ local IFS=$'\n'
+ COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
+ fi
+ ;;
+ delete)
+ if [[ $key_index -eq $COMP_CWORD ]]; then
+ # Complete key
+ local IFS=$'\n'
+ COMPREPLY=( $( echo "$keys" | grep -i "^${cur//\\/\\\\}" ) )
+ fi
+ ;;
+ esac
+
+ return 0
+}
+complete -F _defaults -o default defaults
+}
diff -Naur bash-completion-1.3/completions/launchctl bash-completion-1.3-mac/completions/launchctl
--- bash-completion-1.3/completions/launchctl 1969-12-31 19:00:00.000000000 -0500
+++ bash-completion-1.3-mac/completions/launchctl 2011-02-22 21:02:35.000000000 -0500
@@ -0,0 +1,171 @@
+# ex: filetype=sh et sw=4
+#
+# launchctl(1) completion
+#
+[ $UNAME = Darwin ] && have launchctl &&
+{
+_launchctl()
+{
+ local cur oslevel
+
+ oslevel=${OSTYPE//darwin/}
+ oslevel=${oslevel%%.*}
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [[ $COMP_CWORD -eq 1 ]]; then
+ local commands
+
+ commands="load unload start stop list setenv unsetenv \
+ getenv export limit shutdown getrusage log umask help"
+
+ if [[ $oslevel -le 8 ]]; then
+ commands+=" reloadttys stdout stderr"
+ fi
+
+ if [[ $oslevel -ge 9 ]]; then
+ commands+=" submit remove bootstrap singleuser bsexec bslist"
+ if [[ $oslevel -ge 10 ]]; then
+ commands+=" bstree managerpid manageruid managername"
+ fi
+ fi
+ COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
+ else
+ local command
+ command=${COMP_WORDS[1]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$command" in
+ load|unload)
+ case $prev in
+ -S)
+ COMPREPLY=( $( compgen -W "Aqua LoginWindow Background StandardIO System" -- $cur ) )
+ ;;
+ -D)
+ COMPREPLY=( $( compgen -W "system local network all user" -- $cur ) )
+ ;;
+ *)
+ opts="-w"
+ if [[ $oslevel -ge 0 ]]; then
+ opts+=" -S -D"
+ if [[ $command = load ]]; then
+ opts+=" -F"
+ fi
+ fi
+ COMPREPLY=( $( compgen -f -W "$opts" -- $cur ) )
+ ;;
+ esac
+ ;;
+ start|stop|remove|list)
+ local jobs opts
+
+ if [[ $command != list || $oslevel -ge 9 ]]; then
+ if [[ $oslevel -le 8 ]]; then
+ jobs="$( launchctl list )"
+ else
+ jobs="$( launchctl list | awk 'NR>1 { print $3 }')"
+ if [[ $oslevel -ge 10 && $command = list ]]; then
+ opts="-x"
+ fi
+ fi
+ fi
+ COMPREPLY=( $( compgen -W "$jobs $opts" -- $cur ) )
+ ;;
+ getenv|setenv|unsetenv)
+ if [[ $COMP_CWORD -eq 2 ]]; then
+ envvars="$( launchctl export | cut -f1 -d= )"
+ COMPREPLY=( $( compgen -W "$envvars" -- $cur ) )
+ fi
+ ;;
+ getrusage)
+ if [[ $COMP_CWORD -eq 2 ]]; then
+ COMPREPLY=( $( compgen -W "self children" -- $cur ) )
+ fi
+ ;;
+ limit)
+ if [[ $COMP_CWORD -eq 2 ]]; then
+ local limits
+ limits="$( launchctl limit | awk '{print $1}' )"
+ COMPREPLY=( $( compgen -W "$limits" -- $cur ) )
+ fi
+ ;;
+ log)
+ if [[ $COMP_CWORD -eq 2 ]]; then
+ COMPREPLY=( $( compgen -W "level only mask" -- $cur ) )
+ else
+ local level
+ levels="debug info notice warning error critical alert emergency"
+ case ${COMP_WORDS[2]} in
+ level)
+ if [[ $COMP_CWORD -eq 3 ]]; then
+ COMPREPLY=( $( compgen -W "$levels" -- $cur ) )
+ fi
+ ;;
+ mask|only)
+ COMPREPLY=( $( compgen -W "$levels" -- $cur ) )
+ ;;
+ esac
+ fi
+ ;;
+ stdout|stderr)
+ # Darwin 8 only
+ if [[ $oslevel -le 8 ]]; then
+ _filedir
+ fi
+ ;;
+ submit)
+ local i
+ i=1
+ while [[ $i -lt ${#COMP_WORDS[@]} ]]; do
+ if [[ "${COMP_WORDS[i-1]}" = "--" ]]; then
+ _command_offset $i
+ return 0
+ fi
+ i=$((i+1))
+ done
+
+ local submit_opts
+ submit_opts="-l -p -o -e --"
+ case $prev in
+ -l)
+ ;;
+ -p)
+ _command_offset $COMP_CWORD
+ ;;
+ -o|-e)
+ _filedir
+ ;;
+ *)
+ COMPREPLY=( $( compgen -W "$submit_opts" -- $cur ) )
+ ;;
+ esac
+
+ ;;
+ bslist)
+ local pids opts
+ pids=$( ps axo pid= )
+ [[ $oslevel -ge 10 ]] && opts="-j"
+ COMPREPLY=( $( compgen -W "$pids $opts" -- $cur ) )
+ ;;
+ bsexec)
+ if [[ $COMP_CWORD -eq 2 ]]; then
+ local pids
+ pids=$( ps axo pid= )
+ COMPREPLY=( $( compgen -W "$pids" -- $cur ) )
+ else
+ _command_offset 3
+ fi
+ ;;
+ bstree)
+ if [[ $oslevel -ge 10 ]]; then
+ COMPREPLY=( $( compgen -W "-j" -- $cur ) )
+ fi
+ ;;
+ esac
+ fi
+
+ return 0
+}
+complete -F _launchctl -o filenames launchctl
+}
diff -Naur bash-completion-1.3/completions/open bash-completion-1.3-mac/completions/open
--- bash-completion-1.3/completions/open 1969-12-31 19:00:00.000000000 -0500
+++ bash-completion-1.3-mac/completions/open 2011-02-22 20:11:14.000000000 -0500
@@ -0,0 +1,104 @@
+#
+# Copyright (c) 2004, Lukas Westermann <contact AT openos DOT ch>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# - Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+# - The names of its contributors may not be used to endorse or
+# promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# Bash Auto-Completion for the NextStep command 'open'
+#
+# History
+# ----------------------------------
+# Version 1.0.0 - initial release
+# Version 1.0.1 - added test for availabilty (Darwin only
+# and check for open)
+# Version 1.0.2 - fixed problems with IFS for -a and -e
+# Version 1.0.3 - simplified availability check
+# Version 1.0.4 - fixed problem with spaces and completion
+#
+
+[ $UNAME = Darwin ] && have open && {
+_list_apps() {
+ local IFS=$'\n'
+ find '/Applications' "${HOME}"'/Applications' '/Developer/Applications' -name "${1}*.app" -maxdepth 2 2>/dev/null
+ #TODO: MS Word and other carbon apps...HOW ???
+}
+
+_open()
+{
+
+ local cur prev IFS=$'\t\n'
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ if [[ $prev == -a ]]; then
+ local res ncur
+ ncur=$( echo "$cur" | sed -e 's/\\//g' 2>/dev/null )
+ res=$( _list_apps "${ncur}" | sed -e 's/.*\/\([^\/]*\)\.app/\1/' )
+ COMPREPLY=( $( compgen -W "${res}" -- "${ncur}" ) )
+ elif [[ $prev == -e ]]; then
+ _filedir '@(txt|doc|rtf|rtfd|pdf|png|jpg|gif)'
+ elif [[ $cur == -* ]]; then
+ local IFS=$' \t\n'
+ COMPREPLY=( $( compgen -W '-a -e' -- "$cur" ) )
+ else
+ local first="${COMP_WORDS[1]}" second="${COMP_WORDS[2]}"
+ if [[ $first == -a ]]; then
+ case "$second" in
+ QuickTime*)
+ _filedir '@(mp3|mpg|mpeg|avi|m4*|mov|alc)'
+ ;;
+ iTunes)
+ _filedir '@(mp3|m4*|ogg|alc)'
+ ;;
+ Safari|Mozilla|Camino|Opera|Firebird)
+ # TODO: complete from history/bookmarks ?
+ _filedir '@(htm|html|xhtm|xhtml|php|php3|php3|xml)'
+ ;;
+ VLC)
+ # TODO: complete for CD/DVD too...
+ _filedir '@(avi|mpg)'
+ ;;
+ BitTorrent*)
+ _filedir '@(torrent)'
+ ;;
+ *)
+ # others, complete all
+ _filedir
+ ;;
+ esac
+ else
+ _filedir
+ fi
+ fi
+
+}
+complete -o filenames -F _open open
+}
diff -Naur bash-completion-1.3/completions/procps bash-completion-1.3-mac/completions/procps
--- bash-completion-1.3/completions/procps 2011-01-21 04:36:11.000000000 -0500
+++ bash-completion-1.3-mac/completions/procps 2011-02-22 20:52:21.000000000 -0500
@@ -2,7 +2,7 @@
# killall(1) (Linux and FreeBSD) and pkill(1) completion.
#
-[[ $UNAME == Linux || $UNAME == FreeBSD ]] || have pkill &&
+have killall || have pkill &&
_killall()
{
local cur
@@ -18,7 +18,7 @@
return 0
}
-[[ $UNAME == Linux || $UNAME == FreeBSD ]] && complete -F _killall killall
+have killall && complete -F _killall killall
have pkill && complete -F _killall pkill
# pgrep(1) completion.
diff -Naur bash-completion-1.3/completions/xcodebuild bash-completion-1.3-mac/completions/xcodebuild
--- bash-completion-1.3/completions/xcodebuild 1969-12-31 19:00:00.000000000 -0500
+++ bash-completion-1.3-mac/completions/xcodebuild 2011-02-22 20:27:08.000000000 -0500
@@ -0,0 +1,91 @@
+# xcodebuild
+# Bash command line completion for xcodebuild
+#
+# Created by Jonathon Mah on 2006-11-08.
+# Copyright 2006 Playhaus. All rights reserved.
+#
+# This file is licensed under the BSD license, as follows:
+#
+# Copyright (c) 2006, Playhaus
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of the Playhaus nor the names of its contributors may be
+# used to endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# This software is provided by the copyright holders and contributors "as is"
+# and any express or implied warranties, including, but not limited to, the
+# implied warranties of merchantability and fitness for a particular purpose are
+# disclaimed. In no event shall the copyright owner or contributors be liable
+# for any direct, indirect, incidental, special, exemplary, or consequential
+# damages (including, but not limited to, procurement of substitute goods or
+# services; loss of use, data, or profits; or business interruption) however
+# caused and on any theory of liability, whether in contract, strict liability,
+# or tort (including negligence or otherwise) arising in any way out of the use
+# of this software, even if advised of the possibility of such damage.
+#
+# Version 1.0 (2006-11-08)
+
+[ $UNAME = Darwin ] && have xcodebuild &&
+{
+_xcodebuild()
+{
+ local cur prev #cmds cmdOpts optsParam opt helpCmds optBase i
+
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ cmds='-project -activetarget -alltargets -target -activeconfiguration -configuration -version -list -help build installsrc install clean'
+
+ if [[ "$prev" = "-project" ]]; then
+ # Show list of projects
+ local projects=$( compgen -X "${1:+"!*.xcodeproj"}" -d | sed -e 's/ /\\ /g' )
+ local IFS=$'\n'
+ COMPREPLY=( $( echo "$projects" | grep "^$cur" ) )
+ elif [[ "$prev" = "-target" ]]; then
+ local arg project_args is_project_next
+ is_project_next="false"
+ for arg in ${COMP_WORDS} ; do
+ if [[ "$is_project_next" = "true" ]]; then
+ project_args="-project $arg"
+ break
+ elif [[ "$arg" = "-project" ]]; then
+ is_project_next="true"
+ fi
+ done
+ cur=$(printf '%q' "$cur" )
+ local targets=$(xcodebuild $project_args -list | sed -n -e '/^ Targets:$/,/^$/p' | sed -e '1d' -e '$d' -e 's/^[[:space:]]*//' -e 's/ (Active)$//' -e 's/ /\\ /g' | grep "^$cur" )
+ local IFS=$'\n'
+ COMPREPLY=( $targets )
+ elif [[ "$prev" = "-configuration" ]]; then
+ local arg project_args is_project_next
+ is_project_next="false"
+ for arg in ${COMP_WORDS} ; do
+ if [[ "$is_project_next" = "true" ]]; then
+ project_args="-project $arg"
+ break
+ elif [[ "$arg" = "-project" ]]; then
+ is_project_next="true"
+ fi
+ done
+ cur=$(printf '%q' "$cur" )
+ local configurations=$(xcodebuild $project_args -list | sed -n -e '/^ Build Configurations:$/,/^$/p' | sed -e '1d' -e '$d' -e 's/^[[:space:]]*//' -e 's/ (Active)$//' -e 's/ /\\ /g' | grep "^$cur" )
+ local IFS=$'\n'
+ COMPREPLY=( $configurations )
+ else
+ COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
+ fi
+
+ return 0
+}
+complete -F _xcodebuild xcodebuild
+}
@pdbj
Copy link

pdbj commented Aug 11, 2011

One more: only look at COMP_WORDS[2] if it exists:

--- /sw/etc/bash_completion.d/open      2011-08-08 16:08:30.000000000 -0700
+++ sw/etc/bash_completion.d/open       2011-08-11 11:05:31.000000000 -0700
@@ -69,9 +69,8 @@
         local IFS=$' \t\n'
         COMPREPLY=( $( compgen -W '-a -e' -- "$cur" ) )
     else
-        local first="${COMP_WORDS[1]}" second="${COMP_WORDS[2]}"
-        if [[ $first == -a ]]; then
-            case "$second" in
+        if [[ "${COMP_WORDS[1]}" == -a && ${#COMP_WORDS[]} -ge 2 ]]; then
+            case "${COMP_WORDS[2]}" in
                 QuickTime*)
                     _filedir '@(mp3|mpg|mpeg|avi|m4*|mov|alc)'
                     ;;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment