evanthegrayt / cdc

☣️ Shell plugin for zsh/bash that allows you to cd to subdirectories of user-defined directories from anywhere, without editing CDPATH.
MIT License
22 stars 0 forks source link

Add way to push current directory onto the stack #53

Open evanthegrayt opened 3 years ago

evanthegrayt commented 3 years ago

If I'm in a directory, and it's not currently on the stack, there's no way to add it unless you use cdc DIR. It'd be nice if you could do cdc . and have it push to the stack.

Example:

cd ~/repo 
cd a/nested/subdir
# Now I want to go back to the root of `repo`, but can't use `cdc -n`

# SOLUTION
cd ~/repo # oh crap, I want this on the history stack
cdc .

Also, and I'm not sure about this one... but it'd be cool to add cdc .., and it would traverse up the directory tree until it found a file in the CDC_REPO_MARKERS, changed to that directory, and added it to the stack (if requested).

evanthegrayt commented 3 years ago

I've been thinking more about this. I'm thinking that cdc . can serve both purposes. If $CDC_REPOS_ONLY == true or -r, then it will traverse up $PWD until it finds a $CDC_REPO_MARKER. If none is found, do nothing and print an error. If $CDC_REPOS_ONLY == false or -R, add the current directory.

I've also debated checking to make sure that one of $CDC_DIRS is in your current path... but not sure about this one.

evanthegrayt commented 3 years ago

Was playing around but didn't create a branch yet. Sticking this here for now.

    ##
    # If the argument is `.` and the current directory contains one of the
    # $CDC_DIRS, add the root of the directory to the stack.
    if [[ $cd_dir == '.' ]]; then
        should_return=true
        for dir in ${CDC_DIRS[@]}; do
            if ! [[ $PWD =~ $dir ]]; then
                continue
            fi
            wdir=${PWD/$dir}
            echo $wdir
            if [[ -z $wdir ]]; then
                # TODO: add real output
                echo "you're in a cddir"
                break
            fi
            CDC_HISTORY+=("$wdir")
        done
    fi