Skip to content

Instantly share code, notes, and snippets.

@RaynLegends
Created August 3, 2018 14:23
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 RaynLegends/21f780784e18786a0ef1b33e816a1600 to your computer and use it in GitHub Desktop.
Save RaynLegends/21f780784e18786a0ef1b33e816a1600 to your computer and use it in GitHub Desktop.
Sort SourceTree repositories by name, since there's no option in the gui - Also works with nested folders
#!/usr/bin/python3
import xml.etree.ElementTree as ET
# Modify this line to match the path on your own system
file = 'C:\\Users\\USER\\AppData\\Local\\Atlassian\\SourceTree\\bookmarks.xml'
def get_name(elem):
return elem.findtext("Name").lower()
def is_folder(node):
type = node.attrib['{http://www.w3.org/2001/XMLSchema-instance}type']
return type == 'BookmarkFolderNode'
def sort(tree):
treeViewNodes = tree.findall("TreeViewNode")
for node in treeViewNodes:
if is_folder(node):
children = node.find("Children")
sort(children)
tree.remove(node)
treeViewNodes[:] = sorted(treeViewNodes, key=get_name)
for node in treeViewNodes:
tree.append(node)
tree = ET.parse(file)
sort(tree.getroot())
tree.write(file)
print('Bookmarks sorted!')
@RaynLegends
Copy link
Author

Original gist with no nested bookmarks support: https://gist.github.com/NattyBumppo/a428a3f5985c8fb391523c09ad09be97/

@bretski00
Copy link

Thanks, just what I was looking for!

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