with the change to `status -f` output a `realpath` implementation would be useful #2932

Closed
terlar opened this Issue Apr 13, 2016 · 6 comments

Projects

None yet

3 participants

@terlar
Contributor
terlar commented Apr 13, 2016

If you are symlinking scripts that rely on status -f being resolved to the original source, you will get the wrong file. Is this the correct behaviour of status -f and if so, is there a way to get the real path of the currently executed script?

Reproduction Steps:

  1. mkdir -p /tmp/dir1
  2. mkdir -p /tmp/dir2
  3. echo 'status -f' > /tmp/dir1/real.fish
  4. ln -s /tmp/dir1/real.fish /tmp/dir2/link.fish

Expected behavior:

$ fish /tmp/dir1/real.fish
/tmp/dir1/real.fish
$ fish /tmp/dir2/link.fish
/tmp/dir1/real.fish

Observed behavior:

$ fish /tmp/dir1/real.fish
/tmp/dir1/real.fish
$ fish /tmp/dir2/link.fish
/tmp/dir2/link.fish

Fish version: 2.2.0-747-ge395a0e

Operating system: Arch Linux, fish installed through AUR

Terminal or terminal emulator: termite

@faho
Member
faho commented Apr 13, 2016

See #2643, where this was changed. The intent was to be consistent whether you're using source $file or fish $file.

This case in particular was also mentioned:

I think that resolving symlinks is bad, because some scripts are symlinked to each other and switch off their name to decide what to do.

In other words, this seems to be working as intended. @ridiculousfish: Any comments?

@terlar
Contributor
terlar commented Apr 13, 2016

I see, I thought I remember something about that, but couldn't find it. However tools like realpath have been traditionally shakey, as it works different between systems and are in many cases not a default tool.

Perhaps a built-in solving this path resolution could be a thing? Or a switch to the status command?

@krader1961
Member

The current behavior was deliberately chosen to satisfy the broadest set of use cases. If you're on a distro like OS X which doesn't have a native realpath it probably has readlink which you can wrap in a realpath function. And, of course, it's easy to install via brew install coreutils or sudo apt-get install coreutils (or whatever ArchLinux uses). Too, using other available tools such as python it's easy enough to write such as command. For example,

python2 -c 'import os, sys; print os.path.realpath(sys.argv[1])' symlinks/sms
@krader1961 krader1961 added the question label Apr 13, 2016
@terlar
Contributor
terlar commented Apr 13, 2016

Yes, I agree for personal use that is okay. But I was more thinking if there is some fish code that I want to distribute for other users. I have no idea what systems and setups they have, would be nice to have a reliable way to deal with that. However your suggestions are appreciated.

This was specifically that I wanted to add a custom fish functions path and a custom fish completions path relative from the script location and I wanted to symlink that script into the conf.d. However there might be better ways nowadays to handle custom fish scripts/addons with the vendor things and also through third party "plugin" environments.

@terlar
Contributor
terlar commented Apr 13, 2016

I should probably use the $__fish_datadir/vendor_completions.d, $__fish_datadir/vendor_functions.d and $__fish_datadir/vendor_conf.d.

@krader1961 krader1961 added enhancement and removed question labels Apr 13, 2016
@krader1961 krader1961 added this to the next-2.x milestone Apr 13, 2016
@krader1961 krader1961 self-assigned this Apr 13, 2016
@krader1961
Member

I suppose we could add a realpath function that passes through to the command if it's available else uses one of the workarounds I listed above.

@krader1961 krader1961 changed the title from Using `status -f` with symlinked script files. to with the change to `status -f` output a `realpath` implementation would be useful Apr 13, 2016
@krader1961 krader1961 added a commit to krader1961/fish-shell that referenced this issue Apr 14, 2016
@krader1961 krader1961 provide a realpath implementation
Not all distros have a `realpath` command. Provide a function that uses the
real command if available else try fallback solutions.

Fixes #2932
b23e3e8
@krader1961 krader1961 added a commit to krader1961/fish-shell that referenced this issue Apr 14, 2016
@krader1961 krader1961 provide a realpath implementation
Not all distros have a `realpath` command. Provide a function that uses the
real command if available else try fallback solutions.

Fixes #2932
ecb88f5
@krader1961 krader1961 added a commit to krader1961/fish-shell that referenced this issue Apr 28, 2016
@krader1961 krader1961 provide a realpath implementation
Not all distros have a `realpath` command. Provide a function that uses the
real command if available else use the fish builtin.

Fixes #2932
84fb0df
@krader1961 krader1961 added a commit that closed this issue Apr 28, 2016
@krader1961 krader1961 provide a realpath implementation
Not all distros have a `realpath` command. Provide a function that uses the
real command if available else use the fish builtin.

Fixes #2932
6c329e8
@krader1961 krader1961 added a commit that referenced this issue Apr 30, 2016
@krader1961 krader1961 provide a realpath implementation
Not all distros have a `realpath` command. Provide a function that uses the
real command if available else use the fish builtin.

Fixes #2932

(cherry picked from commit 6c329e8)
52731c4
@krader1961 krader1961 modified the milestone: 2.3.0, next-2.x Apr 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment