]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/history-substring-search/update-from-upstream.zsh
81e1942a508e3358c63354be658c56ef0ba2c2ef
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / history-substring-search / update-from-upstream.zsh
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
20
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
23 # be fine.
24 set -e
25
26
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"
32
33 if [[ -z "$UPSTREAM_REPO_PATH" ]]; then
34   # Do a clean checkout
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"
40 else
41         print "Using existing $upstream_basename repo at $UPSTREAM_REPO_PATH"
42 fi
43
44 upstream="$UPSTREAM_REPO_PATH"
45
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"
53 print
54
55 # Copy the files over, using the OMZ plugin's names where needed
56 cp -v "$upstream"/* .
57 mv -v zsh-history-substring-search.zsh $plugin_basename.zsh
58 mv -v zsh-history-substring-search.plugin.zsh $plugin_basename.plugin.zsh
59
60 if [[ $need_repo_cleanup == true ]]; then
61         print "Removing temporary repo at $my_tempdir"
62         rm -rf "$my_tempdir"
63 fi
64
65 # Do OMZ-specific edits
66
67 print
68 print "Updating files with OMZ-specific stuff"
69 print
70
71 # OMZ binds the keys as part of the plugin loading
72
73 cat >> $plugin_basename.plugin.zsh <<EOF
74
75
76 # Bind terminal-specific up and down keys
77
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
81 fi
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
85 fi
86
87 EOF
88
89 # Tack OMZ-specific notes on to readme
90
91 thin_line="------------------------------------------------------------------------------"
92 cat >> README.md <<EOF
93
94 $thin_line
95 Oh My Zsh Distribution Notes
96 $thin_line
97
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.
100
101 The upstream repo, $UPSTREAM_REPO, can be found on GitHub at 
102 $upstream_github_url.
103
104 This downstream copy was last updated from the following upstream commit:
105
106   SHA:          $upstream_sha
107   Commit date:  $upstream_commit_date
108
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.
114
115 EOF
116
117 # Announce success and generate git commit messages
118
119 cat <<EOF
120 Done OK
121
122 Now you can check the results and commit like this:
123
124   git add *
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"
127
128 EOF
129