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

Fix bugs in _hydro_pwd #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

blt-r
Copy link

@blt-r blt-r commented Apr 17, 2023

There were a couple of bugs in the implementation of _hydro_pwd which caused path to be rendered incorrectly:

  • if there is a parent directory named the same way as git root, it will be "highlighted" instead of the actual git root.
    For example, if you are in /foo/repo/bar/repo/baz and the second repo is git root, the first one will be highlighted.

  • if you are in directory named : (but not in git repo) it will not be shown.
    For example, if you are in /tmp/: you will see /t/ instead of /t/:.

  • if one of your parent directories is : and you are in git repo, the name of the repo will be shown instead of :.
    For example, if you are in /foo/:/bar/repo/baz you will see /f/repo/b/r/baz instead of /f/:/b/repo/baz.

  • if fish_prompt_pwd_dir_length is set to 0 and one of the parent directories starts with dot, the directory shown will start with dot.
    For example, if you are in /home/me/.config/fish you will see .fish instead of fish.

  • if you are in a directory that looks like your home directory but isn't, it will be replaced with ~.
    For example, if you are in /tmp/home/me you will see /tmp~.

(Sorry I didn't make a commit per bug fix, probably would have been more readable that way)

@blt-r
Copy link
Author

blt-r commented Apr 18, 2023

Also, it runs for every single prompt (or even twice per prompt?) instead of only when $PWD is changing. This is caused by --on-variable fish_prompt_pwd_dir_length. I know the standard prompt_pwd is setting the $fish_prompt_pwd_dir_length, and there is probably something else in fish that sets it.

I would recommend not dealing with $fish_prompt_pwd_dir_length and instead have something like $hydro_pwd_dir_length

@blt-r
Copy link
Author

blt-r commented Nov 2, 2024

Just added here another commit that I've also been using for past 8 months.

(see commit message for details)

For me, these two commits fixed the small annoyances I had before.

There were a couple of bugs in the implementation of _hydro_pwd
which caused path to be rendered incorrectly:

- if there is a parent directory named the same way as git root, it will
    be "highlighted" instead of the actual git root.
    For example, if you are in `/foo/repo/bar/repo/baz` and the second
    `repo` is git root, the first one will be highlighted.

- if you are in directory named `:` (but not in git repo) it will not be shown.
    For example, if you are in `/tmp/:` you will see `/t/` instead of `/t/:`.

- if one of your parent directories is `:` and you are in git repo,
    the name of the repo will be shown instead of `:`.
    For example, if you are in `/foo/:/bar/repo/baz` you will see
    `/f/repo/b/r/baz` instead of `/f/:/b/repo/baz`.

- if `fish_prompt_pwd_dir_length` is set to `0` and one of the parent
    directories starts with dot, the directory shown will start with dot.
    For example, if you are in `/home/me/.config/fish` you will see
    `.fish` instead of `fish`.

- if you are in a directory that looks like your home directory but isn't,
    it will be replaced with `~`.
    For example, if you are in `/tmp/home/me` you will see `/tmp~`.
These changes will make it so `_hydro_pwd` will run only when needed.

Before this, `_hydro_pwd` would always run, not just when pwd changes
beacuse of `--on-variable fish_prompt_pwd_dir_length`.

Now the `hydro_pwd_dir_length` is used instead.

The part about finding git root in `_hydro_pwd` we do want to run every
time, so it is moved to `_hydro_prompt`. Otherwise things break when
initializing and deleting git repos.
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

Successfully merging this pull request may close these issues.

1 participant