New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

Projects
None yet
3 participants
@terlar
Copy link
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

This comment has been minimized.

Copy link
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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

krader1961 commented Apr 13, 2016

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

krader1961 commented Apr 13, 2016

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 Using `status -f` with symlinked script files. with the change to `status -f` output a `realpath` implementation would be useful Apr 13, 2016

krader1961 added a commit to krader1961/fish-shell that referenced this issue Apr 14, 2016

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 fish-shell#2932

krader1961 added a commit to krader1961/fish-shell that referenced this issue Apr 14, 2016

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 fish-shell#2932

krader1961 added a commit to krader1961/fish-shell that referenced this issue Apr 28, 2016

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 fish-shell#2932

krader1961 added a commit that referenced this issue Apr 30, 2016

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)

@krader1961 krader1961 modified the milestones: 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