Skip to content

Instantly share code, notes, and snippets.

@SimeonEhrig
Last active August 28, 2019 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimeonEhrig/8dcdc7bef6db38a0ddd92391d204ffec to your computer and use it in GitHub Desktop.
Save SimeonEhrig/8dcdc7bef6db38a0ddd92391d204ffec to your computer and use it in GitHub Desktop.
wrapper script for cd (change directory) to simplify the cd ../../../.. statement
#!/bin/bash
# wrapper for the cd command
# it expands sequence .... to ../../../../ (each dot becomes a ../ )
# example: ' cd .... ' -> ' cd ../../../../ '
# if the command does not match ' cd ..[.]+ ' , it is passed directly to the cd command
# alias cd=". /path/to/mycd.sh"
if [[ $# != 1 ]]; then
builtin cd $@
else
if [[ $1 =~ ^..[.]+$ ]]; then
numberOfDots=$1
numberOfDots=${#numberOfDots}
pathString=""
for i in $(seq 1 $numberOfDots)
do
pathString="$pathString../"
done
builtin cd $pathString
else
builtin cd $@
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment