Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions recent.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
#!/usr/bin/python3
#!/usr/bin/env python3

import sys
import time

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, Gio

try:
arg = sys.argv[1]
input_file = Gio.File.new_for_path(arg)
if not input_file.query_exists():
print("No such file or directory: %s" % arg)
exit(1)
info = input_file.query_info('time::access', Gio.FileQueryInfoFlags.NONE, None)
info.set_attribute_uint64("time::access", time.time())

gi.require_versions({
'Gtk' : '3.0',
'GLib': '2.0',
})
from gi.repository import Gtk, Gio, GLib


def add_to_recent(file_path):
input_file = Gio.File.new_for_path(file_path)
if not input_file.query_exists(None):
print(f"No such file or directory: {file_path}")
sys.exit(1)

info = input_file.query_info("time::access", Gio.FileQueryInfoFlags.NONE, None)
info.set_attribute_uint64("time::access", int(time.time()))
input_file.set_attributes_from_info(info, Gio.FileQueryInfoFlags.NONE, None)

uri = input_file.get_uri()
rm = Gtk.RecentManager()
rm = rm.get_default()
rm = Gtk.RecentManager.get_default()
rm.add_item(uri)
GObject.idle_add(Gtk.main_quit)

GLib.idle_add(Gtk.main_quit)
Gtk.main()
except IndexError:
exit(0)


def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} filename")
sys.exit(0)

add_to_recent(sys.argv[1])


if __name__ == "__main__":
main()