Skip to content

Instantly share code, notes, and snippets.

@duff
duff / .bashrc
Created January 26, 2009 18:53 — forked from henrik/.bashrc
Git branch and dirty state (using git-completion.bash) and colored
# [ ~/develop/dir ] master $ # clean working directory
# [ ~/develop/dir ] master* $ # dirty working directory
# [ ~/some_dir ] $ # not a git repo
source ~/bin/.git-completion.sh # Copied the contrib/completion/git-completion.bash file in the git distribution
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
PS1='\e[0m[ \e[32m\w\e[0m ]$(__git_ps1 " \e[33m%s\e[31m$(parse_git_dirty)\e[0m") $ '
@duff
duff / bash_prompt_with_git_branch.bash
Created April 8, 2009 19:08
Some git auto complete goodness
source ~/bin/.git-completion.sh # Copied from the contrib/completion/git-completion.bash file in the git distribution (Also here: http://gist.github.com/91932)
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo '*'
}
PS1='\[\e[0m\][ \[\e[32m\]\w \[\e[0m\]]$(__git_ps1 " \[\e[33m\]%s$(parse_git_dirty)") \[\e[0m\]$ \[\e[0m\]'
alias bash_profile='vi ~/.bash_profile && source ~/.bash_profile'
@duff
duff / gist:132557
Created June 19, 2009 10:55 — forked from defunkt/gist:132456
Bash snippet to open new shells in recent directory
# Bash snippet to open new shells in most recently visited dir.
# Useful if you want to open a new terminal tab at the present
# tab's location.
#
# Put this in your .bashrc or whatever.
pathed_cd () {
if [ "$1" == "" ]; then
cd
else
@duff
duff / post-merge
Created June 26, 2009 15:34 — forked from austintaylor/post-merge
Show the diff after a git merge
#!/bin/sh
# Print out what changed in a nice format.
git log @{1}.. --pretty=format:"%Cblue%an%Creset %ar: %Cred\"%s%b\"%Creset (%h)" --reverse
@duff
duff / gist:319907
Created March 2, 2010 20:35
Easily jump to Rails migrations
Learned about this feature in the rails.vim plugin:
:R/:A jump to next/previous timestamped migration.
@duff
duff / gist:320619
Created March 3, 2010 13:59
Moving the cursor in visual mode
In visual mode, press o to move the cursor to the other end of the selected region.
This allows you to easily adjust the selected region from either side.
Pressing O while in visual block mode moves the cursor to the other corner.
@duff
duff / gist:320890
Created March 3, 2010 19:13
Webrat monkey patch so save_and_open_page can use stylesheets
module Webrat
module SaveAndOpenPage
def save_and_open_page
return unless File.exist?(Webrat.configuration.saved_pages_dir)
filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.html"
File.open(filename, "w") do |f|
f.write prettified(response_body)
end
@duff
duff / gist:325216
Created March 8, 2010 14:51
Bash alias for simple git log output
alias gl='git log -n1000 --no-merges --pretty=format:"* %s (%cn) %b"'
@duff
duff / gist:328225
Created March 10, 2010 19:10
See the routes for a controller
:.Rake
When you're in a controller. This will do a
routes CONTROLLER=...
so you can see the routes specific to that controller. Brilliant!
This ability comes from the Rails.vim plugin.
I've got this in my .vimrc:
@duff
duff / gist:332204
Created March 14, 2010 20:16
Autocomplete an entire line
^x^l In insert mode, complete a line
When there's more than one choice use the following to easily select the right one:
^n Get next choice
^p Get previous choice