update-from-upstream.zsh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env zsh
  2. #
  3. # update-from-upstream.zsh
  4. #
  5. # This script updates the Oh My Zsh version of the zsh-history-substring-search
  6. # plugin from the independent upstream repo. This is to be run by OMZ developers
  7. # when they want to pull in new changes from upstream to OMZ. It is not run
  8. # during normal use of the plugin.
  9. #
  10. # The official upstream repo is zsh-users/zsh-history-substring-search
  11. # https://github.com/zsh-users/zsh-history-substring-search
  12. #
  13. # This is a zsh script, not a function. Call it with `zsh update-from-upstream.zsh`
  14. # from the command line, running it from within the plugin directory.
  15. #
  16. # You can set the environment variable REPO_PATH to point it at an upstream
  17. # repo you have already prepared. Otherwise, it will do a clean checkout of
  18. # upstream's HEAD to a temporary local repo and use that.
  19. # Just bail on any error so we don't have to do extra checking.
  20. # This is a developer-use script, so terse output like that should
  21. # be fine.
  22. set -e
  23. UPSTREAM_BASE=zsh-history-substring-search
  24. UPSTREAM_REPO=zsh-users/$UPSTREAM_BASE
  25. need_repo_cleanup=false
  26. upstream_github_url="https://github.com/$UPSTREAM_REPO"
  27. if [[ -z "$UPSTREAM_REPO_PATH" ]]; then
  28. # Do a clean checkout
  29. my_tempdir=$(mktemp -d -t omz-update-histsubstrsrch)
  30. UPSTREAM_REPO_PATH="$my_tempdir/$UPSTREAM_BASE"
  31. git clone "$upstream_github_url" "$UPSTREAM_REPO_PATH"
  32. need_repo_cleanup=true
  33. print "Checked out upstream repo to $UPSTREAM_REPO_PATH"
  34. else
  35. print "Using existing zsh-history-substring-search repo at $UPSTREAM_REPO_PATH"
  36. fi
  37. upstream="$UPSTREAM_REPO_PATH"
  38. # Figure out what we're pulling in
  39. upstream_sha=$(cd $upstream && git rev-parse HEAD)
  40. upstream_commit_date=$(cd $upstream && git log -1 --pretty=format:%ci)
  41. print "upstream SHA: $upstream_sha"
  42. print "upstream commit date: $upstream_commit_date"
  43. print
  44. # Copy the files over, using the OMZ plugin's names where needed
  45. cp -v "$upstream"/* .
  46. mv zsh-history-substring-search.plugin.zsh history-substring-search.plugin.zsh
  47. mv zsh-history-substring-search.zsh history-substring-search.zsh
  48. if [[ $need_repo_cleanup == true ]]; then
  49. print "Removing temporary repo at $my_tempdir"
  50. rm -rf "$my_tempdir"
  51. fi
  52. # Do OMZ-specific edits
  53. print
  54. print "Updating files with OMZ-specific stuff"
  55. # Tack OMZ-specific notes on to readme
  56. thin_line="------------------------------------------------------------------------------"
  57. cat >> README.md <<EOF
  58. $thin_line
  59. Oh My Zsh Notes
  60. $thin_line
  61. This is Oh My Zsh's repackaging of zsh-history-substring-search as an OMZ module
  62. inside the Oh My Zsh distribution.
  63. The upstream repo, $UPSTREAM_REPO, can be found on GitHub at $upstream_github_url.
  64. This downstream copy was last updated from the following upstream commit:
  65. SHA: $upstream_sha
  66. Commit date: $upstream_commit_date
  67. Everything above this section is a copy of the original upstream's README, so things
  68. may differ slightly when you're using this inside OMZ. In particular, you do not
  69. need to set up key bindings yourself in \`~/.zshrc\`; the OMZ plugin does that for
  70. you.
  71. EOF
  72. print
  73. print "Done OK"