cde
extends cd
to reach more paths easily, and knows what to do once it gets there.
cde
knows where you are going because it knows where you've been, and what directory structures look like.
The name "cde
" extends "cd
" on a qwert keyboard.
(In a simpler world the name was kd
.)
This package does not change the cd
command, and trys not to hurt your system in silly ways.
We cool?
OK, clone the repo, and source the bash functions:
$ git clone https://github.com/jalanb/cde/cde.git
$ . cde/cde.sh
And something similar to your bashrc
if it works for you.
You just added a bash function called cde
which is intended as a drop-in replacement for the cd
command.
$ cde -h
cd to a dir and react to it
cde [dirname [subdirname ...]]
$ cde /usr/local/bin; pwd
/usr/local/bin
(Examples will work depending on system layout, please allow reasonable defaults, and no history yet)
A dirname can abbreviate a path, e.g.
$ cd /; cd /usr/local/bin; pwd
/usr/local/bin
$ cd /; cde /u loc bi; pwd
/usr/local/bin
The first argument to cde
is a dirname
, further arguments are subdirnames
. This makes it easier to leave out all those annoying "/"s, e.g.
$ cd /usr/local/bin; pwd
/usr/local/bin
$ cde /usr local bin; pwd
/usr/local/bin
A full path to a directory works as a dirname
$ cde /usr/local/bin; pwd
/usr/local/bin
A full path to a file can also be a dirname
as cd
will use the parent directory.
$ cde /usr/local/bin/python; pwd
/usr/local/bin
A globbed path to a file or directory can also be a dirname
(cde
will take the first match). For example, /bin/l*
matches /bin/ls
, which is an existing file, whose parent is /bin
, so
$ cde /bin/l*; pwd
/bin
A "dirname" can be a short name for a directory, and a "subdirname" can be a prefix for a sub-directory. Names can be shortened as much as you like while keeping them unique
$ cd /usr/local/bin; pwd
/usr/local/bin
$ cde /u lo b; pwd
/usr/local/bin
If you abbreviate too much, cde
will refuse to guess, unless told to
$ cde /u l
Try again: Too many possiblities
0: /usr/lib
1: /usr/libexec
2: /usr/local
$ cde -1 /u l; pwd
/usr/lbexec
cde
keeps a history of everywhere it has been to, and so a dirname
can just use the old directory's name (not path). For example, given that we have cde
'd to it already, we can get back to /usr/local/bin (from anywhere else) by simply
$ cde b
If nothing matches then cde
tries directories in $PATH which have matching executables. For example:
$ cde python; pwd
/usr/local/bin
When looking for partial names cde
will look for each of these in turn, stopping as soon as it gets some match
- directories with the same name
- directories that start with that name
- files that start with that name
- directories with that in their name
- files with that in their name