ducker.bash 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python3
  2. # Ducker - search with DuckDuckGo from the command line
  3. # Copyright (C) 2016-2017 Jorge Maldonado Ventura
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. _ducker() {
  15. COMPREPLY=()
  16. local IFS=$' \n'
  17. local cur=$2 prev=$3
  18. local -a opts opts_with_args
  19. opts=(
  20. -h --help
  21. --version
  22. -m --multiple-search
  23. -w --website-search
  24. -H --no-javascript
  25. -l --lite
  26. -i --image-search
  27. -v --video-search
  28. -x --exact
  29. -C --nocolor
  30. --noua
  31. --json
  32. --np --noprompt
  33. -d --debug
  34. --colors
  35. -t --time
  36. -c --reg
  37. --site
  38. -p --proxy
  39. -s --start
  40. -n --count
  41. )
  42. opts_with_args=(
  43. --colors
  44. -t --time
  45. -c --reg
  46. --site
  47. -p --proxy
  48. -s --start
  49. -n --count
  50. )
  51. # Do not complete non option names
  52. [[ $cur == -* ]] || return 1
  53. # Do not complete when the previous arg is an option expecting an argument
  54. for opt in "${opts_with_args[@]}"; do
  55. [[ $opt == $prev ]] && return 1
  56. done
  57. # Complete option names
  58. COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
  59. return 0
  60. }
  61. complete -F _ducker ducker