Skip to content

Instantly share code, notes, and snippets.

@jrburke
Last active February 11, 2024 23:19
Show Gist options
  • Save jrburke/6015899 to your computer and use it in GitHub Desktop.
Save jrburke/6015899 to your computer and use it in GitHub Desktop.
Gaia shortcuts for UX people working with developers
#!/bin/bash
# Example gaia-clean-pull 10962
PULLID=$1
if [ -z "$1" ]
then
echo "Usage: gaia-clean-pull PULL-REQUEST-ID"
exit 1
fi
## Remove any local changes from the patch
git checkout -- .
# Go back to master
git checkout master
# Delete the temporary branch used for pull
git branch -D pull$PULLID
#!/bin/bash
# Example gaia-pull 10962
PULLID=$1
if [ -z "$1" ]
then
echo "Usage: gaia-pull PULL-REQUEST-ID"
exit 1
fi
git checkout master
git fetch upstream
git pull upstream master
git checkout -b pull$PULLID
curl https://github.com/mozilla-b2g/gaia/pull/$PULLID.patch -o $PULLID.patch
git apply $PULLID.patch

Git color

Turn on coloring in git. It is an easy one line command:

git config --global --add color.ui true

Git command autocompletion

This is probably more useful to a developer that is doing lots of git commands. Autocompletion also autocompletes on branch names, making it easier to switch branches.

For OS X:

If you have Homebrew installed, then I have used the bash_completion route to get this capability:

http://blog.jeffterrace.com/2012/09/bash-completion-for-mac-os-x.html

Looks like there is also this pathway, but have not tried it:

http://www.codethatmatters.com/2010/01/git-autocomplete-in-mac-os-x/

If on Linux you may already have this capability built in.

Show branch on command line

For showing the current git branch on the command line, and showing the command line in color, open your ~/.profile file and comment out (using a #) any existing PS1 line and paste the following below that commented out line:

(this is for the standard default bash shell on OS X)

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

function proml {
  local        END="\[\033[0m\]"
  local        BLUE="\[\033[0;34m\]"
  local         RED="\[\033[0;31m\]"
  local   LIGHT_RED="\[\033[1;31m\]"
  local       GREEN="\[\033[0;32m\]"
  local LIGHT_GREEN="\[\033[1;32m\]"
  local       WHITE="\[\033[1;37m\]"
  local  LIGHT_GRAY="\[\033[0;37m\]"
  case $TERM in
    xterm*)
    TITLEBAR='\[\033]0;\u@\h:\w\007\]'
    ;;
    *)
    TITLEBAR=""
    ;;
  esac

PS1="${TITLEBAR}\
$BLUE[$RED\w$GREEN\$(parse_git_branch)$BLUE]\
$END$ "
PS2='> '
PS4='+ '
}
proml

Next shell you open should have the colors.

Shell scripts to fetch pulls

Below are two scripts, gaia-pull and gaia-clean-pull. They both assume you already have your own fork of gaia set up and you have pull it down and have set the mozilla-b2g/gaia as the upstream repo:

git remote add upstream https://github.com/mozilla-b2g/gaia.git

Once you have your fork cloned locally you can place gaia-pull and gaia-clean-pull in your PATH and use them to try out pull requests. General process:

  • You get a link to a pull request, in the form of https://github.com/mozilla-b2g/gaia/pull/123456. The last number on there is the pull request number. Copy that (in this example, 123456), and then inside the gaia directory, type:
  • gaia-pull 123456
  • The gaia repo is ready to go. Type make GAIA_OPTIMIZE=1 reset-gaia to install on the device.
  • You can use git diff in the gaia directory to see what files have changed.
  • Once you are done, clean up the temporary branch by doing:
  • gaia-clean-pull 123456

At the end of that, you should be back on the master branch in your fork.

If you comment on this Gist, I will not see it, because GitHub does not notify me of Gist comments, so be sure to ping me in IRC or online if you do leave a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment