vim-plugin-add: fix url input
This commit is contained in:
parent
3121d1c844
commit
d2b5ccfe69
1 changed files with 60 additions and 34 deletions
94
vim-plugin-add.sh
Normal file → Executable file
94
vim-plugin-add.sh
Normal file → Executable file
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
# Given a to a link plugin on GitHub, add the plugin to nixpkgs
|
||||
# - Run from the `nixpkgs` repository
|
||||
# - Provide plugin names in the author/plugin format
|
||||
# Requires git and nix to be in the environment
|
||||
# Example usage:
|
||||
# vim-plugin-add.sh nvim-lua/plenary.nvim letieu/btw.nvim
|
||||
## Trying to figure out a dumb bug
|
||||
#!nix-shell --run bash -p bash
|
||||
#
|
||||
# exit
|
||||
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p git neovim vimPluginsUpdater
|
||||
|
||||
set -eu
|
||||
|
||||
|
@ -31,6 +32,7 @@ nix_test_build() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Error checking
|
||||
if [ $# -lt 1 ]; then
|
||||
err 'Please pass the plugins you want to add as arguments, like so:'
|
||||
err "$0 Zeioth/compiler.nvim jmbuhr/otter.nvim"
|
||||
|
@ -42,6 +44,7 @@ if ! git remote get-url origin | grep --silent -P 'nixpkgs.git$'; then
|
|||
fi
|
||||
if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
|
||||
msg 'WARNING: currently not on master branch!'
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
nixpkgs_dir="$(git rev-parse --show-toplevel)"
|
||||
|
@ -49,15 +52,20 @@ nixpkgs_vim_plugin_dir=pkgs/applications/editors/vim/plugins
|
|||
tmp_dir="$(mktemp -d)"
|
||||
tmp_generated_nix="$(mktemp)"
|
||||
tmp_ending_nix="$(mktemp)"
|
||||
urls=()
|
||||
pr_urls=()
|
||||
|
||||
for p; do
|
||||
msg "Adding $p"
|
||||
|
||||
# set basic variables
|
||||
domain=https://github.com
|
||||
if grep --silent -P '^http' <<< "$p"; then # support inputting urls
|
||||
domain="$(grep -Po '^http.*://[^/]+' <<< "$p")"
|
||||
p="$(grep -Po '[^/]+/[^/]+$' <<< "$p")"
|
||||
fi
|
||||
repo_url="$domain/$p"
|
||||
plugin_name="${p##*/}"
|
||||
plugin_author="${p%/*}"
|
||||
repo_url="https://github.com/$p"
|
||||
nixpkgs_plugin_name="$(tr . - <<< "$plugin_name")" # the plugin name, as nixpkgs will know it
|
||||
plugin_repo_tmp_dir="$tmp_dir/$plugin_name"
|
||||
|
||||
|
@ -76,8 +84,8 @@ for p; do
|
|||
rm -rf "$plugin_repo_tmp_dir"
|
||||
git checkout --quiet -b "$plugin_name"
|
||||
dbg "actually running the updater"
|
||||
# nix-shell -p vimPluginsUpdater --command "vim-plugins-updater add $p"
|
||||
vim-plugins-updater add "$p"
|
||||
nix run nixpkgs#vimPluginsUpdater -- add "$p"
|
||||
# vim-plugins-updater add "$p"
|
||||
|
||||
# Append the new plugin to generated.nix
|
||||
dbg "Writing generated.nix"
|
||||
|
@ -85,44 +93,62 @@ for p; do
|
|||
head -n -2 generated.nix > "$tmp_generated_nix"
|
||||
editor_start_line="$(wc -l "$tmp_generated_nix")"
|
||||
cat <<- EOF > "$tmp_ending_nix"
|
||||
$nixpkgs_plugin_name = buildVimPlugin {
|
||||
pname = "$nixpkgs_plugin_name";
|
||||
version = "$git_date_version";
|
||||
src = fetchFromGitHub {
|
||||
owner = "$plugin_author";
|
||||
repo = "$plugin_name";
|
||||
rev = "$git_rev_hash";
|
||||
sha256 = "$repo_hash";
|
||||
};
|
||||
meta.homepage = "$repo_url";
|
||||
};
|
||||
$nixpkgs_plugin_name = buildVimPlugin {
|
||||
pname = "$nixpkgs_plugin_name";
|
||||
version = "$git_date_version";
|
||||
src = fetchFromGitHub {
|
||||
owner = "$plugin_author";
|
||||
repo = "$plugin_name";
|
||||
rev = "$git_rev_hash";
|
||||
sha256 = "$repo_hash";
|
||||
};
|
||||
meta.homepage = "$repo_url";
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
EOF
|
||||
}
|
||||
EOF
|
||||
cat "$tmp_generated_nix" "$tmp_ending_nix" > generated.nix
|
||||
|
||||
first=true
|
||||
until nix_test_build "$nixpkgs_plugin_name" && ! $first; do
|
||||
if [ $first = true ]; then
|
||||
msg "Please make any needed changes and then exit to automatically commit continue."
|
||||
msg "Please make any needed changes and then exit to continue."
|
||||
msg "Such as adding dependencies to $nixpkgs_vim_plugin_dir/overrides.nix"
|
||||
msg "Exit to commit and push your changes"
|
||||
msg "Exit with a status code of 0 to test, commit, and push your changes"
|
||||
first=false
|
||||
fi
|
||||
|
||||
$SHELL
|
||||
until $SHELL; do
|
||||
ec=$?
|
||||
msg -n "Shell exited with code $ec. Do you want to stop? [y/N]"
|
||||
until [ $ec = 0 ]; do
|
||||
read -r
|
||||
case "$REPLY" in
|
||||
[y|Y])
|
||||
exit $ec
|
||||
;;
|
||||
[n|N])
|
||||
ec=0
|
||||
;;
|
||||
*)
|
||||
echo "Please answer y or n."
|
||||
ec=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
git commit -a --amend
|
||||
git push --set-upstream origin "$plugin_name" --force
|
||||
git switch -
|
||||
# shellcheck disable=SC2016
|
||||
pr_urls+=("https://$(git remote get-url origin | sed -r 's/^[^@]+@//g; s_:_/_g; s_\.git$__g')/pull/new/$plugin_name")
|
||||
echo
|
||||
done
|
||||
git commit -a --amend
|
||||
git push --set-upstream origin "$plugin_name" --force
|
||||
git switch -
|
||||
# shellcheck disable=SC2016
|
||||
urls+=("https://$(git remote get-url origin | sed -r 's/^[^@]+@//g; s_:_/_g; s_\.git$__g')/pull/new/$plugin_name")
|
||||
echo
|
||||
done
|
||||
|
||||
echo "Pull Request URLs:"
|
||||
for url in "${urls[@]}"; do
|
||||
for url in "${pr_urls[@]}"; do
|
||||
echo " - $url"
|
||||
done
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue