Sublime Forum

Does anything like Atom's nice-index exist for Sublime

#1

I’m referencing this plugin. Basically, if you have foo/index.js open, the tab will display foo/ instead of index.js.

Does an equivalent exist for Sublime. If not, could anyone give me some pointers on how I can start implementing it (still a novice with plugins)?

It seems to me that the key here is to be able to calculate the tab name based on the path of the file.

0 Likes

#2

I’m pretty sure ST plugins can’t change the name of a tab that holds a file reference - unsaved tabs only can be named

0 Likes

#3

If you’re ok with the fact that you wouldn’t be able to edit the file (at least without triggering the “save as…” box), you could make a plugin that reads the file content from disk, opens an empty view, pastes the content, sets the name that you want (it would become the tab’s name) and marks it as scratch. Then you would have what you ask more ore less. You could also add a symbol prefix to the tab name to increase visibility.

0 Likes

#4

This should do it:

import sublime_plugin
import os
import re

class NiceIndexListener(sublime_plugin.EventListener):

    def on_load(self, view):

        fname = os.path.basename(view.file_name())
        basename, ext = os.path.splitext(fname)
        if basename == 'index' and ext in ['.js', '.html', '.jsx']:
            dir = os.path.dirname(view.file_name())
            dir = "/" + re.sub(r".*" + re.escape(os.sep), "", dir)
            view.set_name(dir)
            view.set_scratch(True)
0 Likes

#5

Thanks for the suggestions, everyone. Unfortunately, it won’t be useful if you can’t edit the file. Thanks for the info, though.

0 Likes