-
-
Save NattyBumppo/a428a3f5985c8fb391523c09ad09be97 to your computer and use it in GitHub Desktop.
A script to alphabetize SourceTree repository bookmarks by name
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
import xml.etree.ElementTree as ET | |
# Modify this line to match the path on your own system | |
bookmarks_filename = 'C:\\Users\\natguy\\AppData\\Local\\Atlassian\\SourceTree\\bookmarks.xml' | |
def get_name(elem): | |
return elem.findtext("Name").lower() | |
tree = ET.parse(bookmarks_filename) | |
root = tree.getroot() | |
treeViewNodes = tree.findall("TreeViewNode") | |
for t in treeViewNodes: | |
root.remove(t) | |
treeViewNodes[:] = sorted(treeViewNodes, key=get_name) | |
for t in treeViewNodes: | |
root.append(t) | |
print('Bookmarks sorted!') | |
tree.write(bookmarks_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment