是否可以在 Sublime 侧边栏中的文件名旁边显示文件大小?
Is it possible to show the size of files next to the file names inside Sublime sidebar?
我 运行 一个在特定文件夹中生成和更新大量文件的应用程序。在应用程序 运行s 时,我通过 sublime 侧边栏观察文件夹的内容。因为我有兴趣在应用程序 运行s 时查看每个文件的当前大小,所以我有一个打开的终端 (Mac),我在其中使用以下命令来获取文件夹的实时状态。
watch -d ls -al -h folderName
我想知道是否可以直接从 sublime 获取这些信息。
所以我的问题是:是否可以在 sublime 侧边栏中的文件名旁边显示每个文件的大小?如果是,怎么做?
由于侧边栏在官方中没有API,我认为这是不可能的或者至少是不容易的。
然而,将信息转化为 sublime text 很容易。您可以使用视图对其进行存档。只需执行 ls
命令并将结果写入视图即可。
我为此写了一个小插件(ST3):
import subprocess
import sublime
import sublime_plugin
# change to whatever command you want to execute
commands = ["ls", "-a", "-s", "-1", "-h"]
# the update interval
TIMEOUT = 2000 # ms
def watch_folder(view, watch_command):
"""create a closure to watch a folder and update the view content"""
window = view.window()
def watch():
# stop if the view is not longer open
open_views = [v.id() for v in window.views()]
if view.id() not in open_views:
print("closed")
return
# execute the command and read the output
output = subprocess.check_output(watch_command).decode()
# replace the view content with the output
view.set_read_only(False)
view.run_command("select_all")
view.run_command("insert", {"characters": output})
view.set_read_only(True)
# call this function again after the interval
sublime.set_timeout(watch, TIMEOUT)
return watch
class WatchFolderCommand(sublime_plugin.WindowCommand):
def run(self):
folders = self.window.folders()
if not folders:
sublime.error_message("You don't have opened any folders")
return
folder = folders[0] # get the first folder
watch_command = commands + [folder]
# create a view and set the desired properties
view = self.window.new_file()
view.set_name("Watch files")
view.set_scratch(True)
view.set_read_only(True)
view.settings().set("auto_indent", False)
# create and call the watch closure
watch_folder(view, watch_command)()
只需打开 User
文件夹(或 Packages 的任何其他子文件夹),创建一个 python 文件(例如 watch_folder.py
)并粘贴源代码。
您可以通过将以下内容粘贴到您的键映射来将其绑定到键绑定:
{
"keys": ["ctrl+alt+shift+w"],
"command": "watch_folder",
},
我 运行 一个在特定文件夹中生成和更新大量文件的应用程序。在应用程序 运行s 时,我通过 sublime 侧边栏观察文件夹的内容。因为我有兴趣在应用程序 运行s 时查看每个文件的当前大小,所以我有一个打开的终端 (Mac),我在其中使用以下命令来获取文件夹的实时状态。
watch -d ls -al -h folderName
我想知道是否可以直接从 sublime 获取这些信息。
所以我的问题是:是否可以在 sublime 侧边栏中的文件名旁边显示每个文件的大小?如果是,怎么做?
由于侧边栏在官方中没有API,我认为这是不可能的或者至少是不容易的。
然而,将信息转化为 sublime text 很容易。您可以使用视图对其进行存档。只需执行 ls
命令并将结果写入视图即可。
我为此写了一个小插件(ST3):
import subprocess
import sublime
import sublime_plugin
# change to whatever command you want to execute
commands = ["ls", "-a", "-s", "-1", "-h"]
# the update interval
TIMEOUT = 2000 # ms
def watch_folder(view, watch_command):
"""create a closure to watch a folder and update the view content"""
window = view.window()
def watch():
# stop if the view is not longer open
open_views = [v.id() for v in window.views()]
if view.id() not in open_views:
print("closed")
return
# execute the command and read the output
output = subprocess.check_output(watch_command).decode()
# replace the view content with the output
view.set_read_only(False)
view.run_command("select_all")
view.run_command("insert", {"characters": output})
view.set_read_only(True)
# call this function again after the interval
sublime.set_timeout(watch, TIMEOUT)
return watch
class WatchFolderCommand(sublime_plugin.WindowCommand):
def run(self):
folders = self.window.folders()
if not folders:
sublime.error_message("You don't have opened any folders")
return
folder = folders[0] # get the first folder
watch_command = commands + [folder]
# create a view and set the desired properties
view = self.window.new_file()
view.set_name("Watch files")
view.set_scratch(True)
view.set_read_only(True)
view.settings().set("auto_indent", False)
# create and call the watch closure
watch_folder(view, watch_command)()
只需打开 User
文件夹(或 Packages 的任何其他子文件夹),创建一个 python 文件(例如 watch_folder.py
)并粘贴源代码。
您可以通过将以下内容粘贴到您的键映射来将其绑定到键绑定:
{
"keys": ["ctrl+alt+shift+w"],
"command": "watch_folder",
},