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"))

4 Likes

#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