Last active
August 28, 2019 09:29
-
-
Save SimeonEhrig/8dcdc7bef6db38a0ddd92391d204ffec to your computer and use it in GitHub Desktop.
wrapper script for cd (change directory) to simplify the cd ../../../.. statement
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
#!/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