Created
August 3, 2018 14:23
-
-
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
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/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!') |
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
Original gist with no nested bookmarks support: https://gist.github.com/NattyBumppo/a428a3f5985c8fb391523c09ad09be97/