Skip to content

Instantly share code, notes, and snippets.

@dreua
Last active February 23, 2024 23:23
Show Gist options
  • Save dreua/2e399ffcfb42c4b6932de73a5ad5f268 to your computer and use it in GitHub Desktop.
Save dreua/2e399ffcfb42c4b6932de73a5ad5f268 to your computer and use it in GitHub Desktop.
Simple instructions for adding a shortcut to nautilus which opens a terminal at the current location

I copied this from "RobotMan" on http://askubuntu.com/a/696901

I added a new feature to Nautilus with the precious help of the maintainers.

This new feature allow you to map custom keyboard shortcuts to launch the scripts in the scripts folder ( ~/.local/share/nautilus/scripts ).

So, when you add an executable in that folder it will appear in the right-click context menu, but now if you create a special configuration file ( ~/.config/nautilus/scripts-accels ) you can assign a shortcut to it.

For example make a script called Terminal with the following content:

#! /bin/sh
gnome-terminal

Now create (or edit) the ~/.config/nautilus/scripts-accels file adding the following line:

F4 Terminal

Restart Nautilus and when you'll press F4 key you'll open a new terminal window in the current directory.

Note: if you select one or more files, their names will be passed as parameters to the executable. Your script can also have access to many information through environment variables.

Link of the commit: https://git.gnome.org/browse/nautilus/commit/?id=9fe1335

There is also a gui to manage these shortcuts: https://github.com/echo-devim/nautilusaccelsmanager

@pietro-coretto
Copy link

pietro-coretto commented Aug 26, 2022

Did you remember to:

Quit all Nautilus instances with nautilus -q

Other than looking at journalctl --follow while trying the shortcuts I have no ideas at the top of my head. Are you using nautilus as a snap or flatpak? Does the script work when invoked via context menu -> scripts?

Yes I did. However after deleting everything and redoing it... now it works! Don't know why!

@pietro-coretto
Copy link

in ~/.config/nautilus/scripts-accels how do I assign shortcuts like this?

Superkey + T
Ctrl + Shift + T
Ctrl + Alt + T

@pietro-coretto
Copy link

I tried the trick you suggested above but when folders contain spaces it doesn't work. It just opens the terminal into the last folder in the path not having spaces. Moreover if I select more than one file it just don't do any action.

@dreua
Copy link
Author

dreua commented Aug 26, 2022

I use <Primary>b as shortcut (b like Bash)

This is Ctrl + B which works fine for me. Super will probably be handled by the Window manager as a global shortcut so I'd recommend something simple.

@cfgnunes
Copy link

cfgnunes commented Jun 20, 2023

Thanks, @dreua!!! I did not know about this feature!!!

Now, I can access my scripts (https://github.com/cfgnunes/nautilus-scripts) using the keyboard! 😊

Moreover, I will configure to open the VSCode in the current directory more easily!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment