Skip to content

Instantly share code, notes, and snippets.

@acook
acook / git_prompt
Created September 6, 2011 21:04
Customizes your prompt to work with git!
#!/bin/bash
# Creates a shiny prompt that integrates well with git
# Load up my script that lets me set colors much easier
source bashrgb
# Load my prompt helpers that make a lot of this voodoo easier to do
source prompt_helpers
# pulls information from git to display in the prompt
@acook
acook / git_completion.bash
Created September 6, 2011 21:05
Tab completion for git in bash!
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@acook
acook / prompt_helpers
Created September 6, 2011 21:06
Provides helpers for making prompts.
#!/bin/bash
# Just some stuff to make writing prompts easier
# Set a Terminal's title with this, saves a lot of weird strings from the prompts
function title { echo -ne "\\033]0;$*\007"; }
# Gets the present working directory and returns just the last 2 directories, good for shortening titles and prompts
function PWD { tmp=${PWD%/*/*}; [ ${#tmp} -gt 0 -a "$tmp" != "$PWD" ] && echo ${PWD:${#tmp}+1} || echo $PWD; }
# Does the same thing, but for any path
function shortpath { tmp=${1%/*/*}; [ ${#tmp} -gt 0 -a "$tmp" != "$1" ] && echo ${1:${#tmp}+1} || echo $1; }
@acook
acook / bashrgb
Created September 6, 2011 21:19
Easily set colors in bash.
#!/bin/sh
# defined colors to make it easier to output visually stimulating prompts and other messages
# escapes the arguments you send it
function esc () { echo -ne "\\033[$*"; }
# color code escapes your first argument then follows with the rest of them
function escc () { echo -ne "\\033[$1m$2 $3 $4 $5 $6 $7 $8 $9"; }
# basic color escapes
function c () { echo -ne "\\033[$1m"; }
function fg () { echo -ne "\\033[0;$1m"; }
@acook
acook / .autotest
Created September 8, 2011 17:44
Put this in your home directory.
Autotest.add_hook :initialize do |autotest|
%w{.git .svn .hg .DS_Store ._* vendor tmp log doc tag TAG TAGS tags *.orig Gemfile.lock}.each do |exception|
autotest.add_exception(exception)
end
end
@acook
acook / .gitconfig
Created September 8, 2011 19:28
Copy and paste this into your .gitconfig. (located in your home directory)
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = auto
pager = true
[color "branch"]
current = yellow reverse
@acook
acook / rubystuff.rb
Created September 9, 2011 15:07
Explanation of some of the internals of ruby.
public # call from anywhere
protected # call from inside instance of a class
private # only call implicitly from instance
Constants # Not inherited, not changed
@@class_variables # Inherited, changeable
# Changes all sub and super classe as well!!
my_new_array = Array.new 5
my_new_array.map! do
Array.new(5).map do
:placeholder
end
end
p my_new_array
@acook
acook / gist:1207038
Created September 9, 2011 18:58
Pry session, show-doc string
pry(main)> x = ""
=> ""
pry(main)> cd x
pry(""):1> show-doc chars
From: string.c in Ruby Core (C Method):
Number of lines: 11
visibility: public
signature: chars()
@acook
acook / gist:1208045
Created September 10, 2011 06:57
Supposedly a fix for 'xterm-256': unknown terminal type.
sudo apt-get install ncurses-term