diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-11-25 10:33:41 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-11-25 10:34:32 +0100 |
commit | cfd82092c2f5518e037f26b9dd266a461e08326c (patch) | |
tree | 806c454a7c65a8714957647ad6d202732115b9c1 | |
parent | 779c37847d9e6676ced5a5c9c608d47f3d42e5b5 (diff) |
bashrc: add a function for "cd n dirs up"
-rw-r--r-- | bash/bashrc | 16 |
1 files changed, 16 insertions, 0 deletions
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) |