Guest User

Untitled

a guest
Nov 20th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. from subprocess import getoutput
  3. import re
  4.  
  5.  
  6. def main():
  7. branches_dict = branches()
  8. save_nums = input('type branch numbers to NOT delete, seperated by spaces\n')
  9. save_nums = map(int, re.findall(r'\d+', save_nums))
  10. for num in save_nums:
  11. branches_dict.pop(num)
  12. for k, v in branches_dict.items():
  13. print(k, v)
  14. input('will delete these, press ctrl-c to stop, otherwise return...')
  15. for branch in branches_dict.values():
  16. getoutput('git branch -D ' + branch)
  17. return branches_dict
  18.  
  19.  
  20. def branches():
  21. branches = getoutput('git branch').split('\n')
  22. branches = [b for b in branches if 'master' not in b]
  23. return print_branches_return_dict(branches)
  24.  
  25.  
  26. def print_branches_return_dict(branches):
  27. branch_dict = {}
  28. for i, b in enumerate(branches):
  29. if i < 10:
  30. print(i, '', b)
  31. else:
  32. print(i, b)
  33. branch_dict[i] = b
  34. return branch_dict
  35.  
  36.  
  37. if __name__ == '__main__':
  38. main()
Add Comment
Please, Sign In to add comment