mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-09-21 10:27:09 +00:00
lib/directories (cd): do not use pushd/DIRSTACK by default
https://github.com/ohmybash/oh-my-bash/pull/450
This commit is contained in:
parent
8e5e43e401
commit
24bd7e71ad
@ -1,19 +1,24 @@
|
|||||||
#! bash oh-my-bash.module
|
#! bash oh-my-bash.module
|
||||||
# Common directories functions
|
# Common directories functions
|
||||||
|
|
||||||
|
OMB_DIRECTORIES_CD_USE_PUSHD=false
|
||||||
|
|
||||||
|
_omb_cd_dirstack=("$PWD")
|
||||||
|
|
||||||
# A clone of the Zsh `cd' builtin command. This supports the numbered option
|
# A clone of the Zsh `cd' builtin command. This supports the numbered option
|
||||||
# `-1', `-2', etc.
|
# `-1', `-2', etc.
|
||||||
function _omb_directories_cd {
|
function _omb_directories_cd {
|
||||||
local oldpwd=$OLDPWD
|
|
||||||
local -i index
|
local -i index
|
||||||
if [[ $# -eq 1 && $1 =~ ^-[1-9]+$ ]]; then
|
if [[ $# -eq 1 && $1 =~ ^-[1-9]+$ ]]; then
|
||||||
index=${1#-}
|
index=${1#-}
|
||||||
if ((index >= ${#DIRSTACK[@]})); then
|
if ((index >= ${#_omb_cd_dirstack[@]})); then
|
||||||
builtin echo "cd: no such entry in dir stack" >&2
|
builtin echo "cd: no such entry in dir stack" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
set -- "${DIRSTACK[index]}"
|
set -- "${_omb_cd_dirstack[index]}"
|
||||||
fi
|
fi
|
||||||
|
if [[ ${OMB_DIRECTORIES_CD_USE_PUSHD-} == true ]]; then
|
||||||
|
local oldpwd=$OLDPWD
|
||||||
builtin pushd . >/dev/null &&
|
builtin pushd . >/dev/null &&
|
||||||
OLDPWD=$oldpwd builtin cd "$@" &&
|
OLDPWD=$oldpwd builtin cd "$@" &&
|
||||||
oldpwd=$OLDPWD &&
|
oldpwd=$OLDPWD &&
|
||||||
@ -23,7 +28,24 @@ function _omb_directories_cd {
|
|||||||
builtin popd "+$index" >/dev/null || return 1
|
builtin popd "+$index" >/dev/null || return 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
local status=$?
|
||||||
|
_omb_cd_dirstack=("${DIRSTACK[@]/#~/$HOME}")
|
||||||
OLDPWD=$oldpwd
|
OLDPWD=$oldpwd
|
||||||
|
else
|
||||||
|
[[ ${_omb_cd_dirstack[0]} == "$PWD" ]] ||
|
||||||
|
_omb_cd_dirstack=("$PWD" "${_omb_cd_dirstack[@]}")
|
||||||
|
builtin cd "$@" &&
|
||||||
|
_omb_cd_dirstack=("$PWD" "${_omb_cd_dirstack[@]}")
|
||||||
|
local status=$?
|
||||||
|
|
||||||
|
for ((index = ${#_omb_cd_dirstack[@]} - 1; index >= 1; index--)); do
|
||||||
|
if [[ ${_omb_cd_dirstack[0]} == "${_omb_cd_dirstack[index]}" ]]; then
|
||||||
|
unset -v '_omb_cd_dirstack[index]'
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
_omb_cd_dirstack=("${_omb_cd_dirstack[@]}")
|
||||||
|
fi
|
||||||
|
return "$status"
|
||||||
}
|
}
|
||||||
_omb_util_alias cd='_omb_directories_cd'
|
_omb_util_alias cd='_omb_directories_cd'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user