3 # update-from-upstream.zsh
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.
10 # The official upstream repo is zsh-users/zsh-history-substring-search
11 # https://github.com/zsh-users/zsh-history-substring-search
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.
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.
21 # Just bail on any error so we don't have to do extra checking.
22 # This is a developer-use script, so terse output like that should
27 upstream_basename=zsh-history-substring-search
28 plugin_basename=history-substring-search
29 UPSTREAM_REPO=zsh-users/$upstream_basename
30 need_repo_cleanup=false
31 upstream_github_url="https://github.com/$UPSTREAM_REPO"
33 if [[ -z "$UPSTREAM_REPO_PATH" ]]; then
35 my_tempdir=$(mktemp -d -t omz-update-histsubstrsrch)
36 UPSTREAM_REPO_PATH="$my_tempdir/$upstream_basename"
37 git clone "$upstream_github_url" "$UPSTREAM_REPO_PATH"
38 need_repo_cleanup=true
39 print "Checked out upstream repo to $UPSTREAM_REPO_PATH"
41 print "Using existing $upstream_basename repo at $UPSTREAM_REPO_PATH"
44 upstream="$UPSTREAM_REPO_PATH"
46 # Figure out what we're pulling in
47 upstream_sha=$(cd $upstream && git rev-parse HEAD)
48 upstream_commit_date=$(cd $upstream && git log -1 --pretty=format:%ci)
49 upstream_just_date=${${=upstream_commit_date}[1]}
50 print "upstream SHA: $upstream_sha"
51 print "upstream commit time: $upstream_commit_date"
52 print "upstream commit date: $upstream_just_date"
55 # Copy the files over, using the OMZ plugin's names where needed
57 mv -v zsh-history-substring-search.zsh $plugin_basename.zsh
58 mv -v zsh-history-substring-search.plugin.zsh $plugin_basename.plugin.zsh
60 if [[ $need_repo_cleanup == true ]]; then
61 print "Removing temporary repo at $my_tempdir"
65 # Do OMZ-specific edits
68 print "Updating files with OMZ-specific stuff"
71 # OMZ binds the keys as part of the plugin loading
73 cat >> $plugin_basename.plugin.zsh <<EOF
76 # Bind terminal-specific up and down keys
78 if [[ -n "\$terminfo[kcuu1]" ]]; then
79 bindkey -M emacs "\$terminfo[kcuu1]" history-substring-search-up
80 bindkey -M viins "\$terminfo[kcuu1]" history-substring-search-up
82 if [[ -n "\$terminfo[kcud1]" ]]; then
83 bindkey -M emacs "\$terminfo[kcud1]" history-substring-search-down
84 bindkey -M viins "\$terminfo[kcud1]" history-substring-search-down
89 # Tack OMZ-specific notes on to readme
91 thin_line="------------------------------------------------------------------------------"
92 cat >> README.md <<EOF
95 Oh My Zsh Distribution Notes
98 What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search
99 as an OMZ module inside the Oh My Zsh distribution.
101 The upstream repo, $UPSTREAM_REPO, can be found on GitHub at
102 $upstream_github_url.
104 This downstream copy was last updated from the following upstream commit:
107 Commit date: $upstream_commit_date
109 Everything above this section is a copy of the original upstream's README, so things
110 may differ slightly when you're using this inside OMZ. In particular, you do not
111 need to set up key bindings for the up and down arrows yourself in \`~/.zshrc\`; the OMZ
112 plugin does that for you. You may still want to set up additional emacs- or vi-specific
113 bindings as mentioned above.
117 # Announce success and generate git commit messages
122 Now you can check the results and commit like this:
125 git commit -m "history-substring-search: update to upstream version $upstream_just_date" \\
126 -m "Updates OMZ's copy to commit $upstream_sha from $UPSTREAM_REPO"