asdf.fish 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. function __fish_asdf_needs_command
  2. set -l cmd (commandline -opc)
  3. if test (count $cmd) -eq 1
  4. return 0
  5. end
  6. return 1
  7. end
  8. function __fish_asdf_using_command -a current_command
  9. set -l cmd (commandline -opc)
  10. if test (count $cmd) -gt 1
  11. if test $current_command = $cmd[2]
  12. return 0
  13. end
  14. end
  15. return 1
  16. end
  17. function __fish_asdf_arg_number -a number
  18. set -l cmd (commandline -opc)
  19. test (count $cmd) -eq $number
  20. end
  21. function __fish_asdf_arg_at -a number
  22. set -l cmd (commandline -opc)
  23. echo $cmd[$number]
  24. end
  25. function __fish_asdf_list_versions -a plugin
  26. asdf list $plugin 2> /dev/null | sed -e 's/^\s*//'
  27. end
  28. function __fish_asdf_list_all -a plugin
  29. asdf list-all $plugin 2> /dev/null
  30. end
  31. function __fish_asdf_plugin_list
  32. asdf plugin-list 2> /dev/null
  33. end
  34. function __fish_asdf_plugin_list_all
  35. asdf plugin-list-all 2> /dev/null
  36. end
  37. # plugin-add completion
  38. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-add -d "Add git repo as plugin"
  39. complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list_all | grep -v \'*\' | awk \'{ print $1 }\')'
  40. complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 3' -a '(__fish_asdf_plugin_list_all | grep (__fish_asdf_arg_at 3) | awk \'{ print $2 }\')'
  41. complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 4'
  42. # plugin-list completion
  43. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list -d "List installed plugins"
  44. # plugin-list-all completion
  45. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list-all -d "List all existing plugins"
  46. # plugin-remove completion
  47. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-remove -d "Remove plugin and package versions"
  48. complete -f -c asdf -n '__fish_asdf_using_command plugin-remove; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  49. # plugin-update completion
  50. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-update -d "Update plugin"
  51. complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  52. complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a --all
  53. # install completion
  54. complete -f -c asdf -n '__fish_asdf_needs_command' -a install -d "Install a specific version of a package"
  55. complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  56. complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_all (__fish_asdf_arg_at 3))'
  57. # uninstall completion
  58. complete -f -c asdf -n '__fish_asdf_needs_command' -a uninstall -d "Remove a specific version of a package"
  59. complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  60. complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
  61. # current completion
  62. complete -f -c asdf -n '__fish_asdf_needs_command' -a current -d "Display version set or being used for package"
  63. complete -f -c asdf -n '__fish_asdf_using_command current; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  64. # where completion
  65. complete -f -c asdf -n '__fish_asdf_needs_command' -a where -d "Display install path for an installed version"
  66. complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  67. complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
  68. # list completion
  69. complete -f -c asdf -n '__fish_asdf_needs_command' -a list -d "List installed versions of a package"
  70. complete -f -c asdf -n '__fish_asdf_using_command list; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  71. # list-all completion
  72. complete -f -c asdf -n '__fish_asdf_needs_command' -a list-all -d "List all versions of a package"
  73. complete -f -c asdf -n '__fish_asdf_using_command list-all; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  74. # reshim completion
  75. complete -f -c asdf -n '__fish_asdf_needs_command' -a reshim -d "Recreate shims for version of a package"
  76. complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  77. complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
  78. # local completion
  79. complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
  80. complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  81. complete -f -c asdf -n '__fish_asdf_using_command local; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
  82. # global completion
  83. complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
  84. complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  85. complete -f -c asdf -n '__fish_asdf_using_command global; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
  86. # misc
  87. complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"
  88. complete -f -c asdf -n '__fish_asdf_needs_command' -l "version" -d "Displays asdf version"