DEV Community

Discussion on: Bash: How To Teleport In The Terminal

Collapse
 
stephencweiss profile image
Stephen Charles Weiss

I have this little function in my .zshrc which is pretty convenient:

# up is a composable version of 'cd ..' taking a numeric argument. if one is passed (e.g., `up 3`, the result is `cd ../../../`)
# taken from here: https://news.ycombinator.com/item?id=9869231
function up {
        if [[ "$#" < 1 ]] ; then
            cd ..
        else
            CDSTR=""
            for i in {1..$1} ; do
                CDSTR="../$CDSTR"
            done
            cd $CDSTR
        fi
    }