From cfd82092c2f5518e037f26b9dd266a461e08326c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 25 Nov 2020 10:33:41 +0100 Subject: bashrc: add a function for "cd n dirs up" --- bash/bashrc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'bash') diff --git a/bash/bashrc b/bash/bashrc index 2e48a70..4cf0273 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -27,6 +27,22 @@ fi # XXX should this be here? stty -ixon +cu() +{ + local lvl=$1 + if ! [[ "${lvl}" =~ ^[0-9]+$ ]]; then + echo "Parameter must be a non-negative integer: ${lvl}" + return 1 + fi + + local dir="" + for i in $(seq "${lvl}"); do + dir=${dir}../ + done + + cd "${dir}" +} + # define the prompt . ~/.config/bash/prompt PS1=$(__prompt_func) -- cgit v1.2.3