执行命令:
sudo apt-get install python3-gi python-nautilus
mkdir -p ~/.local/share/nautilus-python/extensions
gedit ~/.local/share/nautilus-python/extensions/nautilus-acme.py
然后,复制下面的内容到这个python文件中:
from os.path import join
from gi.repository import GObject, Nautilus
class Acme(GObject.GObject, Nautilus.MenuProvider):
def __init__(self):
pass
def new_empty_file(self, menu, folder):
with open(join(folder.get_uri().replace("file://", ""), "new_file"), 'w') as f:
f.write('')
return
def get_background_items(self, window, current_folder):
AcmeMenuItem = Nautilus.MenuItem(
name="Acme::NewEmptyFile",
label="New empty file",
tip="New empty file"
)
AcmeMenuItem.connect('activate', self.new_empty_file, current_folder)
return [AcmeMenuItem]
然后重启Nautilus。
执行:nautilus -q,就OK啦。