d7e6ba0b66fd65c71e9e3d4a4a5216dfde141944

Author
Andrew Janke <andrew@apjanke.net>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

history-substring-search: add a script to automatically update OMZ from the upstream repo

Diff

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