From d8d3a771136cecf29da0b4f98175dde48f4b3a92 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Tue, 10 Dec 2024 12:49:56 +0100 Subject: [PATCH] Addet dots() bash function and corresponding aliases for easier upward navigation in directories. --- bash/bash_functions | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bash/bash_functions b/bash/bash_functions index 4b4a916..1a73f1a 100644 --- a/bash/bash_functions +++ b/bash/bash_functions @@ -101,3 +101,28 @@ goto() { cd -- "$(dirname "$(fd $1 $HOME /bin /usr/local /usr /etc | fzy)")" } + +# Easier cd'ing (aliases here because they depend on dots() function being available) + +dots() { + # Count number of dots + local depth=$(echo -n "$1" | tr -cd '.' | wc -c) + + # if no dots, stay in current directory + if [ "depth" -eq 0 ]; then + depth=1 + fi + + for _ in $(seq 1 "$depth"); do + cd .. + done + +} + +# aliases for even easier navigation + +alias ..='dots ..' +alias ...='dots ...' +alias ....='dots ....' +alias .....='dots .....' +alias ......='dots ......'