Improving the Pull Request from terminal

:  ~ 1 min read

Just a slight improvement for last post: sometimes I don't have the branch pushed on GitHub, so why not automate that too?

perform_pull_request() {
  branch="development"
  branch_to_push="$(parse_git_branch)"
  git push origin "$branch_to_push":"$branch_to_push"

  if [ -n "$1" ]; then
    branch=$1
  fi

  pr_url=$(hub pull-request -b "$branch" -m "$(formatted_git_branch)")

  if [ $? -eq 0 ]; then
    open "$pr_url"
  fi
}

I also found some nice helpers for easier color printing:

// A bit redundant to have both of them, but I like having extra stuff
// instead of not having something when I could use it.
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
reset_color=$(tput sgr0)

black() { echo "$black$*$reset_color"; }
red() { echo "$red$*$reset_color"; }
green() { echo "$green$*$reset_color"; }
yellow() { echo "$yellow$*$reset_color"; }
blue() { echo "$blue$*$reset_color"; }
magenta() { echo "$magenta$*$reset_color"; }
cyan() { echo "$cyan$*$reset_color"; }
white() { echo "$white$*$reset_color"; }

Now I can do these:

red "Something went wrong."
cyan "Multicolored $magenta example.$reset_color"
echo "${yellow}This is a warning.$blue For reason x."