Skip to content

Instantly share code, notes, and snippets.

@drosenstark
Created June 8, 2017 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drosenstark/9a48dde5b7159c32adead7d8f05fda16 to your computer and use it in GitHub Desktop.
Save drosenstark/9a48dde5b7159c32adead7d8f05fda16 to your computer and use it in GitHub Desktop.
Choose a git stash to apply (or other operation)
#!/usr/bin/env ruby
#git-stash-pick by Dan Rosenstark
# can take a command, default is apply
command = ARGV[0]
if !command
command = "apply"
puts "Using git stash #{command}.\nYou can choose a different command, e.g., git stash-pick pop"
end
ARGV.clear
stashes = []
stashNames = []
`git stash list`.split("\n").each_with_index { |line, index|
lineSplit = line.split(": ");
puts "#{index+1}. #{lineSplit[2]}"
stashes[index] = lineSplit[0]
stashNames[index] = lineSplit[2]
}
print "Choose Stash or ENTER to exit: "
input = gets.chomp
if input.to_i.to_s == input
realIndex = input.to_i - 1
puts "\n\nDoing #{command} to #{stashNames[realIndex]}\n\n"
puts `git stash #{command} #{stashes[realIndex]}`
end
@drosenstark
Copy link
Author

You could use git stash-pick drop to remove 'em, too. Fun and safe!

@drosenstark
Copy link
Author

Use git stash save STASHNAME to save, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment