From 6cc985f5ca5b7b65e9bfbb6991da6d4f79402151 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Tue, 9 Mar 2021 22:13:12 -0800 Subject: [PATCH] Replaced navigation aliases with up() function --- .bashrc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.bashrc b/.bashrc index 7915189..e8896db 100644 --- a/.bashrc +++ b/.bashrc @@ -106,11 +106,24 @@ ex () alias doas="doas --" # navigation -alias ..='cd ..' -alias ...='cd ../..' -alias .3='cd ../../..' -alias .4='cd ../../../..' -alias .5='cd ../../../../..' +up () { + local d="" + local limit="$1" + + # Default to limit of 1 + if [ -z "$limit" ] || [ "$limit" -le 0 ]; then + limit=1 + fi + + for ((i=1;i<=limit;i++)); do + d="../$d" + done + + # perform cd. Show error if cd fails + if ! cd "$d"; then + echo "Couldn't go up $limit dirs."; + fi +} # vim and emacs alias vim="nvim"