Skip to content

Instantly share code, notes, and snippets.

@ddribin
Created March 30, 2016 23:08
Show Gist options
  • Save ddribin/a67938040f04f70460eb220fcdea5af5 to your computer and use it in GitHub Desktop.
Save ddribin/a67938040f04f70460eb220fcdea5af5 to your computer and use it in GitHub Desktop.
The 'cd' function in my .zshrc
cd ()
{
if (( ${#argv} == 0 )); then
builtin cd
return
fi
local dir=$1
if [[ -f $dir ]]; then
file=$dir:t
echo "Ignoring: $file"
dir=$dir:h
fi
builtin cd "$dir"
}
@ddribin
Copy link
Author

ddribin commented Mar 30, 2016

This allows running cd on a file and it will ignore the file component:

% cd /etc/passwd
Ignoring: passwd
% pwd
/etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment