nushell: `path relative-to` does not like piping to its input

Describe the bug feature request

Important EDIT: from the help page of path relative-to, it says The argument path needs to be a parent of the input path., but this issue of mine is more a feature request to relax this and compute the relative path to go from one to the other, regardless of parentness ๐Ÿ˜‹

iโ€™m not sure what to say more than the title really ๐Ÿ˜†

How to reproduce

  1. pipe pwd to path relative-to
> pwd | path relative-to $nu.home-path
documents/repos/github.com/amtoine/nushell
  1. give pwd as the argument
> $nu.home-path | path relative-to (pwd)
Error: nu::shell::cant_convert

  ร— Can't convert to prefix not found.
   โ•ญโ”€[source:1:1]
 1 โ”‚ nu
   ยท โ–ฒ
   ยท โ•ฐโ”€โ”€ can't convert string to prefix not found
   โ•ฐโ”€โ”€โ”€โ”€

Expected behavior

i expected both the commands to give the same result and no error ๐Ÿ‘

Screenshots

No response

Configuration

key value
version 0.84.1
branch fix-expand-table-unnessary-color-in-trail-head-config
commit_hash 9744418a2144a0bad7b8506f58a58cd5a40b8fdf
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.70.0 (90c541806 2023-05-31)
rust_channel 1.70.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.70.0 (ec8a8a0ca 2023-04-25)
build_time 2023-09-14 18:55:46 +02:00
build_rust_channel debug
allocator standard
features default, sqlite, trash, which, zip
installed_plugins gstat, nu_plugin_explore

Additional context

i also get other errors depending on the thing piped to path relative

> $env.HOME | path relative-to (pwd)
Error: nu::shell::cant_convert

  ร— Can't convert to prefix not found.
    โ•ญโ”€[Host Environment Variables:55:1]
 55 โ”‚ "HISTFILE"="/home/amtoine/.local/state/bash/history"
 56 โ”‚ "HOME"="/home/amtoine"
    ยท        โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€
    ยท               โ•ฐโ”€โ”€ can't convert string to prefix not found
 57 โ”‚ "IPFS_PATH"="/home/amtoine/.ipfs"
    โ•ฐโ”€โ”€โ”€โ”€
> "." | path relative-to (pwd)
Error: nu::shell::cant_convert

  ร— Can't convert to prefix not found.
   โ•ญโ”€[entry #13:1:1]
 1 โ”‚ "." | path relative-to (pwd)
   ยท โ”€โ”ฌโ”€
   ยท  โ•ฐโ”€โ”€ can't convert string to prefix not found
   โ•ฐโ”€โ”€โ”€โ”€

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 1
  • Comments: 17 (12 by maintainers)

Most upvoted comments

okey, i see.

then, from the help page of the command

Express a path as relative to another path.

Can be used only when the input and the argument paths are either both absolute or both relative. The argument path needs to be a parent of the input path.

i think this is more of a feature request: i would vote for relaxing The argument path needs to be a parent of the input path. and just compute the absolute path from the input to the argument ๐Ÿ˜‹

One way of making it work bidirectionally is just do:

try lhs -> rhs, if it works, 
  return working value
if it fails, try rhs -> lhs, if it works
  return working value
else return an error

ok, but how is it supposed to know when one is the prefix to strip?