dotnet.plugin.zsh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # --------------------------------------------------------------------- #
  2. # Aliases and Completions for .NET Core (https://dotnet.microsoft.com/) #
  3. # Author: Shaun Tabone (https://github.com/xontab) #
  4. # --------------------------------------------------------------------- #
  5. # Helper function to cache and load completions
  6. local cache_base_path="${ZSH_CACHE_DIR}/dotnet_"
  7. _dotnet_cache_completion() {
  8. local cache="${cache_base_path}$(echo $1)_completion"
  9. if [[ ! -f $cache ]]; then
  10. $2 $cache
  11. fi
  12. [[ -f $cache ]] && cat $cache
  13. }
  14. _dotnet_cache_completion_cleanup() {
  15. local cache="${cache_base_path}$(echo $1)_completion"
  16. rm -f $cache
  17. }
  18. # --------------------------------------------------------------------- #
  19. # dotnet new #
  20. # ALIAS: dn #
  21. # --------------------------------------------------------------------- #
  22. _dotnet_new_completion() {
  23. if [ $commands[dotnet] ]; then
  24. dotnet new -l | tail -n +21 | sed 's/ \+/:/g' | cut -d : -f 2 >$1
  25. fi
  26. }
  27. _dotnet_new_completion_cached() {
  28. _dotnet_cache_completion 'new' _dotnet_new_completion
  29. }
  30. _dotnet_cache_completion_cleanup 'new'
  31. alias dn='dotnet new'
  32. # --------------------------------------------------------------------- #
  33. # dotnet #
  34. # --------------------------------------------------------------------- #
  35. _dotnet() {
  36. if [ $CURRENT -eq 2 ]; then
  37. _arguments \
  38. '--diagnostics[Enable diagnostic output.]' \
  39. '--help[Show command line help.]' \
  40. '--info[Display .NET Core information.]' \
  41. '--list-runtimes[Display the installed runtimes.]' \
  42. '--list-sdks[Display the installed SDKs.]' \
  43. '--version[Display .NET Core SDK version in use.]'
  44. _values \
  45. 'add[Add a package or reference to a .NET project.]' \
  46. 'build[Build a .NET project.]' \
  47. 'build-server[Interact with servers started by a build.]' \
  48. 'clean[Clean build outputs of a .NET project.]' \
  49. 'help[Show command line help.]' \
  50. 'list[List project references of a .NET project.]' \
  51. 'msbuild[Run Microsoft Build Engine (MSBuild) commands.]' \
  52. 'new[Create a new .NET project or file.]' \
  53. 'nuget[Provides additional NuGet commands.]' \
  54. 'pack[Create a NuGet package.]' \
  55. 'publish[Publish a .NET project for deployment.]' \
  56. 'remove[Remove a package or reference from a .NET project.]' \
  57. 'restore[Restore dependencies specified in a .NET project.]' \
  58. 'run[Build and run a .NET project output.]' \
  59. 'sln[Modify Visual Studio solution files.]' \
  60. 'store[Store the specified assemblies in the runtime package store.]' \
  61. 'test[Run unit tests using the test runner specified in a .NET project.]' \
  62. 'tool[Install or manage tools that extend the .NET experience.]' \
  63. 'vstest[Run Microsoft Test Engine (VSTest) commands.]' \
  64. 'dev-certs[Create and manage development certificates.]' \
  65. 'fsi[Start F# Interactive / execute F# scripts.]' \
  66. 'sql-cache[SQL Server cache command-line tools.]' \
  67. 'user-secrets[Manage development user secrets.]' \
  68. 'watch[Start a file watcher that runs a command when files change.]'
  69. return
  70. fi
  71. if [ $CURRENT -eq 3 ]; then
  72. case ${words[2]} in
  73. "new")
  74. compadd -X ".NET Installed Templates" $(_dotnet_new_completion_cached)
  75. return
  76. ;;
  77. "sln")
  78. _values \
  79. 'add[Add one or more projects to a solution file.]' \
  80. 'list[List all projects in a solution file.]' \
  81. 'remove[Remove one or more projects from a solution file.]'
  82. return
  83. ;;
  84. "nuget")
  85. _values \
  86. 'delete[Deletes a package from the server.]' \
  87. 'locals[Clears or lists local NuGet resources such as http requests cache, packages folder, plugin operations cache or machine-wide global packages folder.]' \
  88. 'push[Pushes a package to the server and publishes it.]'
  89. return
  90. ;;
  91. esac
  92. fi
  93. _arguments '*::arguments: _normal'
  94. }
  95. compdef _dotnet dotnet
  96. # --------------------------------------------------------------------- #
  97. # Other Aliases #
  98. # --------------------------------------------------------------------- #
  99. alias dr='dotnet run'
  100. alias dt='dotnet test'
  101. alias dw='dotnet watch'
  102. alias dwr='dotnet watch run'
  103. alias ds='dotnet sln'
  104. alias da='dotnet add'
  105. alias dp='dotnet pack'
  106. alias dng='dotnet nuget'