Skip to content

Instantly share code, notes, and snippets.

@aik099
Forked from mrflip/gist:7983
Last active December 10, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aik099/4482856 to your computer and use it in GitHub Desktop.
Save aik099/4482856 to your computer and use it in GitHub Desktop.
Bash completion for "open -a" command on Mac. Changes from original script: * no need to enclose app names, that have spaces in them (e.g. "Sublime Text 2") in double quotes to get auto-complete * app names lowercased for auto-complete, which allows to use "open -a subl" instead of "open -a Subl"
# http://woss.name/2005/09/06/bash-completion-for-mac-os-x-open/
if [ "`uname`" = "Darwin" ]; then
_open() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ "${prev}" = -a ]; then
local IFS=$'\n'
COMPREPLY=( $(
compgen -W "$(
/bin/ls -d1 /Applications/*/*.app /Applications/*.app | \
sed 's|^.*/\([^/]*\)\.app.*|\1|;s/\ /\\ /g' | \
sed 's/ /\\ /g' | \
awk '{ print tolower($0) }'
)" -- $cur)
)
return 0
fi
}
complete -F _open -o default open
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment