Closed rgieseke closed 5 years ago
Could you explain why you'd want this behaviour? z
logs the absolute path to the file, hence the completions would always be valid (if the folder still exists).
Just for being able to more quickly scan the completions results and save screenspace.
The tab completions (if that's what you were referring to) was not an original feature of z, and was built because it was easy to do so in this fish port. That said, it was never meant to be for how z were to be used.
In most cases, typing z partial_dir
should be sufficient, and is the primary way people use it. I'm not sure it's worth adding additional code around this, but I'll leave this issue open for others to chime in as to whether they want your proposal implemented.
Cool, thanks a lot for the explanation! In both cases I'd find it easier to check whether it's the directory I wanted if there would be only "~".
I had already briefly once tried to add this, should it theoretically be sufficient to change the $PWD in https://github.com/jethrokuan/z/blob/master/functions/__z_add.fish#L3 to a path where $HOME is replaced in $PWD?
(I see that this could be problematic for upgrading users.)
I'm not sure why you would see the directory path. In the main use-case, the user would automatically be changed to the directory without prompting.
If you insist, I recommend that you keep the data file the same, storing absolute paths, and then in the completions using string
to sub any occurrence of $HOME
with ~
before returning.
Thanks, i'll give this a try!
@rgieseke Could there be a way to replace "/home/username/" or "/Users/username" with "~" in the completions?
I think this is impossible. Try this:
complete -xc foo -a "~"
foo<TAB>/Users/me
As you can see fish expands ~
to $HOME
. I agree it would be nice if we could, though.
@jorgebucaran I don't understand the example you're showing but maybe it's related to what i found?
I tried changing in __z_complete.fish
:
set -l __z_marks (string replace -r '\|.*' '' < $Z_DATA | string escape | string replace $HOME '~')
I still get expanded items with z -l
Trying only
string replace -r '\|.*' '' < $Z_DATA | string escape | string replace $HOME '~'
in the shell works as expected.
yup @jorgebucaran is showing that the complete function expands ~
, so it's impossible for a completion to contain ~
.
@rgieseke See my screenshot. It shows I added a ~
Tab completion to some foo
command. (There is no foo
command, but that's irrelevant now.)
Still fish shows my full $HOME
(/Users/x
) instead of ~
, which is what we wanted.
@jorgebucaran @jethrokuan Thanks for the explanations!
This might be related? https://github.com/fish-shell/fish-shell/issues/4570
When I experimented with replacing $HOME as above I once had a state where the "~" appeared escaped (not a real improvement) and fish wouldn't find the directory to change to.
In most cases, typing z partial_dir should be sufficient, and is the primary way people use it.
In any case i realised that i probably need tab completion much less than i thought (never having used z before) - just typing "something" is indeed enough most of the time.
@rgieseke Yeah, you can escape it:
complete -xc foo -a "\~"
or
complete -xc foo -a \\~
...and this is the result.
foo<TAB>\~
This, however, is worse, because you have an invalid path now and it looks ugly.
Closing as unsolvable.
Thanks for this amazing tool/port to fish!
Could there be a way to replace "/home/username/" or "/Users/username" with "~" in the completions?