Since I have to juggle between several projects on my typical day job, it would be nice if I can see which branch I am on in a git repository. I figured it out just a single line in my .bashrc:
local GIT='$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "($(git branch | grep '^*' |sed s/\*\ //))"; fi)'
Then add it to your prompt:
PS1="\u$....${GIT}${NONE}\$ "
Now I get:
~/Projects/spice-workspace/spice2(master)$ git checkout develop
~/Projects/spice-workspace/spice2(develop)$
Very cool!
Nov 11, 2008
link_to_action with confirmation
I like Merb, it gives you the best flexibility to extends or hack by yourself. Unlike Rails which gives you every thing that you might need, in merb some of the basic features may need polished. For example, the helper plugin have the delete_button helper method, it deletes the record without get any confirmation. Some times in my app, I want get the user's confirmation first. This is easy, implement your own helper method. There might be a better way to do this, but this works for me:
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
# create a link to an action. A confirm box will pop up before | |
# you can process to action specified here. | |
# link_to_action "Delete", "Are you sure?", :method => 'delete', | |
# :class => "negative", :controller => 'price_letters', | |
# :action => 'destroy', :id => letter.id | |
# link_to_action "Effect Now", "Take effect now, and can not be reversed?", | |
# :controller => "price_letters", :action => 'effect_now', :id => letter.id | |
def link_to_action(link_text, msg = "Are you sure", attributes = {}) | |
content = (msg || "Are you sure?") | |
attrs = { :method => 'post' } | |
attrs = attrs.merge(attributes) | |
%{<a href="/#{attrs[:controller]}/#{attrs[:action]}/#{attrs[:id]}" | |
onclick="if (confirm('#{content}')) | |
{ | |
var f = document.createElement('form'); | |
f.style.display = 'none'; | |
this.parentNode.appendChild(f); | |
f.method = 'POST'; | |
f.action = this.href; | |
var m = document.createElement('input'); | |
m.setAttribute('type', 'hidden'); | |
m.setAttribute('name', '_method'); | |
m.setAttribute('value', '#{attrs[:method]}'); | |
f.appendChild(m);f.submit(); | |
} | |
return false;" class="#{attrs[:class]}">#{link_text}</a>} | |
end |
Nov 10, 2008
Git
I was having a problem with my git add -i command, here is the error message:
Can't locate Error.pm in @INC (@INC contains: /opt/local/lib/perl5/site_perl/5.8.8 /System/Lib....
After playing with it for a while, I finally find that when I use mac port to install the git-core, it failed to copy the Error.pm file to the working directory. Here is how to fix it:
$sudo cp /opt/local/lib/perl5/vendor_perl/5.8.8/Error.pm /opt/local/lib/perl5/site_perl/5.8.8/.
I am hoping this could save someone sometime to find the answer.
Can't locate Error.pm in @INC (@INC contains: /opt/local/lib/perl5/site_perl/5.8.8 /System/Lib....
After playing with it for a while, I finally find that when I use mac port to install the git-core, it failed to copy the Error.pm file to the working directory. Here is how to fix it:
$sudo cp /opt/local/lib/perl5/vendor_perl/5.8.8/Error.pm /opt/local/lib/perl5/site_perl/5.8.8/.
I am hoping this could save someone sometime to find the answer.
Subscribe to:
Posts (Atom)