Last active
August 29, 2015 14:10
-
-
Save olivierpichon/9993ea61f1e493b37c37 to your computer and use it in GitHub Desktop.
Stash clear for subfolders of provided PATH
This file contains hidden or 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 | |
def no_folder | |
Kernel.abort 'No Folder provided. Exiting...' | |
end | |
def prompt(*args) | |
print(*args) | |
gets.strip | |
end | |
def clear_stash(folder) | |
puts 'clearing stash for folder ' + folder | |
cmd = "cd #{folder} && git stash clear" | |
`#{cmd}` | |
end | |
if ARGV.length > 0 | |
path = ARGV.first.chomp | |
ARGV.clear | |
no_folder unless File.directory? path | |
folders = Dir.entries(path).select {|entry| File.directory? File.join(path,entry) and !(entry =='.' || entry == '..') } | |
proceed = false | |
while !['y','n'].include?(proceed) | |
proceed = prompt("This will attempt to clear the stash in the following folders: \n" + folders.join("\n") + "\n\n Proceed? (y/n)") | |
if proceed == 'y' | |
folders.map{|folder| File.absolute_path(folder)}.each{|folder| clear_stash(folder)} | |
end | |
end | |
else | |
no_folder | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My 2 cents:
#!/usr/bin/env ruby
in the first linestash_clear
chmod +x stash_clear
)Done! Now you can call
./stash_clear