From 9afc4b419e6c52efb6e1be86080fae79bdde87d3 Mon Sep 17 00:00:00 2001 From: Moritz Wilhelmy Date: Sun, 4 Nov 2018 21:43:12 +0800 Subject: [PATCH] Allow `cd .` to re-enter the current directory Closes #4543. --- doc_src/cd.txt | 2 ++ share/functions/cd.fish | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/doc_src/cd.txt b/doc_src/cd.txt index caffa842c..748f0c322 100644 --- a/doc_src/cd.txt +++ b/doc_src/cd.txt @@ -16,6 +16,8 @@ Note that the shell will attempt to change directory without requiring `cd` if t Fish also ships a wrapper function around the builtin `cd` that understands `cd -` as changing to the previous directory. See also `prevd`. This wrapper function maintains a history of the 25 most recently visited directories in the `$dirprev` and `$dirnext` global variables. If you make those universal variables your `cd` history is shared among all fish instances. +As a special case, `cd .` is equivalent to `cd $PWD`, which is useful in cases where a mountpoint has been recycled or a directory has been removed and recreated. + \subsection cd-example Examples \fish diff --git a/share/functions/cd.fish b/share/functions/cd.fish index 23f169d2c..eed8a9f94 100644 --- a/share/functions/cd.fish +++ b/share/functions/cd.fish @@ -27,6 +27,12 @@ function cd --description "Change directory" return $status end + # allow explicit "cd ." if the mount-point became stale in the meantime + if test "$argv" = "." + cd "$PWD" + return $status + end + builtin cd $argv set -l cd_status $status