iEFdev

Code, Computers & Random Junk

.bash_git

When you setup your bash environment, splitting up the files are a good idea to keep things organized. Normally you would end up with a set o files like:

  • .bash_profiles
  • .bashrc
  • .bash_aliases
  • .bash_functions
  • … perhaps more

Recently I added a couple of things for git, and to not “break” my setup, they went in the different files. But, it felt wrong - so I made a separate file for that content instead. Also, easier to add in, share (like this) etc…

So, I added an xtra .bash_git to my setup. This is my version for OS X, but I use the same in Linux, except for the path to git-completion.bash- which is just a matter och editing the path to it. And the clipboard needs to be removed (see below).

.git_bashlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# ~/.bash_git
#
#
# Description: Separate file for git related stuff
#
# Load it in: ~/.bashrc with
# ------------------------------------------------------------------------------
#   # Load: ~/.bash_git
#   [ -f ~/.bash_git ] && . ~/.bash_git
# ------------------------------------------------------------------------------
#

# Function to get current branch
git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'; }

# Git branch to PS1 (see .bashrc)
PS1="\[\e[0;32m\]\$(git_branch)\[\e[m\]$PS1";

# Load git-completion
[ -f /usr/local/git/contrib/completion/git-completion.bash ] && . /usr/local/git/contrib/completion/git-completion.bash

# Get shortURL from git.io to clipboard
function gitio()
{
    local _url="$1";
    echo -n $(curl -i http://git.io -F "url=$_url" | grep 'Location' | awk '{ print $2 }') | pbcopy;
}

Load it in your .bashrc (or .bash_profile if you are using that one) with:

# Load: ~/.bash_git
[ -f ~/.bash_git ] && . ~/.bash_git

Edits

The last function (gitio())… At the end you might want to remove pbcopy:

echo -n $(curl -i http://git.io -F "url=$_url" | grep 'Location' | awk '{ print $2 }');

… &/or replace it with xclip for Linux/*BSD:

echo -n $(curl -i http://git.io -F "url=$_url" | grep 'Location' | awk '{ print $2 }') | xclip -selection clipboard;

Screenshot

Comments