├── .gitignore ├── messages.json ├── Tab Context.sublime-menu ├── Default.sublime-commands ├── Context.sublime-menu ├── README.md ├── messages └── 1.3.0.txt └── PathTools.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "1.3.0": "messages/1.3.0.txt" 3 | } 4 | -------------------------------------------------------------------------------- /Tab Context.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "-" 4 | }, 5 | { 6 | "command": "copy_file_name", 7 | "caption": "Copy File Name" 8 | }, 9 | { 10 | "command": "copy_file_directory", 11 | "caption": "Copy File Directory" 12 | }, 13 | { 14 | "command": "copy_path", 15 | "caption": "Copy File Path" 16 | }, 17 | { 18 | "command": "copy_relative_path", 19 | "caption": "Copy Relative File Path" 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Insert File Path", 4 | "command": "insert_file_path" 5 | }, 6 | { 7 | "caption": "Insert File Directory", 8 | "command": "insert_file_directory" 9 | }, 10 | { 11 | "caption": "Insert File Name", 12 | "command": "insert_file_name" 13 | }, 14 | { 15 | "caption": "Insert Path Relative to Project", 16 | "command": "insert_relative_path" 17 | }, 18 | { 19 | "caption": "Insert Directory Relative to Project", 20 | "command": "insert_relative_directory" 21 | }, 22 | { 23 | "caption": "Copy Path Relative to Project", 24 | "command": "copy_relative_path" 25 | }, 26 | { 27 | "caption": "Copy File Path", 28 | "command": "copy_path" 29 | }, 30 | { 31 | "caption": "Copy File Directory", 32 | "command": "copy_file_directory" 33 | }, 34 | { 35 | "caption": "Copy File Name", 36 | "command": "copy_file_name" 37 | } 38 | ] 39 | -------------------------------------------------------------------------------- /Context.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Path Tools", 4 | "children": [ 5 | { 6 | "caption": "Insert File Path", 7 | "command": "insert_file_path" 8 | }, 9 | { 10 | "caption": "Insert File Directory", 11 | "command": "insert_file_directory" 12 | }, 13 | { 14 | "caption": "Insert File Name", 15 | "command": "insert_file_name" 16 | }, 17 | { 18 | "caption": "Insert Path Relative to Project", 19 | "command": "insert_relative_path" 20 | }, 21 | { 22 | "caption": "Insert Directory Relative to Project", 23 | "command": "insert_relative_directory" 24 | }, 25 | { 26 | "caption": "Copy Path Relative to Project", 27 | "command": "copy_relative_path" 28 | }, 29 | { 30 | "caption": "Copy File Path", 31 | "command": "copy_path" 32 | }, 33 | { 34 | "caption": "Copy File Directory", 35 | "command": "copy_file_directory" 36 | }, 37 | { 38 | "caption": "Copy File Name", 39 | "command": "copy_file_name" 40 | } 41 | ] 42 | } 43 | ] 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Path Tools 2 | 3 | A suite of commands for copying or inserting the current file's path in Sublime Text 2 or 3. 4 | 5 | ## Context Menus 6 | 7 | All commands are available from the regular context menu. The copy commands are made available from the tab context menu. 8 | 9 | ## Command Palette 10 | 11 | You may also run commands directly from the Command Palette. Open the Command Palette (`Ctrl/Super` + `Shift` + `P`) and enter one of the following: 12 | 13 | - Insert File Path 14 | - Insert File Directory 15 | - Insert File Name 16 | - Insert Path Relative to Project 17 | - Insert Directory Relative to Project 18 | - Copy File Path 19 | - Copy File Directory 20 | - Copy File Name 21 | 22 | ## Key Bindings 23 | 24 | Path Tools no longer supplies any default key bindings. Previous versions provided key bindings that conflicted with built-in Sublime Text commands. 25 | 26 | If you wish to add key bindings, you may add them as user overrides by opening `Preferences` -> `Key Bindings - User`. 27 | 28 | ## Installation 29 | 30 | ### Sublime Package Control 31 | 32 | You can install Path Tools using the excellent [Package Control][] package manager for Sublime Text: 33 | 34 | 1. Open "Package Control: Install Package" from the Command Palette (`Ctrl/Super` + `Shift` + `P`). 35 | 2. Select the "Path Tools" option to install Path Tools. 36 | 37 | [Package Control]: http://wbond.net/sublime_packages/package_control 38 | 39 | ### Git Installation 40 | 41 | To install manually using Git, clone to your "Packages" directory. 42 | 43 | ```bash 44 | git clone https://github.com/pjdietz/sublime-path-tools.git "Path Tools" 45 | ``` 46 | -------------------------------------------------------------------------------- /messages/1.3.0.txt: -------------------------------------------------------------------------------- 1 | Path Tools 1.3.0 Change Log 2 | 3 | Default key bindings have been removed as they conflicted with built-in Sublime 4 | Text key bindings. If you wish to add key binds, please add them as user 5 | overrides. 6 | 7 | For reference, the previous default key binding are as follows: 8 | 9 | Linux: 10 | [ 11 | { "keys": ["ctrl+shift+c"], "command": "copy_path" }, 12 | { "keys": ["ctrl+alt+c"], "command": "copy_file_name" }, 13 | { "keys": ["ctrl+alt+shift+c"], "command": "copy_file_directory" }, 14 | { "keys": ["ctrl+shift+v"], "command": "insert_file_path" }, 15 | { "keys": ["ctrl+alt+v"], "command": "insert_file_name" }, 16 | { "keys": ["ctrl+alt+shift+v"], "command": "insert_file_directory" }, 17 | { "keys": [""], "command": "insert_relative_path" }, 18 | { "keys": [""], "command": "insert_relative_directory" } 19 | ] 20 | 21 | OSX: 22 | [ 23 | { "keys": ["super+shift+c"], "command": "copy_path" }, 24 | { "keys": ["super+alt+c"], "command": "copy_file_name" }, 25 | { "keys": ["super+alt+shift+c"], "command": "copy_file_directory" }, 26 | { "keys": ["super+shift+v"], "command": "insert_file_path" }, 27 | { "keys": ["super+alt+v"], "command": "insert_file_name" }, 28 | { "keys": ["super+alt+shift+v"], "command": "insert_file_directory" }, 29 | { "keys": [""], "command": "insert_relative_path" }, 30 | { "keys": [""], "command": "insert_relative_directory" } 31 | ] 32 | 33 | Windows: 34 | [ 35 | { "keys": ["ctrl+shift+c"], "command": "copy_path" }, 36 | { "keys": ["ctrl+alt+c"], "command": "copy_file_name" }, 37 | { "keys": ["ctrl+alt+shift+c"], "command": "copy_file_directory" }, 38 | { "keys": ["ctrl+shift+v"], "command": "insert_file_path" }, 39 | { "keys": ["ctrl+alt+v"], "command": "insert_file_name" }, 40 | { "keys": ["ctrl+alt+shift+v"], "command": "insert_file_directory" }, 41 | { "keys": [""], "command": "insert_relative_path" }, 42 | { "keys": [""], "command": "insert_relative_directory" } 43 | ] 44 | -------------------------------------------------------------------------------- /PathTools.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import sublime 4 | import sublime_plugin 5 | 6 | 7 | class InsertFilePathCommand(sublime_plugin.TextCommand): 8 | 9 | def run(self, edit): 10 | file_path = self.view.file_name() 11 | replace_text_in_selections(self.view, edit, file_path) 12 | 13 | def is_enabled(self): 14 | return bool(self.view.file_name() and len(self.view.file_name()) > 0) 15 | 16 | 17 | class InsertRelativePathCommand(sublime_plugin.TextCommand): 18 | 19 | def run(self, edit): 20 | projectFolders = self.view.window().folders() 21 | self.path = self.view.file_name() 22 | for folder in projectFolders: 23 | if folder in self.view.file_name(): 24 | self.path = self.path.replace(folder, '') 25 | break 26 | replace_text_in_selections(self.view, edit, self.path) 27 | 28 | def is_enabled(self): 29 | if self.view.window().folders(): 30 | return bool(self.view.file_name()) 31 | return False 32 | 33 | 34 | class InsertFileNameCommand(sublime_plugin.TextCommand): 35 | 36 | def run(self, edit): 37 | file_name = os.path.basename(self.view.file_name()) 38 | replace_text_in_selections(self.view, edit, file_name) 39 | 40 | def is_enabled(self): 41 | return bool(self.view.file_name() and len(self.view.file_name()) > 0) 42 | 43 | 44 | class InsertFileDirectoryCommand(sublime_plugin.TextCommand): 45 | 46 | def run(self, edit): 47 | file_directory = os.path.dirname(self.view.file_name()) 48 | replace_text_in_selections(self.view, edit, file_directory) 49 | 50 | def is_enabled(self): 51 | return bool(self.view.file_name() and len(self.view.file_name()) > 0) 52 | 53 | 54 | class InsertRelativeDirectoryCommand(sublime_plugin.TextCommand): 55 | 56 | def run(self, edit): 57 | projectFolders = self.view.window().folders() 58 | self.directory = os.path.dirname(self.view.file_name()) 59 | for folder in projectFolders: 60 | if folder in self.view.file_name(): 61 | self.directory = self.directory.replace(folder, '') 62 | break 63 | replace_text_in_selections(self.view, edit, self.directory) 64 | 65 | def is_enabled(self): 66 | if self.view.window().folders(): 67 | return bool(self.view.file_name()) 68 | return False 69 | 70 | 71 | class CopyFileNameCommand(sublime_plugin.TextCommand): 72 | 73 | def run(self, edit): 74 | file_name = os.path.basename(self.view.file_name()) 75 | sublime.set_clipboard(file_name) 76 | sublime.status_message("Copied file name: %s" % file_name) 77 | 78 | def is_enabled(self): 79 | return bool(self.view.file_name() and len(self.view.file_name()) > 0) 80 | 81 | 82 | class CopyFileDirectoryCommand(sublime_plugin.TextCommand): 83 | 84 | def run(self, edit): 85 | file_directory = os.path.dirname(self.view.file_name()) 86 | sublime.set_clipboard(file_directory) 87 | sublime.status_message("Copied file directory: %s" % file_directory) 88 | 89 | def is_enabled(self): 90 | return bool(self.view.file_name() and len(self.view.file_name()) > 0) 91 | 92 | class CopyRelativePathCommand(sublime_plugin.TextCommand): 93 | 94 | def run(self, edit): 95 | projectFolders = self.view.window().folders() 96 | self.path = self.view.file_name() 97 | for folder in projectFolders: 98 | if folder in self.view.file_name(): 99 | self.path = self.path.replace(folder, '')[1:] 100 | break 101 | sublime.set_clipboard(self.path) 102 | sublime.status_message("Copied file directory: %s" % self.path) 103 | 104 | def is_enabled(self): 105 | return bool(self.view.file_name() and len(self.view.file_name()) > 0) 106 | 107 | def replace_text_in_selections(view, edit, text): 108 | """Replace every selection with the passed text""" 109 | for region in view.sel(): 110 | view.replace(edit, region, text) 111 | --------------------------------------------------------------------------------