Monday, May 2, 2016

Create your own Autocompletion

# complete -W "`find ${NMWS_HOME}/repository/ -maxdepth 1 -type d \
-printf '%f\n' | grep -v repository`" make PACKAGE=
 
# complete -W “home data images baw” syncfiles


001 #!/bin/bash
002
003 oocalc_complete() {
004   local ext="ods"
005   local word="$2"
006
007   # Standard completion (filename-completion)
008   local i=0 line
009   declare -a list
010   while read line; do
011     list[i++]="$line"
012   done < <(compgen -f -- "$word")
013
014   # Filter: only filenames with the correct extension
015   local w e
016   for w in "${list[@]}"; do
017     if [ -d "$w" ]; then
018       continue
019     else
020       e="${w##*.}"
021       if [ "$e" = "$ext" ]; then
022         COMPREPLY[i++]="$w"
023       fi
024     fi
025   done
026 }
027
028 complete -o plusdirs -F oocalc_complete oocalc

http://www.linux-magazine.com/Online/Features/Bash-Tips-Autocompletion

No comments:

Blog Archive