Skip to content

Instantly share code, notes, and snippets.

@facelessuser
Created December 5, 2022 14:43
Show Gist options
  • Save facelessuser/c7722e552f47965bbe524b6ebbaba46f to your computer and use it in GitHub Desktop.
Save facelessuser/c7722e552f47965bbe524b6ebbaba46f to your computer and use it in GitHub Desktop.
Sublime Wildcard Navigation

Installing

  1. Create folder in Sublime's Packages folder called WildcardNav.
  2. Copy files to created folder.
  3. Run Package Control: Satisfy Dependencies
  4. Restart Sublime Text.

Usage

Command can be run via Wildcard Navigation command from the command palette. Relative patterns will be run using recursive glob logic. For instance, *.py would be run as **/*.py. An absolute pattern would not use implied recursive logic.

Multiple patterns can be used by separating patterns with |. Literal | must be escaped (\|). Negate patterns can be used and are denoted by a leading !. If paired with other patterns, filters out the undesired files from the results. For instance: *.py|!__init__.py would find all Python files exect files **/__init__.py.

Brace expansion and extended glob patterns are enabled by default.

This plugin is built on the Wildcard Match library. Please reference its documentation to better understand the supported glob features.

[
{
"caption": "Wildcard Navigation",
"command": "wildcard_nav"
}
]
{
"*": {
">=3000": [
"wcmatch",
"bracex"
]
}
}
"""
Sublime Text wildcard search plugin.
Copyright (c) 2020 - 2022 Isaac Muse <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import sublime
import sublime_plugin
import os
import re
from wcmatch import glob
import platform
RE_WIN_DRIVE = re.compile(r"(^[A-Za-z]{1}:(?:\\|/))")
class WildcardNavCommand(sublime_plugin.WindowCommand):
"""Wildcard Navigation command."""
def run(self):
"""Run command."""
self.window.show_input_panel('glob', '', self.glob, None, None)
def get_folder_path(self, folder, proj):
"""Get folder path."""
if (
(sublime.platform() == "windows" and RE_WIN_DRIVE.match(folder["path"]) is None and proj is not None) or
(sublime.platform() != "windows" and not folder["path"].startswith("/") and proj is not None)
):
return path.abspath(path.join(path.dirname(proj_file), folder["path"]))
else:
return folder['path']
def glob(self, value):
"""Perform a filesystem glob."""
flags = (
glob.GLOBSTAR | glob.NEGATE | glob.SPLIT | glob.MATCHBASE | glob.NEGATEALL | glob.O |
glob.EXTGLOB | glob.BRACE
)
folders = []
proj = self.window.project_file_name()
self.files = []
for folder in self.window.project_data().get('folders', []):
folder = self.get_folder_path(folder, proj)
self.files.extend([os.path.join(folder, f) for f in glob.glob(value, flags=flags, root_dir=folder)])
if self.files:
self.window.show_quick_panel(
[[os.path.basename(x), x] for x in self.files],
self.check_selection,
0,
0,
self.preview_selection
)
def preview_selection(self, value):
"""Check selection."""
if value > -1:
self.window.open_file(self.files[value], sublime.TRANSIENT)
def check_selection(self, value):
"""Check selection."""
if value > -1:
self.window.open_file(self.files[value])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment