-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesper Haug Karsrud
authored and
Jesper Haug Karsrud
committed
Jul 12, 2012
0 parents
commit b123c93
Showing
6 changed files
with
541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
export PATH=$HOME/local/node/bin:$PATH | ||
export LC_ALL=en_US.UTF-8 | ||
export LANG=en_US.UTF-8 | ||
|
||
alias ll='ls -lasG' | ||
|
||
# Git shortcuts | ||
alias g='git' | ||
alias ga='git add' | ||
alias gp='git push' | ||
alias gpa='gp --all' | ||
alias gu='git pull' | ||
alias gl='git log' | ||
alias gg='gl --decorate --oneline --graph --date-order --all' | ||
alias gs='git status' | ||
alias gst='gs' | ||
alias gd='git diff' | ||
alias gdc='gd --cached' | ||
alias gm='git commit -m' | ||
alias gma='git commit -am' | ||
alias gb='git branch' | ||
alias gba='git branch -a' | ||
function gc() { git checkout "${@:-master}"; } # Checkout master by default | ||
alias gco='gc' | ||
alias gcb='gc -b' | ||
alias gr='git remote' | ||
alias grv='gr -v' | ||
#alias gra='git remote add' | ||
alias grr='git remote rm' | ||
alias gcl='git clone' | ||
|
||
# add a github remote by github username | ||
function gra() { | ||
if (( "${#@}" != 1 )); then | ||
echo "Usage: gra githubuser" | ||
return 1; | ||
fi | ||
local repo=$(gr show -n origin | perl -ne '/Fetch URL: .*github\.com[:\/].*\/(.*)/ && print $1') | ||
gr add "$1" "git://github.com/$1/$repo" | ||
} | ||
|
||
# git log with per-commit cmd-clickable GitHub URLs (iTerm) | ||
function gf() { | ||
local remote="$(git remote -v | awk '/^origin.*\(push\)$/ {print $2}')" | ||
[[ "$remote" ]] || return | ||
local user_repo="$(echo "$remote" | perl -pe 's/.*://;s/\.git$//')" | ||
git log $* --name-status --color | awk "$(cat <<AWK | ||
/^.*commit [0-9a-f]{40}/ {sha=substr(\$2,1,7)} | ||
/^[MA]\t/ {printf "%s\thttps://github.com/$user_repo/blob/%s/%s\n", \$1, sha, \$2; next} | ||
/.*/ {print \$0} | ||
AWK | ||
)" | less -F | ||
} | ||
|
||
# Just the last few commits, please! | ||
for n in {1..5}; do alias gf$n="gf -n $n"; done | ||
|
||
# OSX-specific Git shortcuts | ||
if [[ "$OSTYPE" =~ ^darwin ]]; then | ||
alias gdk='git ksdiff' | ||
alias gdkc='gdk --cached' | ||
alias gt='gittower -s' | ||
fi | ||
|
||
# My awesome bash prompt | ||
# | ||
# Copyright (c) 2012 "Cowboy" Ben Alman | ||
# Licensed under the MIT license. | ||
# http://benalman.com/about/license/ | ||
# | ||
# Example: | ||
# [master:!?][cowboy@CowBook:~/.dotfiles] | ||
# [11:14:45] $ | ||
# | ||
# Read more (and see a screenshot) in the "Prompt" section of | ||
# https://github.com/cowboy/dotfiles | ||
|
||
# ANSI CODES - SEPARATE MULTIPLE VALUES WITH ; | ||
# | ||
# 0 reset 4 underline | ||
# 1 bold 7 inverse | ||
# | ||
# FG BG COLOR FG BG COLOR | ||
# 30 40 black 34 44 blue | ||
# 31 41 red 35 45 magenta | ||
# 32 42 green 36 46 cyan | ||
# 33 43 yellow 37 47 white | ||
|
||
if [[ ! "${prompt_colors[@]}" ]]; then | ||
prompt_colors=( | ||
"34" # information color | ||
"37" # bracket color | ||
"31" # error color | ||
) | ||
|
||
if [[ "$SSH_TTY" ]]; then | ||
# connected via ssh | ||
prompt_colors[0]="32" | ||
elif [[ "$USER" == "root" ]]; then | ||
# logged in as root | ||
prompt_colors[0]="35" | ||
fi | ||
fi | ||
|
||
# Inside a prompt function, run this alias to setup local $c0-$c9 color vars. | ||
alias prompt_getcolors='prompt_colors[9]=; local i; for i in ${!prompt_colors[@]}; do local c$i="\[\e[0;${prompt_colors[$i]}m\]"; done' | ||
|
||
# Exit code of previous command. | ||
function prompt_exitcode() { | ||
prompt_getcolors | ||
[[ $1 != 0 ]] && echo " $c2$1$c9" | ||
} | ||
|
||
# Git status. | ||
function prompt_git() { | ||
prompt_getcolors | ||
local status output flags | ||
status="$(git status 2>/dev/null)" | ||
[[ $? != 0 ]] && return; | ||
output="$(echo "$status" | awk '/# Initial commit/ {print "(init)"}')" | ||
[[ "$output" ]] || output="$(echo "$status" | awk '/# On branch/ {print $4}')" | ||
[[ "$output" ]] || output="$(git branch | perl -ne '/^\* (.*)/ && print $1')" | ||
flags="$( | ||
echo "$status" | awk 'BEGIN {r=""} \ | ||
/^# Changes to be committed:$/ {r=r "+"}\ | ||
/^# Changes not staged for commit:$/ {r=r "!"}\ | ||
/^# Untracked files:$/ {r=r "?"}\ | ||
END {print r}' | ||
)" | ||
if [[ "$flags" ]]; then | ||
output="$output$c1:$c0$flags" | ||
fi | ||
echo "$c1$c0$output$c1$c9 " | ||
} | ||
|
||
# SVN info. | ||
function prompt_svn() { | ||
prompt_getcolors | ||
local info="$(svn info . 2> /dev/null)" | ||
local last current | ||
if [[ "$info" ]]; then | ||
last="$(echo "$info" | awk '/Last Changed Rev:/ {print $4}')" | ||
current="$(echo "$info" | awk '/Revision:/ {print $2}')" | ||
echo "$c1$c0$last$c1:$c0$current$c1$c9 " | ||
fi | ||
} | ||
|
||
# Maintain a per-execution call stack. | ||
prompt_stack=() | ||
trap 'prompt_stack=("${prompt_stack[@]}" "$BASH_COMMAND")' DEBUG | ||
|
||
function prompt_command() { | ||
local exit_code=$? | ||
# If the first command in the stack is prompt_command, no command was run. | ||
# Set exit_code to 0 and reset the stack. | ||
[[ "${prompt_stack[0]}" == "prompt_command" ]] && exit_code=0 | ||
prompt_stack=() | ||
|
||
# While the simple_prompt environment var is set, disable the awesome prompt. | ||
[[ "$simple_prompt" ]] && PS1='\n$ ' && return | ||
|
||
prompt_getcolors | ||
# http://twitter.com/cowboy/status/150254030654939137 | ||
PS1="\n" | ||
# svn: [repo:lastchanged] | ||
PS1="$PS1$(prompt_svn)" | ||
# git: [branch:flags] | ||
PS1="$PS1$(prompt_git)" | ||
# misc: [cmd#:hist#] | ||
# PS1="$PS1$c1[$c0#\#$c1:$c0!\!$c1]$c9" | ||
# path: [user@host:path] | ||
PS1="$PS1$c1$c0\u$c1@$c0\h$c1:$c0\w$c1$c9" | ||
# exit code: 127 | ||
PS1="$PS1$(prompt_exitcode "$exit_code")" | ||
PS1="$PS1\n" | ||
PS1="$PS1\$ " | ||
} | ||
|
||
PROMPT_COMMAND="prompt_command" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[user] | ||
name = Jesper Haug Karsrud | ||
email = EMAIL | ||
[color] | ||
ui = true | ||
status = true | ||
interactive = true | ||
diff = true | ||
branch = true | ||
[core] | ||
whitespace = trailing-space,space-before-tab | ||
autocrlf = input | ||
[apply] | ||
whitespace = fix | ||
[alias] | ||
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit |
Oops, something went wrong.