Permalink
Browse files

split bash/zsh config, aliases & function into files

  • Loading branch information...
mislav committed May 30, 2012
1 parent e58e854 commit a79a880fc315b20273fa97c71cce78e693952e04
Showing with 191 additions and 268 deletions.
  1. +0 −107 bash_aliases
  2. +10 −17 bash_profile
  3. +2 −55 bashrc
  4. +17 −0 shrc/1.brew.sh
  5. +4 −0 shrc/2.rbenv.sh
  6. +16 −0 shrc/3.coral.sh
  7. +3 −0 shrc/alias.sh
  8. +12 −0 shrc/editor.sh
  9. +15 −0 shrc/git.sh
  10. +4 −0 shrc/process.sh
  11. +60 −0 shrc/prompt.sh
  12. +40 −0 shrc/ruby.sh
  13. +8 −89 zshrc
View
@@ -1,107 +0,0 @@
-#######
-# git #
-#######
-alias gl='git pull'
-alias gp='git push'
-alias gd='git diff'
-alias gc='git commit -v'
-alias gca='git commit -v -a'
-alias gb='git branch -v'
-alias st='git status -sb'
-
-function gco {
- if [ $# -eq 0 ]; then
- git checkout master
- else
- git checkout "$@"
- fi
-}
-
-function superblame {
- git log --format=%h --author=$1 $2 | \
- xargs -L1 -ISHA git diff --shortstat 'SHA^..SHA' -- app config/environment* config/initializers/ public/stylesheets/ | \
- ruby -e 'n=Hash.new(0); while gets; i=0; puts $_.gsub(/\d+/){ n[i+=1] += $&.to_i }; end' | tail -n1
-}
-
-########
-# RUBY #
-########
-
-if which noglob >/dev/null; then
- alias rake='noglob rake' # allows square brackets for rake task invocation
- alias brake='noglob bundle exec rake' # execute the bundled rake gem
-fi
-
-#########
-# RAILS #
-#########
-
-# console
-function sc() {
- if [ -f config/environment.rb ] && which pry >/dev/null; then
- pry -r./config/environment.rb
- elif [ -x script/rails ]; then
- script/rails console
- elif [ -x script/console ]; then
- script/console
- elif [ -f app.rb ]; then
- local repl=$(which pry >/dev/null && echo pry || echo irb)
- local args=$([ -n "$BUNDLE_GEMFILE" -o -f Gemfile ] && echo "-rbundler/setup")
- $repl $args -I. -r./app.rb
- else
- echo "no script/rails or script/console found" >&2
- return 1
- fi
-}
-
-# server
-function ss() {
- if [ -x script/rails ]; then
- script/rails server "$@"
- elif [ -x script/server ]; then
- script/server "$@"
- else
- echo "no script/rails or script/server found" >&2
- return 1
- fi
-}
-
-# stop daemonized Rails server
-function sst() {
- if [ -f tmp/pids/mongrel.pid ]; then
- echo "Stopping Mongrel ..."
- kill `cat tmp/pids/mongrel.pid`
- elif [ -f tmp/pids/server.pid ]; then
- echo "Stopping server ..."
- kill `cat tmp/pids/server.pid`
- fi
-}
-
-# restart Rails application
-function sr() {
- if [ -f tmp/pids/mongrel.pid ]; then
- echo "Restarting Mongrel ..."
- kill -USR2 `cat tmp/pids/mongrel.pid`
- elif [ -f tmp/pids/server.pid ]; then
- echo "Restarting server ..."
- kill -USR2 `cat tmp/pids/server.pid`
- else
- echo "Restarting application ..."
- touch tmp/restart.txt
- fi
-}
-
-########
-# misc #
-########
-
-alias h='history'
-alias j="jobs -l"
-alias l="ls -lah"
-alias ll="ls -l"
-alias la='ls -A'
-
-# mojombo http://gist.github.com/180587
-function psg {
- ps wwwaux | egrep "($1|%CPU)" | grep -v grep
-}
View
@@ -1,23 +1,16 @@
-[ -f ~/.bashrc ] && source ~/.bashrc
+# vim:ft=sh:
-# setenv CLICOLOR "1"
-# setenv LSCOLORS "ExFxCxDxBxegedabagacad"
+# don't put duplicate lines in the history. See bash(1) for more options
+export HISTCONTROL=ignoredups
-localbin=/usr/local/bin
+export EDITOR=vim
-if [ -d $localbin ]; then
- export PATH=$localbin:$(echo $PATH | sed -E s%$localbin:?%%)
+if [[ $TERM =~ xterm ]]; then
+ PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
fi
-if [ -L $localbin/ruby ]; then
- target=$(readlink $localbin/ruby)
- rubybin=$(cd $localbin/$(dirname $target) && pwd -P)
- export PATH=$rubybin:$PATH
-fi
+for file in ~/.shrc/*.sh; do
+ source "$file"
+done
-if [ -d ~/.rbenv/bin ]; then
- export PATH="$HOME/.rbenv/bin:$PATH"
- eval "$(rbenv init -)"
-fi
-[ -d ~/.coral/bin ] && export PATH=~/.coral/bin:$PATH
-[ -d ~/bin ] && export PATH=~/bin:$PATH
+[ -d ~/bin ] && export PATH=~/bin:"$PATH"
View
57 bashrc
@@ -1,56 +1,3 @@
-# ~/.bashrc: executed by bash(1) for non-login shells.
-# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
-# for examples
+# invoked for non-login, interactive shells
-# If not running interactively, don't do anything
-[ -z "$PS1" ] && return
-
-# don't put duplicate lines in the history. See bash(1) for more options
-export HISTCONTROL=ignoredups
-
-export EDITOR=vim
-
-# set variable identifying the chroot you work in (used in the prompt below)
-if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
- debian_chroot=$(cat /etc/debian_chroot)
-fi
-
-parse_git_branch() {
- (git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null | \
- /usr/bin/ruby -pe '$_.sub!(%r{^(?:refs/)?(?:(heads|tags)/)?(.+?)(\^0)?$}, %{ (\\2)})'
-}
-
-PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\h\[\033[00m\]:\[\e[0;31m\]\w\[\e[m\]$(parse_git_branch) $ '
-
-# Terminal title (git completion is required for this):
-# export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~} $(__git_ps1 " (%s)")"; echo -ne "\007"'
-
-# If this is an xterm set the title to user@host:dir
-case "$TERM" in
-xterm*|rxvt*)
- PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
- ;;
-*)
- ;;
-esac
-
-# Alias definitions.
-if [ -f ~/.bash_aliases ]; then
- . ~/.bash_aliases
-fi
-
-# enable programmable completion features (you don't need to enable
-# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
-# sources /etc/bash.bashrc).
-if [ -f /etc/bash_completion ]; then
- . /etc/bash_completion
-fi
-
-homebrew=$(brew --prefix)
-
-for file in $(find $homebrew/etc/bash_completion.d -not -type d)
-do
- source $file 2>/dev/null
-done
-
-source $homebrew/Library/Contributions/brew_bash_completion.sh
+[[ -n "$PS1" ]] && source ~/.bash_profile
View
@@ -0,0 +1,17 @@
+brew=/usr/local
+
+if [ -x $brew/bin/brew ]; then
+ PATH=$brew/sbin:"$PATH"
+ PATH=$brew/bin:"$(echo $PATH | sed -E "s%$brew/bin:?%%")"
+ export PATH
+
+ if [ "$(basename "$SHELL")" = bash ]; then
+ for file in $brew/etc/bash_completion.d/*; do
+ [ -f "$file" ] && source "$file" 2>/dev/null
+ done
+
+ source $brew/Library/Contributions/brew_bash_completion.sh
+ fi
+fi
+
+unset brew file
View
@@ -0,0 +1,4 @@
+if [ -d $HOME/.rbenv/bin ]; then
+ export PATH="$HOME/.rbenv/bin:$PATH"
+ eval "$(rbenv init -)"
+fi
View
@@ -0,0 +1,16 @@
+if [ -d ~/.coral/bin ]; then
+ export PATH=~/.coral/bin:"$PATH"
+
+ # Provide `coral cd <name>` command, which uses `coral path <name>` and changes
+ # into the resulting directory.
+ function coral {
+ if [[ $1 = 'cd' ]]; then
+ shift
+ local dir
+ dir="$(command coral path "$@")" || return $?
+ cd "$dir"
+ else
+ command coral "$@"
+ fi
+ }
+fi
View
@@ -0,0 +1,3 @@
+alias l="ls -lah"
+alias ll="ls -l"
+alias la='ls -A'
View
@@ -0,0 +1,12 @@
+export EDITOR=vim
+export GIT_EDITOR=$EDITOR
+# wanted to set VISUAL here, but it affects too many things I don't want
+[[ "$(uname -s)" == Darwin ]] && GEM_EDITOR=mvim || GEM_EDITOR=gvim
+export GEM_EDITOR
+
+if which zle >/dev/null; then
+ # C-x C-e to edit command-line in EDITOR
+ autoload -U edit-command-line
+ zle -N edit-command-line
+ bindkey '\C-x\C-e' edit-command-line
+fi
View
@@ -0,0 +1,15 @@
+alias gl='git pull'
+alias gp='git push'
+alias gd='git diff'
+alias gc='git commit -v'
+alias gca='git commit -v -a'
+alias gb='git branch -v'
+alias st='git status -sb'
+
+function gco {
+ if [ $# -eq 0 ]; then
+ git checkout master
+ else
+ git checkout "$@"
+ fi
+}
View
@@ -0,0 +1,4 @@
+# mojombo http://gist.github.com/180587
+function psg {
+ ps wwwaux | egrep "($1|%CPU)" | grep -v grep
+}
View
@@ -0,0 +1,60 @@
+# show git branch/tag, or name-rev if on detached head
+parse_git_branch() {
+ (command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null
+}
+
+case $(basename "$SHELL") in
+
+bash )
+ # set variable identifying the chroot you work in (used in the prompt below)
+ if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
+ debian_chroot=$(cat /etc/debian_chroot)
+ fi
+
+ git_where() {
+ ref="$(parse_git_branch)"
+ echo ${ref#(refs/heads/|tags/)}
+ }
+
+ PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\h\[\033[00m\]:\[\e[0;31m\]\w\[\e[m\]$(git_where) $ '
+ ;;
+
+zsh )
+ local GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
+ local GIT_PROMPT_SUFFIX="]%{$reset_color%}"
+ local GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
+ local GIT_PROMPT_CLEAN=""
+
+ # show red star if there are uncommitted changes
+ parse_git_dirty() {
+ if command git diff-index --quiet HEAD 2> /dev/null; then
+ echo "$GIT_PROMPT_CLEAN"
+ else
+ echo "$GIT_PROMPT_DIRTY"
+ fi
+ }
+
+ # if in a git repo, show dirty indicator + git branch
+ git_custom_status() {
+ local git_where="$(parse_git_branch)"
+ [ -n "$git_where" ] && echo "$(parse_git_dirty)$GIT_PROMPT_PREFIX${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
+ }
+
+ # show current rbenv version if different from rbenv global
+ rbenv_version_status() {
+ local ver=$(rbenv version-name)
+ [ "$(rbenv global)" != "$ver" ] && echo "[$ver]"
+ }
+
+ # put fancy stuff on the right
+ if which rbenv &> /dev/null; then
+ RPS1='$(git_custom_status)%{$fg[red]%}$(rbenv_version_status)%{$reset_color%} $EPS1'
+ else
+ RPS1='$(git_custom_status) $EPS1'
+ fi
+
+ # basic prompt on the left
+ PROMPT='%{$fg[cyan]%}%~% %(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
+ ;;
+
+esac
View
@@ -0,0 +1,40 @@
+if which noglob >/dev/null; then
+ alias rake='noglob rake' # allows square brackets for rake task invocation
+ alias brake='noglob bundle exec rake' # execute the bundled rake gem
+fi
+
+# console
+function sc() {
+ if [ -f config/environment.rb ] && which pry >/dev/null; then
+ pry -r./config/environment.rb
+ elif [ -x script/rails ]; then
+ script/rails console
+ elif [ -x script/console ]; then
+ script/console
+ elif [ -f app.rb ]; then
+ local repl=$(which pry >/dev/null && echo pry || echo irb)
+ local args=$([ -n "$BUNDLE_GEMFILE" -o -f Gemfile ] && echo "-rbundler/setup")
+ $repl $args -I. -r./app.rb
+ else
+ echo "no script/rails or script/console found" >&2
+ return 1
+ fi
+}
+
+# server
+function ss() {
+ if [ -x script/rails ]; then
+ script/rails server "$@"
+ elif [ -x script/server ]; then
+ script/server "$@"
+ else
+ echo "no script/rails or script/server found" >&2
+ return 1
+ fi
+}
+
+# restart
+function sr() {
+ mkdir -p tmp
+ touch tmp/restart.txt
+}
Oops, something went wrong.

0 comments on commit a79a880

Please sign in to comment.