-
-
Save sndao/232c554dbf0038b123ccc3039b1cc89b to your computer and use it in GitHub Desktop.
cd backwards to named directoy in current path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add to ~/.bashrc | |
| # jump backwards from cwd path | |
| dc() { | |
| cd "${PWD%/$1/*}/$1/" 2>/dev/null || echo "Directory not found: $1" | |
| } | |
| # Function to add tab completion to dc | |
| _dc_complete() { | |
| IFS='/' read -ra dirs <<<"$(pwd)" | |
| local dir_names=("${dirs[@]:1}") | |
| COMPREPLY=() | |
| for dir in "${dir_names[@]}"; do | |
| [[ $dir == ${COMP_WORDS[COMP_CWORD]}* ]] && COMPREPLY+=("$dir") | |
| done | |
| } | |
| complete -F _dc_complete dc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment