Sublime Forum

Show file modification time

#1

You know, what would be cool? If each file tab would somewhere show me the modification time of this file.

0 Likes

#2

The status bar is a more appropriate place to show that imo. Tabs are crowded.

Both of them can be done with plugin APIs already anyway.

0 Likes

#3

Do you know if there is already a plug-in, which does this?

Well yeah, the status bar is definitely a good place. I didn’t actually mean on the tab when I said that. I just meant that the modification time should be shown somewhere when I click on a file tab.

0 Likes

#4

No. I don’t claim it exists or it doesn’t. I just say it can be done via plugin APIs.

0 Likes

#5

Here’s a simple implementation.

import datetime
import os
import sublime
import sublime_plugin


class ShowFileModifiedTimeListener(sublime_plugin.ViewEventListener):
    def on_activated_async(self):
        file = self.view.file_name()

        try:
            mtime = os.path.getmtime(file)
        except:
            mtime = 0

        self.show_file_modified_time(self.view, mtime)

    def show_file_modified_time(self, view, t):
        if t == 0:
            sublime.status_message("")
            return

        mdate = datetime.datetime.fromtimestamp(t)

        view.set_status("mdate", mdate.strftime("mod: %Y/%m/%d %H:%M:%S"))

5 Likes

Add file date/time to status bar
#6

Man, you are truly awesome :slight_smile: I will try this when I have the chance.

Edit: I tried this and it just works magically. Thanks!

0 Likes

#7

@jfcherng is there a way in this code snippet to control where exactly on the status bar this appears? currently the file modification date/time sits all the way on the lower left (before the line/column indicators). how can this be moved to after the line/column? or somewhere else far to the right on the status bar? status_bar

0 Likes

#8

I don’t think that’s possible.

0 Likes

#9

Status messages are displayed sorted alphabetically by their key name.

Line,Column is provided by core and can’t be moved.

As of ST4 you could however hide it (and replace it with a plugin), which would enable some more control about its location. An example can be found at Line count or percentage in status bar

1 Like