Permalink
Browse files

add file_exclude_patterns/drives_include_patterns

  • Loading branch information...
s-trooper committed Nov 12, 2012
1 parent 38fe66c commit e80f202905fcacc2093b56078b925e4864110e32
Showing with 35 additions and 10 deletions.
  1. +4 −0 SublimeFiles.sublime-settings
  2. +31 −10 sublime_files.py
@@ -2,4 +2,8 @@
//The command to execute to open a terminal.
//Program will append the directory to open to the end of term_command.
"term_command": "open -a Terminal "
+
+ // Filter for Drives and files
+ // "drives_include_patterns": ["c:\\"],
+ // "file_exclude_patterns": ["*.pyc"]
}
View
@@ -1,13 +1,18 @@
-import sublime, sublime_plugin
-import os, sys, glob
+import sublime
+import sublime_plugin
+import os
+import sys
import subprocess
import shlex
-import locale
+import fnmatch
from subprocess import Popen
bullet = u'\u2022'
+
+
class SublimeFilesCommand(sublime_plugin.WindowCommand):
+
def run(self, command):
try:
self.home
@@ -24,11 +29,19 @@ def run(self, command):
os.chdir(os.getenv(self.home))
self.bookmark = None
self.term_command = settings.get('term_command')
- self.drives = [] # for windows machines
+ self.drives = settings.get('drives_include_patterns', []) # for windows machines
+ self.file_exclude_patterns = settings.get("file_exclude_patterns", [])
if command == 'navigate':
self.open_navigator()
+ def file_match(self, filename):
+ for pattern in self.file_exclude_patterns:
+ if fnmatch.fnmatch(filename, pattern):
+ return True
+
+ return False
+
# function for showing panel for changing directories / opening files
def open_navigator(self):
self.dir_files = ['[' + os.getcwdu() + ']', bullet + ' Directory actions', '..' + os.sep, '~' + os.sep]
@@ -44,10 +57,15 @@ def open_navigator(self):
for element in os.listdir(os.getcwdu()):
fullpath = os.path.join(os.getcwdu(), element)
+
+ if self.file_match(element):
+ continue
+
if os.path.isdir(fullpath):
self.dir_files.append(element + os.sep)
else:
self.dir_files.append(element)
+
self.dir_files = self.dir_files[:4] + sorted(self.dir_files[4:], key=sort_files)
if self.bookmark:
self.dir_files.insert(2, bullet + ' To bookmark (' + self.bookmark + ')')
@@ -58,7 +76,7 @@ def open_navigator(self):
# handles user's selection in open_navigator. cd's into new directory, opens cur dir options, or opens file
def handle_navigator_option(self, call_value):
if call_value != -1:
- option = self.dir_files[call_value];
+ option = self.dir_files[call_value]
if call_value == 0:
self.open_navigator()
elif call_value == 1:
@@ -73,19 +91,19 @@ def handle_navigator_option(self, call_value):
os.chdir(os.path.dirname(self.window.active_view().file_name()))
elif option.startswith(bullet + ' To bookmark'):
os.chdir(self.bookmark)
- else:
+ else:
fullpath = os.path.join(os.getcwdu(), self.dir_files[call_value])
- if os.path.isdir(fullpath): # navigate to directory
+ if os.path.isdir(fullpath): # navigate to directory
os.chdir(self.dir_files[call_value])
- else: # open file
+ else: # open file
self.window.open_file(os.path.join(os.getcwdu(), fullpath))
return
self.open_navigator()
# options for when a user selects current directory
- def open_directory_options(self):
+ def open_directory_options(self):
self.directory_options = [bullet + ' Add folder to project', bullet + ' Create new file',
- bullet + ' Create new directory', bullet + ' Set bookmark here', bullet + ' Back']
+ bullet + ' Create new directory', bullet + ' Set bookmark here', bullet + ' Back']
# terminal opening. only for osx/linux right now
if os.name == 'posix' and self.term_command:
self.directory_options.insert(0, bullet + ' Open terminal here')
@@ -144,6 +162,8 @@ def sort_files(filename):
return total_weight
# hack to add folders to sidebar (stolen from wbond)
+
+
def get_sublime_path():
if sublime.platform() == 'osx':
return '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'
@@ -152,6 +172,7 @@ def get_sublime_path():
else:
return sys.executable
+
def sublime_command_line(args):
args.insert(0, get_sublime_path())
return subprocess.Popen(args)

0 comments on commit e80f202

Please sign in to comment.