Skip to content

Instantly share code, notes, and snippets.

@sndao
Forked from GNOMES/dc.sh
Created October 29, 2025 03:03
Show Gist options
  • Save sndao/232c554dbf0038b123ccc3039b1cc89b to your computer and use it in GitHub Desktop.
Save sndao/232c554dbf0038b123ccc3039b1cc89b to your computer and use it in GitHub Desktop.
cd backwards to named directoy in current path
# 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