asdf.fish 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. set -x asdf_data_dir (
  2. if test -n "$ASDF_DATA_DIR"; echo $ASDF_DATA_DIR;
  3. else; echo $HOME/.asdf; end)
  4. function __fish_asdf_needs_command
  5. set -l cmd (commandline -opc)
  6. if test (count $cmd) -eq 1
  7. return 0
  8. end
  9. return 1
  10. end
  11. function __fish_asdf_using_command -a current_command
  12. set -l cmd (commandline -opc)
  13. if test (count $cmd) -gt 1
  14. if test $current_command = $cmd[2]
  15. return 0
  16. end
  17. end
  18. return 1
  19. end
  20. function __fish_asdf_arg_number -a number
  21. set -l cmd (commandline -opc)
  22. test (count $cmd) -eq $number
  23. end
  24. function __fish_asdf_arg_at -a number
  25. set -l cmd (commandline -opc)
  26. echo $cmd[$number]
  27. end
  28. function __fish_asdf_list_versions -a plugin
  29. asdf list $plugin 2> /dev/null | sed -e 's/^[[:space:]]*//'
  30. end
  31. function __fish_asdf_list_all -a plugin
  32. asdf list-all $plugin 2> /dev/null
  33. end
  34. function __fish_asdf_plugin_list
  35. asdf plugin-list 2> /dev/null
  36. end
  37. function __fish_asdf_plugin_list_all
  38. asdf plugin-list-all 2> /dev/null
  39. end
  40. function __fish_asdf_list_shims
  41. ls $asdf_data_dir/shims
  42. end
  43. # update
  44. complete -f -c asdf -n '__fish_asdf_needs_command' -a update -d "Update asdf"
  45. complete -f -c asdf -n '__fish_asdf_using_command update; and __fish_asdf_arg_number 2' -l "head" -d "Updates to master HEAD"
  46. # plugin-add completion
  47. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-add -d "Add git repo as plugin"
  48. 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 }\')'
  49. 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 }\')'
  50. complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 4'
  51. # plugin-list completion
  52. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list -d "List installed plugins"
  53. # plugin-list-all completion
  54. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list-all -d "List all existing plugins"
  55. # plugin-remove completion
  56. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-remove -d "Remove plugin and package versions"
  57. complete -f -c asdf -n '__fish_asdf_using_command plugin-remove; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  58. # plugin-update completion
  59. complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-update -d "Update plugin"
  60. complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  61. complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a --all
  62. # install completion
  63. complete -f -c asdf -n '__fish_asdf_needs_command' -a install -d "Install a specific version of a package"
  64. complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  65. 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))'
  66. # uninstall completion
  67. complete -f -c asdf -n '__fish_asdf_needs_command' -a uninstall -d "Remove a specific version of a package"
  68. complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  69. 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))'
  70. # current completion
  71. complete -f -c asdf -n '__fish_asdf_needs_command' -a current -d "Display version set or being used for package"
  72. complete -f -c asdf -n '__fish_asdf_using_command current; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  73. # where completion
  74. complete -f -c asdf -n '__fish_asdf_needs_command' -a where -d "Display install path for an installed version"
  75. complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  76. 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))'
  77. # which completion
  78. complete -f -c asdf -n '__fish_asdf_needs_command' -a which -d "Display executable path for a command"
  79. complete -f -c asdf -n '__fish_asdf_using_command which; and __fish_asdf_arg_number 2' -a '(__fish_asdf_list_shims)'
  80. # latest completion
  81. complete -f -c asdf -n '__fish_asdf_needs_command' -a latest -d "Show latest stable version of a package"
  82. complete -f -c asdf -n '__fish_asdf_using_command latest; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  83. # list completion
  84. complete -f -c asdf -n '__fish_asdf_needs_command' -a list -d "List installed versions of a package"
  85. complete -f -c asdf -n '__fish_asdf_using_command list; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  86. # list-all completion
  87. complete -f -c asdf -n '__fish_asdf_needs_command' -a list-all -d "List all versions of a package"
  88. complete -f -c asdf -n '__fish_asdf_using_command list-all; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  89. # reshim completion
  90. complete -f -c asdf -n '__fish_asdf_needs_command' -a reshim -d "Recreate shims for version of a package"
  91. complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  92. 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))'
  93. # local completion
  94. complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
  95. complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  96. 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'
  97. # global completion
  98. complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
  99. complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  100. 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'
  101. # shell completion
  102. complete -f -c asdf -n '__fish_asdf_needs_command' -a shell -d "Set version for a plugin in current shell session"
  103. complete -f -c asdf -n '__fish_asdf_using_command shell; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
  104. complete -f -c asdf -n '__fish_asdf_using_command shell; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
  105. # misc
  106. complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"
  107. complete -f -c asdf -n '__fish_asdf_needs_command' -l "version" -d "Displays asdf version"