Sublime Forum

Relative Path in Title Bar

#1

Is it possible to show the relative path to a file in the title bar? Showing only the file name can be confusing when working with similarly named files in different folders and showing the full path seems to be a waste of when I only care about the end.

0 Likes

#2

As far as I know this isn’t possible. One issue with attempting to implement something like this (that I could think of) is relative to what? Though not in the title bar, a plugin to display some subsection of the path in the status bar is doable. Maybe that would suffice for what you need?

0 Likes

#3

It could be relative to the folder that has been added to the project.

0 Likes

#4

It ain’t impossible. I’ve had “Subethaedit + Transmit” working this way.
I’m searching for this aswell… There is a possibility to “activate” the path but what you get is something like this;
“~/Library/Caches/Cleanup At Startup/Transmit/BAE7A76C-116F-644F-8487-7B381FB6FFCF/file.php”

While in the previous situation (Subethaedit + Transmit) it was something like this;
ftp://domain-name.com:21//domains/domain-name.com/public_html/path/file.php

I hope a developer reads this, because this extra feature will be so helpful. I’ve had a few encounters where i accidentally edited the wrong website :mrgreen:

0 Likes

#5

Yes, part of the issue is that sublime doesn’t have or expose the notion of current working directory (CWD). That notion partially conflicts with the idea of “project folders”; since you can have >1 project folder, which is the CWD? One solution would be to have the CWD for a buffer’s editing session to be it’s containing project folder, but that has issues when the file is in >1 project folder, or one project folder is nested in another.

Another option is to have the CWD as the directory that sublime is launched from. Some editors have the notion of CWD, and some have a console/commandline which allows it to be changed with a CD command.

In Sublime’s “intuitive-land”, I would favour the approach of the CWD being containing project folder, with some caveats for the multiple project folder scenario above. The CWD for a file that doesn’t belong to a project folder would be the launch dir, and it would be nice to have a Sublime console command to change/show the CWD as well.

S

0 Likes

#6

Something like this?

import sublime, sublime_plugin
import os

class ExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        # check if the current path is in one of the project folders.
        # If yes, then return the relative path of the current file.
        for path in sublime.active_window().folders():
            project_path = os.path.normpath(path)
            file_path = os.path.normpath(sublime.active_window().active_view().file_name())

            relative_path = file_path
            if file_path.startswith(project_path):
                relative_path = file_path.replace(project_path, '...')
                break

        print 'relative_path = %s' % (relative_path)

This just prints out the relative path of the active view, so it would need some work to display it somewhere (not sure where ). It also isn’t correctly using self.view but I couldn’t be bothered to change it (this was more of a proof of concept).

0 Likes

#7

jbjornson, that’s excellent and exactly what I would expect. (well, almost: I would replace $HOME with ~/ and leave relative paths relative instead of adding …/. Like you say, proof of concept)

There’s TONS of room in the window title bar. It would be excellent to put this info up there. +1!

0 Likes

#8

Unfortunately I’m not aware of anything in the API that allows you to change the window title bar text…

@jps Jon, if you are reading this, maybe this could be a candidate for inclusion in the API?

0 Likes

#9

Will this method do what you need?

http://www.treyconnell.com/show-file-path-sublime-text-2/

0 Likes

#10

Will there be any chance if the changing window title can be implemented in plugin API?

0 Likes