From 835d695ed0b7d0e7656e6801a1f9ff140f0ce1b5 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Mon, 21 Aug 2023 08:35:09 +0100 Subject: [PATCH] feat(shell): add prr zsh plugin This will use my directory structure to get the project namespace and name for prr. This way we dont need to keep providing the extra info. --- .../core/files/oh-my-zsh/custom/prr.zsh | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 site-modules/core/files/oh-my-zsh/custom/prr.zsh diff --git a/site-modules/core/files/oh-my-zsh/custom/prr.zsh b/site-modules/core/files/oh-my-zsh/custom/prr.zsh new file mode 100644 index 0000000..08b18f7 --- /dev/null +++ b/site-modules/core/files/oh-my-zsh/custom/prr.zsh @@ -0,0 +1,22 @@ +# Gets the git project name "owner/repo" from the current directory. This uses +# the directory structure like the `GOPATH` this is aliased to `~s`. For +# example the directory would be `~/github.com/AdeAttwood/Dotfiles`, this would +# return `AdeAttwood/Dotfiles`. +function get_project() { + echo "$(basename "$(dirname "$PWD")")/$(basename "$PWD")" +} + +# Gets the PR number from the current git repo and branch. +function get_pr_number() { + gh pr view --json=number --jq='.number' +} + +alias prr-get='prr get "$(get_project)"/"$(get_pr_number)"' +alias prr-submit='prr submit "$(get_project)"/"$(get_pr_number)"' +alias prr-edit='$EDITOR ~/.local/share/prr/$(get_project)/$(get_pr_number).prr' + +function prr-review() { + gh pr checkout "$1" + prr-get + prr-edit +}