Permalink
Browse files

Fix bash completion to handle spaces and special characters

  • Loading branch information...
eugeneius committed Jan 8, 2012
1 parent cd05b5d commit 3bdf65dbaef06de2ea5164b9ffccd868ccfcb822
Showing with 11 additions and 17 deletions.
  1. +11 −17 completion/boom.bash
View
@@ -1,23 +1,17 @@
_boom_complete() {
- local cur prev lists
+ local cur prev lists curr_list items
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
+ curr_list=`eval echo "$prev"`
+ local IFS=$'\n'
- lists=`boom | awk '{print $1}'`
-
- case "${prev}" in
- boom)
- COMPREPLY=( $(compgen -W "${lists}" -- ${cur}) )
- return 0
- ;;
- *)
- for ((i = 0; i < ${#lists}; i++)); do
- local items=`boom $prev | awk '{print $1}' | sed -e 's/://'`
- COMPREPLY=( $(compgen -W "${items}" -- ${cur}))
- return 0
- done
- ;;
- esac
+ if [ $COMP_CWORD -eq 1 ]; then
+ lists=`boom | sed 's/^ \(.*\) ([0-9]\+)$/\1/'`
+ COMPREPLY=( $( compgen -W '${lists}' -- ${cur} ) )
+ elif [ $COMP_CWORD -eq 2 ]; then
+ items=`boom $curr_list | sed 's/^ \(.\{0,16\}\):.*$/\1/'`
+ COMPREPLY=( $( compgen -W '${items}' -- ${cur} ) )
+ fi
}
-complete -F _boom_complete boom
+complete -o filenames -F _boom_complete boom

0 comments on commit 3bdf65d

Please sign in to comment.