9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.64k stars 326 forks source link

Unix Path aliases not honored #447

Closed ealvarezn closed 4 years ago

ealvarezn commented 4 years ago

On plan9port in Linux, at least, acme cannot follow paths that use tilde as an alias for the user's home directory (eg, ~/path/to/foo) or the $HOME environment variable (eg, $HOME/path/to/foo). This happens regardless of what value $acmeshell has been set to. It'd be nice if acme could honor these aliases.

igorburago commented 4 years ago

1. If by “following” paths in acme(1) you mean the ability to open them with button 3, it is entirely a matter of apt plumber(4) configuration (which you can also benefit from in sam(1), 9term(1), etc.).

For instance, the following is the relevant fragment of my plumbing file that makes plumb(1) support paths starting with ~/ and $HOME/. (I also have a similar configuration for paths starting with $PLAN9/.)

# To fill out the below $home variable in acme(1), put
# the cursor between the single quotes and drag-select
# the command in the comment with button 2 (from after
# the '#' character until the end of the line):
home = ''  # <printf %s "$HOME"

# To recognize address suffixes with the $addr regexp:
include fileaddr  # $PLAN9/plumb/fileaddr

filepathtailcc = 'A-Za-z¡-�0-9_\-/'
filepathcc = $filepathtailcc'@., '
filepathre = '(['$filepathcc']*['$filepathtailcc'])'

# Directory paths starting with '~/' and '$HOME/'
type is text
data matches '(~|\$HOME|"\$HOME")/('$filepathre')?'
arg isdir $home/$2/
data set $dir
plumb to edit
plumb client $editor

# File paths starting with '~/' and '$HOME/'
type is text
data matches '(~|\$HOME|"\$HOME")/'$filepathre'('$addr')?'
arg isfile $home/$2
plumb start plumb -a 'addr='$4 $file

(See the plumb(7) man page for the plumbing rule format.)

Feel free to adjust it to your needs before use, especially in regards to the characters allowed in paths, as given by the $filepathre variable defining the regexp(3) matching the path portions in the data matches pattern rules.

2. Of course, one still has to type the full path to the home directory to interactively complete partial paths starting with it via Ctrl+F in acme(1), as there is no way to configure that completion mechanism without modifying the code (src/cmd/acme/text.c:/^textcomplete).

But I personally find the latter less of an issue when the above plumber configuration is employed, because with it one can always first type ~/ somewhere, button 3-click on it to open a home directory window, and then interactively complete the path in question from there.

An even simpler way to avoid the need to type the absolute path to the home directory when using completion, is to run acme(1) from $HOME. Then, any path that does not start with /, when being typed into a new, nameless window—as well as the global or one of the column tag lines— is treated as being relative to the home directory, as if it is typed in the tag or body of the window opened to view that directory.

rsc commented 4 years ago

Acme also doesn't do glob expansion or environment variable substitution or any other shell interpretation. That's just not its job.