Skip to content
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

'~' for home directory #70

Closed
rgieseke opened this issue Jan 11, 2019 · 14 comments
Closed

'~' for home directory #70

rgieseke opened this issue Jan 11, 2019 · 14 comments

Comments

@rgieseke
Copy link

Thanks for this amazing tool/port to fish!

Could there be a way to replace "/home/username/" or "/Users/username" with "~" in the completions?

@jethrokuan
Copy link
Owner

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).

@rgieseke
Copy link
Author

Just for being able to more quickly scan the completions results and save screenspace.

@jethrokuan
Copy link
Owner

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.

@rgieseke
Copy link
Author

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.)

@jethrokuan
Copy link
Owner

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.

@rgieseke
Copy link
Author

Thanks, i'll give this a try!

@jorgebucaran
Copy link
Collaborator

@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.

@rgieseke
Copy link
Author

@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.

@jethrokuan
Copy link
Owner

yup @jorgebucaran is showing that the complete function expands ~, so it's impossible for a completion to contain ~.

@jorgebucaran
Copy link
Collaborator

@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.)

screen shot 2019-01-21 at 16 51 04

Still fish shows my full $HOME (/Users/x) instead of ~, which is what we wanted.

@rgieseke
Copy link
Author

@jorgebucaran @jethrokuan Thanks for the explanations!

This might be related? fish-shell/fish-shell#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.

@rgieseke
Copy link
Author

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.

@jorgebucaran
Copy link
Collaborator

@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.

@jethrokuan
Copy link
Owner

Closing as unsolvable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants