├── README.md ├── LICENSE └── open /README.md: -------------------------------------------------------------------------------- 1 | # open bash completion 2 | 3 | Bash completion for the Mac OS X open builtin. Completes options and 4 | application names (in `$HOME/Applications` and `/Applications`). 5 | 6 | ## Installation 7 | 8 | ### With Homebrew 9 | 10 | Install Homebrew per https://brew.sh/ 11 | 12 | ``` 13 | brew install open-completion 14 | ``` 15 | 16 | ### Without Homebrew 17 | 18 | Copy `open` into your `bash_completion.d` folder. 19 | 20 | ## Usage 21 | 22 | Type `open -a ` and tap tab a couple of times. 23 | 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright © 2015 Colin Kennedy 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the “Software”), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /open: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # bash completion file for the open built-in on OS X 4 | # 5 | 6 | if [[ $(uname) == Darwin ]]; then 7 | _open() { 8 | COMPREPLY=() 9 | local cur 10 | _get_comp_words_by_ref -n : cur 11 | 12 | local optcur="${COMP_WORDS[(( COMP_CWORD - 1 ))]} ${COMP_WORDS[COMP_CWORD]}" 13 | 14 | # Generate list of applications to autocomplete only when we match -a 15 | case "$optcur" in 16 | -a*) 17 | local applications 18 | applications="$( \ 19 | find "$HOME/Applications" {/System,}/Applications{/Utilities,} -maxdepth 2 -iname '*.app' 2>/dev/null \ 20 | | perl -ne 'if(/\/([^\/]+)\.app$/i) { print "$1\n" }')" 21 | 22 | local OLDIFS="$IFS" 23 | while IFS=$'\n' read -r line; do COMPREPLY+=("$line"); done < <(IFS=$'\n' compgen -W "$applications" -- "$cur") 24 | IFS="$OLDIFS" 25 | return 26 | ;; 27 | esac 28 | 29 | case "$cur" in 30 | --*) 31 | local dashdash_options 32 | dashdash_options="$( \ 33 | open -h 2>&1 \ 34 | | perl -ne 'if(/(--[a-zA-Z\-]+)/) { print "$1\n" }')" 35 | local OLDIFS="$IFS" 36 | while IFS=$'\n' read -r line; do COMPREPLY+=("$line"); done < <(IFS=$'\n' compgen -W "$dashdash_options" -- "$cur") 37 | IFS="$OLDIFS" 38 | ;; 39 | -*) 40 | local dash_options 41 | dash_options="$( \ 42 | open -h 2>&1 \ 43 | | perl -ne 'if(/^\s+(-[a-zA-Z])/) { print "$1\n" }')" 44 | local OLDIFS="$IFS" 45 | while IFS=$'\n' read -r line; do COMPREPLY+=("$line"); done < <(IFS=$'\n' compgen -W "$dash_options" -- "$cur") 46 | IFS="$OLDIFS" 47 | ;; 48 | *) 49 | local OLDIFS="$IFS" 50 | while IFS=$'\n' read -r line; do COMPREPLY+=("$line"); done < <(IFS=$'\n' compgen -o default -- "$cur") 51 | IFS="$OLDIFS" 52 | ;; 53 | esac 54 | 55 | return 56 | } 57 | 58 | complete -o filenames -F _open open 59 | fi 60 | --------------------------------------------------------------------------------