Why do you want to do it without modifying your PS1 variable? That is the correct way to do it.
If you run the following, you'll get what you want:
export PS1="\[\e]0;\W\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
This is just taking the default prompt:
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
... and replacing \u@\h: \w
with \W
.
You can do the same thing with any command that echoes the right escape code:
echo -en "\e]0;${PWD##*/}\a"
... but then you'd be constantly fighting bash to stop it from doing it using PS1 (the best way).
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.
Best Answer
You know you can use the tab key for path and filename auto-completion?