Ubuntu – How to open a text file in current working directory with `gedit admin://`

18.04command linegedit

The following terminal command will open the text file ubuntu.css from any location of a file structure:

$ gedit admin:///usr/share/gnome-shell/theme/ubuntu.css

However, if I am already in directory /usr/share/gnome-shell/theme and I want to open the file ubuntu.css with gedit, how should I submit the above command without having to type the full path again?

Edit:
I am adding a link here that I just found that give a short intro to the above command. But it does not deal with the issue that I have identified in my question.

Best Answer

Unfortunately, no, it is not possible to pass a relative path with this admin:// URI. This answer may be disappointing, but that is how it currently (Ubuntu 18.04, Ubuntu 19.10) works.

Using a short wrapper script

You can, however, very conveniently work around the issue with a wrapper script. With the script sedit, you edit a file correctly with administrator privileges, just by typing the command and a filename, as in sedit ubuntu.css.

sedit):

```bash
#!/bin/bash
gedit admin://$(readlink -f "$1")
```

If you place that in a folder in your path, the command sedit ubuntu.css will open the file using the admin URI. Also providing the full path, or any valid path, will work.

Other options

Other, more standard options to not to have to type the pathname are:

  • You can use Tab expansion once you typed the three slashes of the URI.

  • You could drag the file from Files (nautilus) into the terminal. Thus, you could type "gedit admin://' in the terminal, find the file in Files, and then drag the file from Files into the terminal. This can make it easier to enter the URI in the terminal.

  • You could avoid typing the path using $(pwd)filename or $(readlink -f filename).

    gedit admin://$(pwd)/ubuntu.css
    

    or

    gedit admin://$(readlink -f ubuntu.css)`
    
  • You can install the nautilus python extension, nautilus-admin. Install it with the command sudo apt install nautilus-admin or using Synaptic Package manager (unfortunatelly, you cannot find it using Software). This small python extension integrates in the right-click menu, and converts the selected file to an 'admin://' URI for editing with root permissions.