Skip to content

Instantly share code, notes, and snippets.

@olivierpichon
Last active August 29, 2015 14:10
Show Gist options
  • Save olivierpichon/9993ea61f1e493b37c37 to your computer and use it in GitHub Desktop.
Save olivierpichon/9993ea61f1e493b37c37 to your computer and use it in GitHub Desktop.
Stash clear for subfolders of provided PATH
#!/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
@olivierpichon
Copy link
Author

example:

./stash_clear.rb .
This will attempt to clear the stash in the following folders:
analytics-visualiser
angular_credit_card
manservant
playbooks

 Proceed? (y/n)

@lucascaton
Copy link

My 2 cents:

  • Put #!/usr/bin/env ruby in the first line
  • Rename your file to stash_clear
  • Change the permission of the file to be executable (chmod +x stash_clear)

Done! Now you can call ./stash_clear

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