BashCompletion

From RdiffBackupWiki

Jump to: navigation, search
# # # # # # # # # # # # # # # # # # # # # # 
# A basic bash-completion for rdiff-backup
#
# Developed for 1.1.15 but can be "ported" to older version
# by modifying the lists of available options.
#
# This script supplies a completion of --long-options.
# It also tries to judge when to complete and not to complete.
#
# I will most likely upgrade this scripts with more advanced
# features such as the ability to recognize increments, etc.
#
# Feel free to send comments or suggestions to andreas@arrakis.se
# # # # # # # # # # # # # # # # # # # # # # 

_rdiff-backup()
{

   local cur prev longopts optnopath optwfarg needarg
   COMPREPLAY=()
   cur="${COMP_WORDS[COMP_CWORD]}"
   prev="${COMP_WORDS[COMP_CWORD-1]}"
   longopts="--backup-mode --calculate-average --carbonfile --check-destination-dir \
        --compare --compare-at-time --compare-full --compare-full-at-time \
        --compare-hash --compare-hash-at-time --create-full-path --current-time \
        --exclude --exclude-device-files --exclude-fifos --exclude-filelist \
        --exclude-filelist-stdin --exclude-globbing-filelist --exclude-globbing-filelist-stdin \
        --exclude-other-filesystems --exclude-regexp --exclude-special-files --exclude-sockets \
        --exclude-symbolic-links --exclude-if-present --force --group-mapping-file --include \
        --include-filelist --include-filelist-stdin --include-globbing-filelist \
        --include-globbing-filelist-stdin --include-regexp --include-special-files \
        --include-symbolic-links --list-at-time --list-changed-since --list-increments \
        --list-increment-sizes --max-file-size --min-file-size --never-drop-acls --no-acls \
        --no-carbonfile --no-compare-inode --no-compression --no-compression-regexp  --no-eas \
        --no-file-statistics --no-hard-links --null-separator --parsable-output  \
        --override-chars-to-quote --preserve-numerical-ids --print-statistics --restore-as-of \
        --remote-cmd --remote-schema --remote-tempdir --remove-older-than --restrict \
        --restrict-read-only --restrict-update-only --ssh-no-compression --tempdir \
        --terminal-verbosity --test-server --user-mapping-file --verbosity --verify \
        --verify-at-time --version"

   # These options wants an arguments which isn't a path
   optnopath="|--compare-at-time|--compare-full-at-time|--compare-hash-at-time|--current-time|
        |--exclude|--exclude-regexp|--include|--include-regexp|--list-at-time|--list-changed-since|
        |--max-file-size|--min-file-size|--no-compression-regexp|-r|--restore-as-of|--remote-cmd|
        |--remote-schema|--remove-older-than|--terminal-verbosity|--verbosity|--verify-at-time|
        |--version"


    # These options wants an arguments which is a path
    optwfarg="--exclude-filelist|--exclude-if-present|--group-mapping-file|--include-filelist|
        |--include-globbing-filelist|--remote-tempdir|--restrict|--restrict-read-only|
        |--restrict-update-only|--tempdir|--user-mapping-file"


    # Both of the above.
    needarg="${optnopath}|${optwfarg}"


   # Some switches needs some kind of argument. In those cases
   # don't autocomplete other switches
   if [[ ${cur} == -* ]] && [[ ${prev} != @($needarg) ]]; then
     COMPREPLY=( $(compgen -W "${longopts}" -- ${cur}) )
    return 0
   fi

   # In case the switch requires an argument which isn't a filename
   # then don't do any autocompleting.
   if [[ ${prev} == @($optnopath) ]]; then
    echo -en "\a"
    COMPREPLY=( '' )
    return 0
   fi

}
complete -F _rdiff-backup -o default rdiff-backup
Personal tools