Skip to content

Instantly share code, notes, and snippets.

@sidonath
Created June 22, 2009 22:54
Show Gist options
  • Select an option

  • Save sidonath/134242 to your computer and use it in GitHub Desktop.

Select an option

Save sidonath/134242 to your computer and use it in GitHub Desktop.
# Append to ~/.profile (or ~/.bashrc)
# append to history, not overwrite
shopt -s histappend
# append command to history file before it's executed
export PROMPT_COMMAND="history -a"
# ignore duplicate consecutive commands
export HISTCONTROL=ignoreboth
# thanks to:
# http://www.linuxforums.org/forum/linux-programming-scripting/109516-retaining-bash-history-all-sessions.html
# and
# http://www.ducea.com/2006/05/15/linux-tips-take-control-of-your-bash_history/
#!/usr/bin/env ruby
def exec_undo(line)
line.gsub! 'script/generate', 'script/destroy'
puts "Execute command \"#{line}\"? (yN)"
if (gets.chomp.downcase == 'y')
puts line
system line
end
end
history = '~/.bash_history'
lines = File.readlines(File.expand_path(history)).reverse
lines.each do |l|
if l =~ /script\/generate/
exec_undo l.chomp
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment