Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nemo Tab Restore

日本語版

Nemo Tab Restore is a nemo-python extension that adds browser-like closed-tab restoration to the Nemo file manager.

Tabs closed with Ctrl+W, mouse actions, and similar close operations can be restored with Ctrl+Shift+Y.

Features

  • Saves history for tabs closed with Ctrl+W
  • Saves history for tabs closed with mouse actions or the File menu
  • Restores the most recently closed tab with Ctrl+Shift+Y
  • Supports changing shortcuts
  • Supports configuration through a configuration file or environment variables
  • Supports shared, per-window, or hybrid restore history
  • Supports file-backed or in-memory history

Requirements

In addition to Nemo itself, this extension needs the Python bindings that let Nemo load Python extensions, plus the GI / PyGObject packages used by those bindings. Some distributions pull part of this stack through the Nemo package itself, so the number of extra packages may vary by environment.

Linux Mint

On Linux Mint 22.3 Cinnamon, this extension has been confirmed to work without installing additional packages. In the tested default environment, python-nemo, gir1.2-nemo-3.0, python3-gi, and python3-gi-cairo were already available.

Try the install steps first. If Nemo does not load the extension after restarting, check the related packages:

dpkg -l python-nemo gir1.2-nemo-3.0 python3-gi python3-gi-cairo

Ubuntu family

The following package names are confirmed on Ubuntu 24.04-family systems:

sudo apt install nemo-python gir1.2-nemo-3.0 python3-gi python3-gi-cairo

On Ubuntu-family releases, package names may vary. If installation fails, check the available package names with apt search nemo-python and apt search gir1.2-nemo.

openSUSE Tumbleweed

sudo zypper install python3-nemo typelib-1_0-Nemo-3_0

On Tumbleweed, installing python3-nemo also installs the matching Python GObject packages.

Arch Linux

sudo pacman -S nemo nemo-python

On Arch Linux, installing nemo also installs python-gobject and python-cairo.

Install

Install this extension file into Nemo's Python extension directory.

To install manually:

mkdir -p ~/.local/share/nemo-python/extensions
cp nemo_tab_restore.py ~/.local/share/nemo-python/extensions/nemo_tab_restore.py

A helper script is also available to automate the commands above:

./scripts/install.sh

When run in an interactive terminal, the script asks whether to restart Nemo after installation. Use --restart to restart without prompting, or --no-restart to skip both the prompt and restart. In a non-interactive environment, Nemo is not restarted unless --restart is specified.

./scripts/install.sh --restart
./scripts/install.sh --no-restart

After installing, Nemo must be quit completely and started again. Newly installed extensions are not loaded until Nemo is restarted. If the script did not restart Nemo, run:

nemo -q
nemo &

You can also start Nemo normally from the desktop launcher after quitting it with nemo -q.

Update

If you cloned the repository with Git, fetch the latest version and run the install script again. The script does not modify configuration, history, or logs.

git pull --ff-only
./scripts/install.sh --restart

If you downloaded a release archive or source files, replace them with the new version and run ./scripts/install.sh again. See CHANGELOG.md for version-specific changes and upgrade notes.

Updating to v0.7.0

Starting with v0.7.0, the default restore shortcut changed from Ctrl+Shift+T to Ctrl+Shift+Y. This avoids overriding Nemo's built-in Open in New Tab shortcut.

Explicit shortcut settings in the environment, configuration file, or accelerator file take precedence over the new default. To adopt Ctrl+Shift+Y, unset the environment variable and remove or comment out an existing Ctrl+Shift+T override in the configuration or accelerator file. See Shortcuts for accelerator file candidates.

Uninstall

Remove the installed extension file.

To remove it manually:

rm ~/.local/share/nemo-python/extensions/nemo_tab_restore.py

A helper script is also available to automate the command above:

./scripts/uninstall.sh

As with the install script, you can pass --restart or --no-restart. When run without an option in an interactive terminal, the script asks whether to restart Nemo after removal.

The uninstall script removes only the installed extension file. History and logs are kept.

Usage

Close tab

The extension saves the closed tab URI to history for these close operations:

  • Ctrl+W
  • tab close button
  • middle-click on a tab
  • tab context menu close
  • File menu Close

The URI is saved after Nemo confirms that the tab was actually closed.

Restore last closed tab

Ctrl+Shift+Y

The extension pops the most recently closed URI from history and restores the tab.

Internally, it opens the tab in the existing Nemo window with:

nemo --existing-window --tabs URI

Nemo's menu also includes Restore Last Closed Tab.

Files

Extension install path:

