From 98be04b9ddb9ce3b0a8c41c74cb57460f1d872eb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 30 May 2021 21:41:49 +0900 Subject: Update .zshrc: improve __cd_* cmd --- .zshrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.zshrc b/.zshrc index 78e1678..eb2fb3f 100644 --- a/.zshrc +++ b/.zshrc @@ -218,6 +218,8 @@ bindkey "^U" backward-kill-line # C-j To go to the parent directory. function __cd_parent_dir() { + [ -e $BUFFER ] || return + pushd .. > /dev/null zle reset-prompt } @@ -226,6 +228,8 @@ bindkey "^J" __cd_parent_dir # C-o To go to the previous directory. function __cd_prev_dir() { + [ -e $BUFFER ] || return + popd > /dev/null zle reset-prompt } @@ -234,6 +238,8 @@ bindkey "^O" __cd_prev_dir # C-g To go to the project root. function __cd_project_root_dir() { + [ -e $BUFFER ] || return + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]]; then pushd $(git rev-parse --show-toplevel) > /dev/null zle reset-prompt -- cgit v1.2.3-70-g09d2