Created
June 8, 2017 21:52
-
-
Save drosenstark/9a48dde5b7159c32adead7d8f05fda16 to your computer and use it in GitHub Desktop.
Choose a git stash to apply (or other operation)
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
git stash save STASHNAME
to save, of course.