~/.local/share/nemo-python/extensions/nemo_tab_restore.py

History file:

~/.local/share/nemo-tab-restore/closed-tabs.jsonl

This file is not used when the history mode is memory.

Log file:

~/.cache/nemo-tab-restore/nemo-tab-restore.log

Configuration file:

~/.config/nemo-tab-restore/config.env

History, log, and configuration directories are created for owner-only access. Their files are also readable and writable only by the owner.

Configuration

Configuration is done with environment variables or a configuration file. Environment variables are useful for temporary overrides. For persistent settings, use the configuration file so the values do not depend on how Nemo was started.

Priority

Settings listed higher take precedence. For example, if the configuration file and an environment variable specify different values, the environment variable value is used.

environment variables
configuration file
Nemo / GTK accelerator file (shortcuts only)
defaults

Environment Variables

Environment variables are useful when starting Nemo from a terminal to try temporary settings.

NEMO_TAB_RESTORE_RESTORE_SHORTCUT

Sets this extension's restore shortcut.

NEMO_TAB_RESTORE_RESTORE_SHORTCUT=Ctrl+Shift+Y

The default is Ctrl+Shift+Y. To use the browser convention, specify a different shortcut such as Ctrl+Shift+T.

Nemo itself uses Ctrl+Shift+T for Open in New Tab. If you assign the same shortcut, the built-in action may be hidden. See the Shortcuts section below for details.

NEMO_TAB_RESTORE_MAX_HISTORY

Sets the maximum number of closed-tab history entries to keep.

NEMO_TAB_RESTORE_MAX_HISTORY=100

The default is 100, and the maximum is 1000.

NEMO_TAB_RESTORE_HISTORY_MODE

Sets where closed-tab history is stored.

NEMO_TAB_RESTORE_HISTORY_MODE=file
NEMO_TAB_RESTORE_HISTORY_MODE=memory

The default is file. Closed-tab history is saved to ~/.local/share/nemo-tab-restore/closed-tabs.jsonl.

When set to memory, history is kept only in memory while Nemo is running. It is lost when Nemo quits completely, and the history file is not read or written.

NEMO_TAB_RESTORE_HISTORY_SCOPE

Sets how restore history is handled across Nemo windows.

NEMO_TAB_RESTORE_HISTORY_SCOPE=shared
NEMO_TAB_RESTORE_HISTORY_SCOPE=window
NEMO_TAB_RESTORE_HISTORY_SCOPE=hybrid

The default is shared.

shared uses one restore history across all Nemo windows.

window restores only tabs closed in the current window.

hybrid prefers the current window's history. If there is nothing to restore for the current window, history from closed windows and old-format history entries is also considered.

NEMO_TAB_RESTORE_LOG

Configures debug logging.

NEMO_TAB_RESTORE_LOG=true
NEMO_TAB_RESTORE_LOG=false

Use true or false in normal use. Logging is disabled by default when the variable is not set.

Temporary Startup Examples

When starting Nemo from a terminal, place environment variables before the command to apply temporary settings:

NEMO_TAB_RESTORE_LOG=true nemo

You can also set multiple environment variables at once:

NEMO_TAB_RESTORE_LOG=true NEMO_TAB_RESTORE_MAX_HISTORY=300 nemo

Configuration File

The configuration file uses the same names and values as the environment variables above, written as KEY=value.

If the configuration file does not exist, the extension creates it the first time it is loaded. All settings are created as commented-out examples. Uncomment only the settings you want to override.

~/.config/nemo-tab-restore/config.env

When new settings are added in a newer version, existing configuration files are not updated automatically. To regenerate the latest sample, save any settings you still need, delete ~/.config/nemo-tab-restore/config.env, and restart Nemo.

Example:

NEMO_TAB_RESTORE_MAX_HISTORY=300
NEMO_TAB_RESTORE_HISTORY_MODE=memory
NEMO_TAB_RESTORE_HISTORY_SCOPE=hybrid
NEMO_TAB_RESTORE_LOG=true
NEMO_TAB_RESTORE_RESTORE_SHORTCUT=Ctrl+Shift+Y

The configuration file uses a .env-like format. It is not a full shell script.

Supported format:

KEY=value
# comment
blank lines

export, variable expansion, and complex shell quoting or escaping are not supported.

Shortcuts

No shortcut configuration is required by default. Ctrl+W saves closed-tab history, and Ctrl+Shift+Y restores the most recently closed tab.

Nemo assigns Ctrl+Shift+T to <Actions>/DirViewActions/OpenInNewTab, which opens selected items in new tabs. To avoid overriding that built-in action, this extension uses Ctrl+Shift+Y by default.

