summaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-11-25 10:33:41 +0100
committerAnton Khirnov <anton@khirnov.net>2020-11-25 10:34:32 +0100
commitcfd82092c2f5518e037f26b9dd266a461e08326c (patch)
tree806c454a7c65a8714957647ad6d202732115b9c1 /bash
parent779c37847d9e6676ced5a5c9c608d47f3d42e5b5 (diff)
bashrc: add a function for "cd n dirs up"
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc16
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)