update-from-upstream.zsh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_basename=zsh-history-substring-search
  24. plugin_basename=history-substring-search
  25. UPSTREAM_REPO=zsh-users/$upstream_basename
  26. need_repo_cleanup=false
  27. upstream_github_url="https://github.com/$UPSTREAM_REPO"
  28. if [[ -z "$UPSTREAM_REPO_PATH" ]]; then
  29. # Do a clean checkout
  30. my_tempdir=$(mktemp -d -t omz-update-histsubstrsrch)
  31. UPSTREAM_REPO_PATH="$my_tempdir/$upstream_basename"
  32. git clone "$upstream_github_url" "$UPSTREAM_REPO_PATH"
  33. need_repo_cleanup=true
  34. print "Checked out upstream repo to $UPSTREAM_REPO_PATH"
  35. else
  36. print "Using existing $upstream_basename repo at $UPSTREAM_REPO_PATH"
  37. fi
  38. upstream="$UPSTREAM_REPO_PATH"
  39. # Figure out what we're pulling in
  40. upstream_sha=$(cd $upstream && git rev-parse HEAD)
  41. upstream_commit_date=$(cd $upstream && git log -1 --pretty=format:%ci)
  42. upstream_just_date=${${=upstream_commit_date}[1]}
  43. print "upstream SHA: $upstream_sha"
  44. print "upstream commit time: $upstream_commit_date"
  45. print "upstream commit date: $upstream_just_date"
  46. print
  47. # Copy the files over, using the OMZ plugin's names where needed
  48. cp -v "$upstream"/* .
  49. mv -v zsh-history-substring-search.zsh $plugin_basename.zsh
  50. mv -v zsh-history-substring-search.plugin.zsh $plugin_basename.plugin.zsh
  51. if [[ $need_repo_cleanup == true ]]; then
  52. print "Removing temporary repo at $my_tempdir"
  53. rm -rf "$my_tempdir"
  54. fi
  55. # Do OMZ-specific edits
  56. print
  57. print "Updating files with OMZ-specific stuff"
  58. print
  59. # OMZ binds the keys as part of the plugin loading
  60. cat >> $plugin_basename.plugin.zsh <<EOF
  61. # Bind terminal-specific up and down keys
  62. if [[ -n "\$terminfo[kcuu1]" ]]; then
  63. bindkey -M emacs "\$terminfo[kcuu1]" history-substring-search-up
  64. bindkey -M viins "\$terminfo[kcuu1]" history-substring-search-up
  65. fi
  66. if [[ -n "\$terminfo[kcud1]" ]]; then
  67. bindkey -M emacs "\$terminfo[kcud1]" history-substring-search-down
  68. bindkey -M viins "\$terminfo[kcud1]" history-substring-search-down
  69. fi
  70. EOF
  71. # Tack OMZ-specific notes on to readme
  72. thin_line="------------------------------------------------------------------------------"
  73. cat >> README.md <<EOF
  74. $thin_line
  75. Oh My Zsh Distribution Notes
  76. $thin_line
  77. What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search
  78. as an OMZ module inside the Oh My Zsh distribution.
  79. The upstream repo, $UPSTREAM_REPO, can be found on GitHub at
  80. $upstream_github_url.
  81. This downstream copy was last updated from the following upstream commit:
  82. SHA: $upstream_sha
  83. Commit date: $upstream_commit_date
  84. Everything above this section is a copy of the original upstream's README, so things
  85. may differ slightly when you're using this inside OMZ. In particular, you do not
  86. need to set up key bindings for the up and down arrows yourself in \`~/.zshrc\`; the OMZ
  87. plugin does that for you. You may still want to set up additional emacs- or vi-specific
  88. bindings as mentioned above.
  89. EOF
  90. # Announce success and generate git commit messages
  91. cat <<EOF
  92. Done OK
  93. Now you can check the results and commit like this:
  94. git add *
  95. git commit -m "history-substring-search: update to upstream version $upstream_just_date" \\
  96. -m "Updates OMZ's copy to commit $upstream_sha from $UPSTREAM_REPO"
  97. EOF