jira.plugin.zsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # To use: add a .jira-url file in the base of your project
  2. # You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory
  3. # .jira-url in the current directory takes precedence
  4. #
  5. # If you use Rapid Board, set:
  6. #JIRA_RAPID_BOARD="true"
  7. # in you .zshrc
  8. #
  9. # Setup: cd to/my/project
  10. # echo "https://name.jira.com" >> .jira-url
  11. # Usage: jira # opens a new issue
  12. # jira ABC-123 # Opens an existing issue
  13. open_jira_issue () {
  14. local open_cmd
  15. if [[ $(uname -s) == 'Darwin' ]]; then
  16. open_cmd='open'
  17. else
  18. open_cmd='xdg-open'
  19. fi
  20. if [ -f .jira-url ]; then
  21. jira_url=$(cat .jira-url)
  22. elif [ -f ~/.jira-url ]; then
  23. jira_url=$(cat ~/.jira-url)
  24. elif [[ "x$JIRA_URL" != "x" ]]; then
  25. jira_url=$JIRA_URL
  26. else
  27. echo "JIRA url is not specified anywhere."
  28. return 0
  29. fi
  30. if [ -f .jira-prefix ]; then
  31. jira_prefix=$(cat .jira-prefix)
  32. elif [ -f ~/.jira-prefix ]; then
  33. jira_prefix=$(cat ~/.jira-prefix)
  34. else
  35. jira_prefix=""
  36. fi
  37. if [ -z "$1" ]; then
  38. echo "Opening new issue"
  39. $open_cmd "$jira_url/secure/CreateIssue!default.jspa"
  40. else
  41. echo "Opening issue #$1"
  42. if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
  43. $open_cmd "$jira_url/issues/$jira_prefix$1"
  44. else
  45. $open_cmd "$jira_url/browse/$jira_prefix$1"
  46. fi
  47. fi
  48. }
  49. alias jira='open_jira_issue'