I have a bash script that uses hub
to create pull-requests
easily. In bash it works fine, I just type gpr <base_branch>
and does the logic in the code.
# git pr
function gpr() {
# exit if no base branch supplied
if [[ ! $1 ]]; then
echo "No base branch supplied. Exiting"
return
fi
if [[ ! $2 ]]; then
echo "Creating pull-request"
echo "No pull-request message set."
read -p "Do you want to use the last commit message as pull-request message. Y or N? " choice
if [[ $choice =~ ^[Yy]$ ]]; then
# Use last commit message
COMMIT=$(git log -1 HEAD --pretty=format:%s)
echo "Using last commit message: $COMMIT"
MESSAGE="-m '$COMMIT'"
else
# Use own message
read -p "Enter message: " message
MESSAGE=-"m '$message'"
fi
fi
COMMAND="hub pull-request -b $1 $MESSAGE"
echo "Creating pull-request against $1 branch with message: $MESSAGE"
eval $COMMAND
echo "Pull-request created successfully"
}
Which in the end will result to hub pull-request -b <base_branch> -m <pull-request message or last commit message>
But how do I convert this to zsh
?
I tried pasting the code to .zshrc
but it seems to be not working. I get the following when running gpr <base_branch>
gpr develop
Creating pull-request
No pull-request message set.
gpr:read:10: -p: no coprocess
gpr:read:18: -p: no coprocess
Creating pull-request against develop branch with message: -m ''
And vim appears
In bash the process goes like this
gpr develop
Creating pull-request
No pull-request message set.
Do you want to use the last commit message as pull-request message. Y or N? y
Using last commit message: [UIUX-x] Commit message
Creating pull-request against develop branch with message: -m '[UIUX-x] Commit message'
https://github.com/<author>/<repo>/pull/<num>
Pull-request created successfully
~/bin/
or whatever (just set yourPATH
right) with a shebang pointing tobash
?wsl
so it's easier for me to just add my own function tozsh
.gpr
without lines:function ...
and the last}
. (2) Make the very first line a shebang:#!/bin/bash
. (3) Make the file executable:chmod +x gpr
. (4) Move the file to~/bin
directory. (5) Add~/bin
path toPATH
unless it's already there. Thengpr
will be handled bybash
even inzsh
. This is not an answer; it may solve your problem but it doesn't answer the question.