Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific icons for each file type #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.dired" },
{ "key": "setting.dired_rename_mode", "operand": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[≡▸▾]\\s*$|^\\s*$|^⠤.*$"}
{ "key": "preceding_text", "operator": "regex_contains", "operand": "[≡▸▾]\\s*$|^\\s*$|^\\s*\\S\\s$|^⠤.*$"}
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,16 @@ def prepare_filelist(self, names, path, goto, indent):
files = []
index_dirs = []
index_files = []
icons = sublime.load_settings('dired.sublime-settings').get('dired_icons', {})
for name in names:
full_name = join(path, goto, name)
if isdir(full_name):
index_dirs.append(u'%s%s' % (full_name, os.sep))
items.append(''.join([level, u"▸ ", name, os.sep]))
else:
index_files.append(full_name)
files.append(''.join([level, u"≡ ", name]))
icon = icons.get(name.split('.')[-1], '≡')
files.append(''.join([level, icon, ' ', name]))
index = index_dirs + index_files
self.index = self.index[:self.number_line] + index + self.index[self.number_line:]
items += files
Expand Down Expand Up @@ -535,7 +537,7 @@ def _find_in_view(self, item):
pattern = u'^\s*[▸▾] '
sep = re.escape(os.sep)
else:
pattern = u'^\s* '
pattern = r'^\s*\S '
sep = ''
return self.view.find_all(u'%s%s%s' % (pattern, fname, sep))

Expand Down
2 changes: 1 addition & 1 deletion dired.hidden-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<dict>
<key>match</key>
<string>^(\s*)( )(\S.*?(\.[^\.\n]+)?)$</string>
<string>^(\s*)(\S )(\S.*?(\.[^\.\n]+)?)$</string>
<key>name</key>
<string>dired.item.file</string>
<key>captures</key>
Expand Down
15 changes: 13 additions & 2 deletions dired.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def traverse_tree(self, root, path, indent, tree, expanded):
tree[~0] += '\t<empty>'
return

icons = sublime.load_settings('dired.sublime-settings').get('dired_icons', {})
files = []
index_files = []
for f in items:
Expand All @@ -304,7 +305,10 @@ def traverse_tree(self, root, path, indent, tree, expanded):
tree.append(u'%s▸ %s%s' % (indent, f.rstrip(os.sep), os.sep))
else:
index_files.append(new_path)
files.append(u'%s≡ %s' % (indent, f))
icon = icons.get(f.split(".")[-1], "≡")
# Ensure icon are 1 char long
icon = icon[0]
files.append(u'%s%s %s' % (indent, icon, f))

self.index += index_files
tree += files
Expand Down Expand Up @@ -681,6 +685,9 @@ def apply_change_into_view(self, edit, line, indented_region):
end_line = start_line + removed_count
self.index = self.index[:start_line] + self.index[end_line:]
v.settings().set('dired_index', self.index)
else:
# I'm not sure this is the right behavior.
start_line = 1 + v.rowcol(line.a)[0]

if self.marked or self.seled:
path = self.path
Expand All @@ -691,7 +698,11 @@ def apply_change_into_view(self, edit, line, indented_region):
self.seled[0].append(folded_name)

name_point = self._get_name_point(line)
icon_region = Region(name_point - 2, name_point - 1)
if v.substr(name_point) == "▾":
# I'm not sure why but sometimes get_name_point returns the icon
icon_region = Region(name_point, name_point + 1)
else:
icon_region = Region(name_point - 2, name_point - 1)

v.set_read_only(False)
v.replace(edit, icon_region, u'▸')
Expand Down
5 changes: 5 additions & 0 deletions dired.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
// Only for OSX and Linux.
"dired_dup_separator": " — ",

// Map file extensions to a specific icon.
// Works best with an extended font from https://www.nerdfonts.com/
// Example: "dired_icons": { "json": "", "md": "", "py": "", "zip": ""},
"dired_icons": {},

// Automatically disable Vintageous to avoid keybindings incompatibilities;
// note it is Vintageous setting, if it does not work you should report into
// appropriate repository https://github.com/guillermooo/Vintageous/issues
Expand Down
2 changes: 1 addition & 1 deletion dired.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contexts:
3: string.name.directory.dired
4: punctuation.definition.directory.slash.dired
5: string.error.dired
- match: '^(\s*)( )(\S.*?(\.[^\.\n]+)?)$'
- match: '^(\s*)(\S )(\S.*?(\.[^\.\n]+)?)$'
scope: dired.item.file
captures:
1: indent
Expand Down
7 changes: 5 additions & 2 deletions dired_file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def run(self, edit):
before = self.view.settings().get('rename')
# We marked the set of files with a region. Make sure the region still has the same
# number of files.
after = self.get_after()
after = self.get_after()

if len(after) != len(before):
return sublime.error_message('You cannot add or remove lines')
Expand All @@ -276,7 +276,10 @@ def get_after(self):
self.index = self.get_all()
path = self.path
lines = self._get_lines(self.view.get_regions('rename'), self.fileregion())
return [self._new_name(line, path=path) for line in lines]
lines = [self._new_name(line, path=path) for line in lines]
assert '[RENAME MODE]' in lines[0], "Please don't edit the header '[RENAME MODE]' '" + lines[0] + "'"
lines = lines[1:]
return lines

def _new_name(self, line, path=None, full=False):
'''Return new name for line
Expand Down