If you prefer the browser convention, you can assign Ctrl+Shift+T through an environment variable or the configuration file. Nemo's built-in Open in New Tab action will then no longer be available through the same shortcut. See NEMO_TAB_RESTORE_RESTORE_SHORTCUT for details.

To also change Nemo's built-in shortcuts, such as Open in New Tab, you need to edit Nemo / GTK's accelerator file.

If the accelerator file does not exist, you can create this path manually. See Behavior details for other candidate paths.

~/.config/nemo/accels/nemo

Quit Nemo before editing the accelerator file. If Nemo is still running, it may overwrite your changes when it exits.

nemo -q

In GTK accelerator notation, <Primary> usually means the Ctrl key.

Example: change tab restore to Ctrl+Shift+T through the accelerator file:

(gtk_accel_path "<Actions>/NemoTabRestore/RestoreLastClosedTab" "<Primary><Shift>t")

The close shortcut follows Nemo's existing close action (<Actions>/ShellActions/Close). Normally, you do not need to change it.

Syntax Check and Tests

Syntax check:

/usr/bin/python3 -m py_compile nemo_tab_restore.py

Unit tests:

/usr/bin/python3 -m unittest discover -s tests -v

Debugging

Start Nemo with logging enabled:

nemo -q
sleep 1
rm -f ~/.cache/nemo-tab-restore/nemo-tab-restore.log
NEMO_TAB_RESTORE_LOG=true nemo &

Inspect the log:

tail -f ~/.cache/nemo-tab-restore/nemo-tab-restore.log

Expected window hook:

hooked window wid=0x... title='Loading...'
mapped tab page=... uri=file:///...

Known limitations

  • This extension restores closed tabs individually when requested. It does not manage Nemo sessions or restore the tabs that were open when Nemo last exited.
  • Tracking tab closes from mouse actions can depend on the Nemo version, theme, and GTK widget structure. If it does not work in a given environment, keyboard shortcut closes are still tracked.
  • When closing an inactive tab with a mouse action or opening its context menu, the extension may briefly switch to that tab to capture its URI. It switches back to the previously active tab after capturing the URI.
  • This is a Nemo extension, not a Nautilus or Caja extension.

Troubleshooting

No module named 'gi'

Nemo Python extensions use GI / PyGObject.

Nemo loads Python extensions with the distribution Python environment. If another Python installation is first in PATH, gi may fail to import even though it works with the distribution Python.

Check:

which -a python3
python3 --version
python3 -c 'import gi; print(gi.__file__)'

Expected example:

/usr/bin/python3
/usr/lib/python3/dist-packages/gi/__init__.py

When debugging GI import problems, check the distribution Python directly:

/usr/bin/python3 -c 'import gi; print(gi.__file__)'

Behavior details

  • The close shortcut marks the current tab as a close candidate. Its URI is saved only after Nemo's normal close action actually removes the tab.
  • The restore shortcut pops a URI from history and opens it in the existing Nemo window.
  • Each key press is handled separately, matching browser-like behavior.
  • Consecutive duplicate URIs are not suppressed. The same folder can legitimately be open in multiple tabs.
  • URIs are tracked per notebook page, so the closed page is identified correctly across multiple windows and F3 split panes.
  • When closing an inactive tab with a mouse action before its URI is known, the extension briefly switches to that tab to capture the URI, then returns to the previously active tab after the close.
  • With NEMO_TAB_RESTORE_HISTORY_SCOPE=shared, closed-tab history is shared rather than tracked per window.
  • When NEMO_TAB_RESTORE_HISTORY_SCOPE=window is combined with NEMO_TAB_RESTORE_HISTORY_MODE=file, history from old windows remains in the history file but is not restored from the current window. If needed, switch to shared or hybrid to make those entries eligible for restore.
  • With NEMO_TAB_RESTORE_HISTORY_SCOPE=hybrid, history from other currently open Nemo windows is not used as fallback restore history.

The accelerator file location can vary by distribution and Nemo / GTK version. The extension checks these candidates:

$XDG_CONFIG_HOME/nemo/accels/nemo
$XDG_CONFIG_HOME/gtk-3.0/accels/nemo
~/.config/nemo/accels/nemo
~/.gnome2/accels/nemo
~/.config/gtk-3.0/accels/nemo

$XDG_CONFIG_HOME paths are checked first when the variable is set and non-empty.

License

MIT License. See LICENSE.

About

Browser-like closed-tab restoration for the Nemo file manager.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages