Skip to content

Instantly share code, notes, and snippets.

@CourteousCoder
Last active September 21, 2021 02:28
Show Gist options
  • Save CourteousCoder/1a99d495e9da2ce9ea50da2c9b67c234 to your computer and use it in GitHub Desktop.
Save CourteousCoder/1a99d495e9da2ce9ea50da2c9b67c234 to your computer and use it in GitHub Desktop.
Patch zplug locally with pull requests not yet approved
#!/usr/bin/env zsh
# Install zplug if not installed, and patch it locally by merging pull requests by id.
PULL_REQUEST_IDS="$@"
run_remote_zsh_script() {
local url="$1"
shift
curl -sL --proto-redir -all,https "$url" | zsh -s "$@"
}
prompt_zplug_install() {
if read -q "should_install?Should I try to install it there for you using the zplug_installer? "; then
echo
run_remote_zsh_script 'https://raw.githubusercontent.com/zplug/installer/master/installer.zsh'
else
echo "Please make sure \$ZPLUG_HOME points to a zplug installation that was cloned from github. Then run this script again."
exit 1
fi
}
patch_locally() {
local url='https://gist.githubusercontent.com/DanielSchetritt/5da5ab148d088ab4d8087bfb99875178/raw/ghpr-merge.zsh'
echo "Attempting to patch zplug using \`ZPLUG_HOME=$ZPLUG_HOME'"
run_remote_zsh_script "$url" "$ZPLUG_HOME" "$PULL_REQUEST_IDS"
local exit_code="$?"
[[ "$exit_code" -eq "0" ]] \
&& echo "Successfully patched local zplug installation with PRs \`$PULL_REQUEST_IDS'" \
&& echo "Don't forget to source ~/.zshrc or restart your terminal"
return "$exit_code"
}
patch_locally
exit_code="$?"
should_check_zplug_installation="1"
if (( exit_code = should_check_zplug_installation )) && [[ -n "$PULL_REQUESTS_IDS" ]]; then
echo "Could not find a zplug installation in \`$ZPLUG_HOME' that was cloned from github" \
&& install_zplug \
&& patch_locally
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment