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

dirh, prevd, and nextd do not work as usual after builtin cd #4869

Closed
mumeiyamibito opened this issue Apr 2, 2018 · 3 comments
Closed

dirh, prevd, and nextd do not work as usual after builtin cd #4869

mumeiyamibito opened this issue Apr 2, 2018 · 3 comments
Labels

Comments

@mumeiyamibito
Copy link

Hi

I'm using fish-shell 2.7.1 on LinuxMint 18.3 (64 bit) (4.13.0-37-generic).

I used the following function to list files after changing directory.

function cd
	if count $argv > /dev/null
		builtin cd "$argv"; and ls
	else
		builtin cd ~; and ls
	end
end

By the function, I was able to display file list on current directory. But commands dirh, prevd, and nextd did not work as usual.

I checked this function by turning it on and off, and it seemed that it was caused by builtin cd. Below is the result of builtin cd to dirh.
Normal cd

$ cd /tmp
$ mkdir a b
$ dirh
 1) /home/mumeiyamibito
    /tmp

$ cd a
$ dirh
 2) /home/mumeiyamibito
 1) /tmp
    /tmp/a

$ cd ../b
$ dirh
 3) /home/mumeiyamibito
 2) /tmp
 1) /tmp/a
    /tmp/b

builtin cd

$ cd /tmp
$ dirh
 1) /home/mumeiyamibito
    /tmp

$ builtin cd a
$ dirh
 1) /home/mumeiyamibito
    /tmp/a

$ builtin cd ../b
$ dirh
 1) /home/mumeiyamibito
    /tmp/b

How can I resolve this problem?

Thanks.

@krader1961
Copy link
Contributor

That is the expected behavior. The cd history is maintained by the cd function, not the cd builtin. If you replace the standard cd function with your own implementation then it is up to you to mimic the behavior of the standard function (which also includes handling cd -). Run type cd to see the standard implementation (assuming you haven't already redefined it).

How can I resolve this problem?

The simplest solution is to name your cd function something else and remove the builtin prefix. The more complex solution is to use functions -c cd standard_cd then use standard_cd instead of builtin cd in your function.

@mumeiyamibito
Copy link
Author

mumeiyamibito commented Apr 2, 2018

@krader1961

Thank you for your quick and accurate answer!
By the complex solution, both my cd function and dirh can be used.

@zanchey
Copy link
Member

zanchey commented Apr 2, 2018

If you've got it working, I'll close this issue. See also #1640.

@zanchey zanchey closed this as completed Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants