Skip to content

Commit

Permalink
feat(git): add a git clone helper that automatically tracks all remot…
Browse files Browse the repository at this point in the history
…e branches
  • Loading branch information
Deavon M. McCaffery committed Aug 19, 2016
1 parent 602c12a commit 72495ae
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 26 deletions.
16 changes: 12 additions & 4 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ if [ "$(uname)" == "Darwin" ]; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 1>/dev/null 2>&1
fi

LOCAL_PREFIX=$(brew --prefix)

echo "Updating Homebrew..."
brew update 1>/dev/null 2>&1

Expand All @@ -54,6 +56,8 @@ if [ "$(uname)" == "Darwin" ]; then
fi
done

rm -rRf "$LOCAL_PREFIX/etc/bash_completion.d/git-prompt.sh" 1>/dev/null 2>&1

for pkg in ffmpeg gettext gifsicle git git-flow-avh gnu-getopt lame libvo-aacenc mono node x264 xvid; do
if brew list -1 | grep -q "^${pkg}\$"; then
echo "Upgrading $pkg..."
Expand All @@ -64,8 +68,6 @@ if [ "$(uname)" == "Darwin" ]; then
fi
done

LOCAL_PREFIX=$(brew --prefix)

git config --system credential.helper osxkeychain

echo "Tapping extended versions for caskroom..."
Expand All @@ -80,15 +82,21 @@ if [ "$(uname)" == "Darwin" ]; then
brew cask install ${app}
fi
done
elif [ "$(uname)" == "MINGW64_NT-10.0" ]; then
LOCAL_PREFIX=$LOCALAPPDATA/git

mkdir -p "$LOCAL_PREFIX" 1>/dev/null 2>&1
fi

gitpromptname=git-prompt.sh
gitprompt=$LOCAL_PREFIX/etc/bash_completion.d/$gitpromptname
gitprompt=$LOCAL_PREFIX/etc/bash_completion.d
gitprompturi=https://raw.githubusercontent.com/lyze/posh-git-sh/master/$gitpromptname

if test -f "$gitprompt"; then
if test -f "$gitprompt/$gitpromptname"; then
echo "Removing crappy git-prompt..."
rm -rRf "gitprompt" 1>/dev/null 2>&1
else
mkdir -p "$gitprompt" 1>/dev/null 2>&1
fi

echo "Downloading better git-prompt..."
Expand Down
4 changes: 3 additions & 1 deletion src/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export CLR_SSH_PROMPT=$CLR_BRIGHT_MAGENTA # COLOR OF THE PROMPT FOR SSH

# enable colors for various commands
export TERM=xterm-256color
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;32'
export CLICOLOR=1
alias grep="$(which grep) --color=auto"

# change ls colors to be more like original unix/linux
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"
Expand All @@ -39,6 +39,8 @@ export HISTCONTROL=ignoredubs

if type brew 1>/dev/null 2>&1; then
export LOCAL_PREFIX=$(brew --prefix)
elif test -d $LOCALAPPDATA/git; then
export LOCAL_PREFIX=$(echo "/$LOCALAPPDATA/git" | sed -e 's/\\/\//g' -e 's/://')
else
export LOCAL_PREFIX=/usr/local
fi
Expand Down
33 changes: 33 additions & 0 deletions src/scripts/git-extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
git-clone() {
if ! test -f $(which git); then
echo "Git is not available on the current path. Exiting."
return
fi

local url=$1
local name=$2

if [ "$url" == "" ]; then
echo "You must specify a url, which is the first parameter."
return
fi

if [ "$name" == "" ]; then
echo "You must specify a directory name, which is the second parameter."
return
fi

git clone $url $name && \
cd $name && \
git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /\/develop$/d; /remotes/p;" | xargs -L1 git checkout -t 2>/dev/null && \
git init -d 2>/dev/null

echo Checking out master and develop branches...

git checkout develop 2>/dev/null
git checkout master 2>/dev/null
}

clone() {
git-clone $@
}
38 changes: 21 additions & 17 deletions src/scripts/set-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function emit-prompt-arrow()
local CLR_PROMPT=$CLR_USER_PROMPT

# set color for staff user (administrator)
if [ ! -z "$(command id -Gn | grep -s -o admin)" ]; then
if [ ! -z "$(command id -Gn 2>/dev/null | grep -s -o admin)" ]; then
CLR_PROMPT=$CLR_STAFF_PROMPT
fi

Expand All @@ -25,23 +25,27 @@ function emit-prompt-arrow()
fi
}

for f in $LOCAL_PREFIX/etc/bash_completion.d/*; do
source $f
done

if type gulp 1>/dev/null 2>&1; then
eval "$(gulp --completion=bash)"
fi

if type grunt 1>/dev/null 2>&1; then
eval "$(grunt --completion=bash)"
fi

if type npm 1>/dev/null 2>&1; then
eval "$(npm completion)"
fi

function set-prompt() {
local bash_completion=$LOCAL_PREFIX/etc/bash_completion.d

if test -d "$bash_completion"; then
for f in $bash_completion/*; do
source $f
done
fi

if type gulp 1>/dev/null 2>&1; then
eval "$(gulp --completion=bash)"
fi

if type grunt 1>/dev/null 2>&1; then
eval "$(grunt --completion=bash)"
fi

if type npm 1>/dev/null 2>&1; then
eval "$(npm completion)"
fi

# set the window title
echo -ne "\033]0;${USER}@${HOSTNAME%%.*} ${PWD}\007"

Expand Down
12 changes: 8 additions & 4 deletions src/scripts/source-uname.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
function source-uname() {
for f in ~/.ssh/scripts/$(uname)/*; do
source $f
done
function source-uname() {
local unamepath=~/.ssh/scripts/$(uname)

if test -d $unamepath; then
for f in $unamepath/*; do
source $f
done
fi
}

source-uname

0 comments on commit 72495ae

Please sign in to comment.