---
title: "Improving the Pull Request from terminal"
slug: improving-the-pull-request-from-terminal
section: tech
date: 2015-10-17T23:24:00.000Z
canonical: https://roland.leth.ro/blog/tech/improving-the-pull-request-from-terminal
---

Just a slight improvement for [last post](/tech/blog/opening-pull-requests-from-terminal): sometimes I don't have the branch pushed on GitHub, so why not automate that too?

```bash
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](https://raymii.org/s/snippets/Bash_Bits_Add_Color_Output_To_Your_Scripts.html) some nice helpers for easier color printing:

```bash
// 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:

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