My personal dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_diana 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #compdef diana
  2. # ------------------------------------------------------------------------------
  3. # Copyright (c) 2016 Github zsh-users - http://github.com/zsh-users
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # * Neither the name of the zsh-users nor the
  14. # names of its contributors may be used to endorse or promote products
  15. # derived from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # ------------------------------------------------------------------------------
  28. # Description
  29. # -----------
  30. #
  31. # Completion script for Diana a command line interface to the aria2 daemon. (https://github.com/baskerville/diana).
  32. #
  33. # ------------------------------------------------------------------------------
  34. # Authors
  35. # -------
  36. #
  37. # * Jindřich Pilař (https://github.com/JindrichPilar)
  38. #
  39. # ------------------------------------------------------------------------------
  40. local GIDs PGIDs
  41. _diana_load_gids() {
  42. GIDs=()
  43. local downloads hashArr fileName
  44. downloads=$(diana list | cut -d' ' -f1)
  45. if [ ${#downloads} -eq "0" ]; then
  46. return
  47. fi
  48. hashArr=("${(f)$(echo "$downloads")}")
  49. for ((i=1; i<=${#hashArr[@]}; i++)); do
  50. fileName=$(diana files $hashArr[i] | grep "[X]" | rev | cut -d'/' -f1 | rev);
  51. GIDs+=("$hashArr[i]:$fileName");
  52. done
  53. }
  54. _diana_load_paused_gids() {
  55. PGIDs=()
  56. local downloads hashArr fileName
  57. downloads=$(diana paused | cut -d' ' -f1)
  58. if [ ${#downloads} -eq "0" ]; then
  59. return
  60. fi
  61. hashArr=("${(f)$(echo "$downloads")}")
  62. for ((i=1; i<=${#hashArr[@]}; i++)); do
  63. fileName=$(diana files $hashArr[i] | grep "[X]" | rev | cut -d'/' -f1 | rev);
  64. PGIDs+=("$hashArr[i]:$fileName");
  65. done
  66. }
  67. _diana_command_arguments() {
  68. case $words[1] in
  69. (remove)
  70. _diana_load_gids
  71. _describe -t output 'Downloads to delete' GIDs
  72. ;;
  73. (info)
  74. _diana_load_gids
  75. _describe -t output 'Downloads to get info' GIDs
  76. ;;
  77. (files)
  78. _diana_load_gids
  79. _describe -t output 'Get files for downloads' GIDs
  80. ;;
  81. (forcerm)
  82. _diana_load_gids
  83. _describe -t output 'Downloads to delete' GIDs
  84. ;;
  85. (pause)
  86. _diana_load_gids
  87. _describe -t output 'Downloads to pause' GIDs
  88. ;;
  89. (resume)
  90. _diana_load_paused_gids
  91. _describe -t output 'Downloads to resume' PGIDs
  92. ;;
  93. (preview)
  94. _diana_load_gids
  95. _describe -t output 'Downloads to preview' GIDs
  96. ;;
  97. esac
  98. }
  99. _diana() {
  100. local -a commands
  101. commands=(
  102. "list:Output the list of active downloads."
  103. "paused:Output the list of paused downloads."
  104. "stopped:Output the list of stopped downloads."
  105. "info:Output informations regarding the given GIDs."
  106. "files:Output the files owned by the downloads corresponding to the given GIDs."
  107. "errors:Output the list of errors."
  108. "stats:Output download bandwidth statistics."
  109. "add:Download the given items (local or remote URLs to torrents, etc.)."
  110. "remove:Remove the downloads corresponding to the given GIDs."
  111. "forcerm:Forcibly remove the downloads corresponding to the given GIDs."
  112. "pause:Pause the downloads corresponding to the given GIDs."
  113. "resume:Resume the downloads corresponding to the given GIDs."
  114. "preview:Preview all the files from all the downloads corresponding to the given GIDs."
  115. "sleep:Pause all the active downloads."
  116. "wake:Resume all the paused downloads."
  117. "purge:Clear the list of stopped downloads and errors."
  118. "clean:Stop seeding completed downloads."
  119. )
  120. _arguments -C \
  121. '1:cmd:->cmds' \
  122. '*:: :->args' \
  123. case "$state" in
  124. (cmds)
  125. _describe -t commands 'commands' commands
  126. ;;
  127. (*)
  128. _diana_command_arguments
  129. ;;
  130. esac
  131. }
  132. _diana