├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── Default.sublime-commands ├── Main.sublime-menu ├── generate_uuid.py ├── icon.png └── readme.md /Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+shift+u"], "command": "generate_uuid" }, 3 | { "keys": ["ctrl+shift+y"], "command": "generate_uuid", "args": { "short": true } } 4 | ] -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+shift+u"], "command": "generate_uuid" }, 3 | { "keys": ["ctrl+shift+y"], "command": "generate_uuid", "args": { "short": true } } 4 | ] 5 | -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+shift+u"], "command": "generate_uuid" }, 3 | { "keys": ["ctrl+shift+y"], "command": "generate_uuid", "args": { "short": true } } 4 | ] -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Generate UUID v4", 4 | "command": "generate_uuid" 5 | }, 6 | { 7 | "caption": "Generate single UUID v4", 8 | "command": "generate_uuid", 9 | "args": { "single": true } 10 | } 11 | ] -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "tools", 4 | "caption": "Tools", 5 | "children": 6 | [ 7 | { 8 | "id": "packages", 9 | "caption": "Packages", 10 | "children": 11 | [ 12 | { 13 | "caption": "Generate UUID v4", 14 | "command": "generate_uuid" 15 | }, 16 | { 17 | "caption": "Generate short UUID v4", 18 | "command": "generate_uuid", 19 | "args": { "short": true } 20 | }, 21 | { 22 | "caption": "Generate single UUID v4", 23 | "command": "generate_uuid", 24 | "args": { "single": true } 25 | }, 26 | { 27 | "caption": "Generate single short UUID v4", 28 | "command": "generate_uuid", 29 | "args": { "short": true, "single": true } 30 | } 31 | ] 32 | } 33 | ] 34 | } 35 | ] -------------------------------------------------------------------------------- /generate_uuid.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | import uuid 4 | 5 | class GenerateUuidCommand(sublime_plugin.TextCommand): 6 | """ 7 | Generate a UUID version 4. 8 | Plugin logic for the 'generate_uuid' command. 9 | Searches for "uuid_uppercase" setting in user preferences, capitalizes 10 | UUID if true. 11 | """ 12 | 13 | def run(self, edit, short = False, single = False): 14 | for r, value in zip(self.view.sel(), self.generateUuids(short, single)): 15 | self.view.replace(edit, r, value) 16 | 17 | def generateUuids(self, short, single): 18 | settings = sublime.load_settings('Preferences.sublime-settings') 19 | uppercase = settings.get('uuid_uppercase') 20 | 21 | if single: 22 | value = self.newUuid(uppercase, short) 23 | while True: 24 | yield value 25 | else: 26 | while True: 27 | yield self.newUuid(uppercase, short) 28 | 29 | def newUuid(self, uppercase, short): 30 | value = str(uuid.uuid4()) 31 | if uppercase: 32 | value = value.upper() 33 | if short: 34 | value = value.replace('-', '') 35 | return value 36 | 37 | class GenerateUuidListenerCommand(sublime_plugin.EventListener): 38 | """ 39 | Expand 'uuid' and 'uuid4' to a random uuid (uuid4) and 40 | 'uuid1' to a uuid based on host and current time (uuid1). 41 | Searches for "uuid_uppercase" setting in user preferences, capitalizes 42 | UUID if true. - author Matt Morrison mattdmo@pigimal.com 43 | 44 | Author: Rob Cowie 45 | Seealso: https://github.com/SublimeText/GenerateUUID/issues/1 46 | """ 47 | def on_query_completions(self, view, prefix, locations): 48 | uuid_prefix = '' 49 | _prefix = prefix 50 | if prefix[:2] == '0x': 51 | uuid_prefix = '0x' 52 | prefix = prefix[2:] 53 | 54 | if prefix in ('uuid', 'uuid4'): # random 55 | val = str(uuid.uuid4()) 56 | elif prefix == 'uuid1': # host and current time 57 | val = str(uuid.uuid1()) 58 | elif prefix == 'uuid1s': 59 | val = re.sub('-', '', str(uuid.uuid1())) 60 | elif prefix == 'uuids': 61 | val = re.sub('-', '', str(uuid.uuid4())) 62 | else: 63 | return [] 64 | 65 | settings = sublime.load_settings('Preferences.sublime-settings') 66 | if settings.get('uuid_uppercase'): 67 | val = val.upper() 68 | 69 | return [(_prefix, _prefix, uuid_prefix+val)] if val else [] 70 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SublimeText/GenerateUUID/f4810b94d9d89816b12ba335211bb77a8b8a7724/icon.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Generate UUID package for Sublime Text 2 | 3 | Helper script to generate a UUID v4. Can be executed via keyboard shortcut `Ctrl+Shift+U` (Windows, OSX, and Linux) and or via the menu item `Tools >> Packages >> Generate UUID v4`. 4 | 5 | `Ctrl+Shift+Y' will generate short version of UUID 6 | 7 | ## Installation 8 | 9 | The best way to install this bundle and keep up to date is to install it via [Package Control](https://sublime.wbond.net/installation). Once you have installed Package Control, open it via `Preferences >> Package Control` and click on `Package Control: Install Package`. Type `GenerateUUID` into the search box, then hit enter or click on the result to install. 10 | 11 | ### Using Git 12 | 13 | If you are a git user, you can clone the repo directly into your `Packages` directory in the Sublime Text application settings area. Go to your Sublime Text `Packages` directory and clone the repository using the command below: 14 | 15 | git clone https://github.com/SublimeText/GenerateUUID "GenerateUUID" 16 | 17 | ### Download Manually 18 | 19 | * Download the files using the GitHub .zip download option 20 | * Unzip the files and rename the folder to `Generate UUID` 21 | * Copy the folder to your Sublime Text `Packages` directory 22 | 23 | ## Preferences 24 | 25 | To enable uppercase UUIDs, put the key `"uuid_uppercase": true` in your `Packages/User/Preferences.sublime-settings` file (accessible via the `Preferences >> Settings - User` menu option). If this key is not present, or is set to any other value, UUIDs will be generated in lowercase as before. 26 | 27 | 28 | ## Autocomplete 29 | 30 | * `uuid` + TAB - generates UUID v4 (B50EC8D3-253A-43EC-A285-35FC5BCA7A93) 31 | * `uuid1` + TAB - generates UUID v1 (BFC77674-58AA-11E3-BE8D-8438355C18E4) 32 | * `uuids` + TAB - generates UUID v4 short (D917AE5675F54258B4ECF439329F67C9) 33 | * `uuid1s` + TAB - generates UUID v1 short (D63D476E58AA11E389668438355C18E4) 34 | * `0xuuids` + TAB - for all above possible options we can add a prefix `0x` which generates specific UUID with '0x' in front of --------------------------------------------------------------------------------