Scenario:
- I am on my Desktop.
- I perform a right mouse click and select "Open in terminal".
- I envision this to open the terminal in
~/Desktop
and not my home folder.
System:
- Ubuntu 16.10
- Unity
- Nautilus
Scenario:
~/Desktop
and not my home folder.System:
Desktop
, click Make link
. You will be presented with Link to Desktop
file.Open in Terminal
it will open terminal with current working directory set as desktop.A quick & easy one coincidentally, since I only needed to change a script I already had a bit :).
The script assumes you have at least one item on your desktop though.
~/.local/share/nautilus/scripts
terminal_here2
(no extension), and make it executableNow right-click on any file on your desktop, choose Scripts --> open_terminal2:
and a terminal window will open in the desktop's directory ("Bureaublad" in my case)
#!/usr/bin/env python3
import subprocess
import os
def replace(path):
for c in [("%23", "#"), ("%5D", "]"), ("%5E", "^"),
("file://", ""), ("%20", " ")]:
path = path.replace(c[0], c[1])
return path
# get the current path
current = replace(os.getenv("NAUTILUS_SCRIPT_CURRENT_URI"))
# raise the found terminal window
os.chdir(os.path.realpath(current))
subprocess.Popen("gnome-terminal")
urllib.parse.unquote
instead of manually replacing %-encoded characters
NAUTILUS_SCRIPT_CURRENT_URI
shows the correct directory.
Jan 9, 2017 at 8:59
gnome-terminal
to terminate and then terminate itself. Instead you can call os.execlp("gnome-terminal", "gnome-terminal")
to replace the Python process with gnome-terminal
.
Jan 19, 2017 at 10:31