Crates.io | cda |
lib.rs | cda |
version | 0.1.0 |
source | src |
created_at | 2024-04-19 01:13:12.633475 |
updated_at | 2024-04-19 01:13:12.633475 |
description | A shell utility to quickly cd to an ancestor! |
homepage | |
repository | https://github.com/StaticESC/cda |
max_upload_size | |
id | 1213101 |
size | 14,782 |
Do you see yourself doing cd ..
way too many times?
Or even worse, doing cd ../../../../../../../..
and making a guess that the directory you end up at is "close enough"?
If yes, then this tool is for you.
And before you say "just organize your directories in a more meaningful way!", sometimes I end up working with multiple parallel directory trees (which loosely mirror each other), for whatever reason.
cda <ANCESTOR>
cd
s you to the closest ancestor.
Eg:
CWD: /home/jshelly/my-repos/my-project/workspace1/module1/component3/feature/feature.rs
$ cda my-project
$ pwd
/home/jshelly/my-repos/my-project
Similarly, I could've gone with any substring of "my-project" as well!
$ cda proj
$ pwd
/home/jshelly/my-repos/my-project
If multiple ancestors exist with the same name, then it takes you to the closest one. Otherwise, you can specify which occurrence of ancestor you wanna go to.
Eg:
CWD: /home/jshelly/playground/dir/playground/dir
$ cda playground 2 #Second arg is occurence. By default, it is 1.
$ pwd
/home/jshelly/playground
NOTE: The CWD is not considered its own ancestor.
By default, the search happens from closest to furthest ancestor (right to left). You can reverse that by using the -r
flag.
cargo install cda
cda() {
path_or_error=$(cda-bin "$@")
if [ $? -eq 0 ]; then # Path
cd $path_or_error
else # Err
echo $path_or_error
fi
}