Clean up rev-parse usage. check-ignore uses current dir.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-20 21:11:53 +01:00
commit fceefe0786

12
.bashrc
View file

@ -33,23 +33,23 @@ __prompt_git_status() {
# Get some repository information. # Get some repository information.
# shellcheck disable=SC2207 # shellcheck disable=SC2207
IFS=$'\n' GIT_REPO_INFO=( $(git rev-parse --show-toplevel --git-dir --is-bare-repository --is-shallow-repository --is-inside-git-dir --is-inside-work-tree 2>/dev/null) ) IFS=$'\n' GIT_REPO_INFO=( $( git rev-parse --is-bare-repository --is-shallow-repository --is-inside-git-dir --is-inside-work-tree 2>/dev/null) )
ERR="$?" ERR="$?"
# Do nothing if there's an error. # Do nothing if there's an error.
(( ERR >= 1 )) && return "$RET" (( ERR >= 1 )) && return "$RET"
# Generate the prompt. # Generate the prompt.
if [[ "${GIT_REPO_INFO[4]}" == "true" ]]; then if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then
# In the git directory, use a special branch marker. # In the git directory, use a special branch marker.
GIT_PROMPT+="!GIT_DIR!" GIT_PROMPT+="!GIT_DIR!"
elif [[ "${GIT_REPO_INFO[5]}" == "true" ]]; then elif [[ "${GIT_REPO_INFO[3]}" == "true" ]]; then
# In the working directory, generate the prompt. # In the working directory, generate the prompt.
# Add type markers. # Add type markers.
[[ -n "$GIT_PROMPT_SHOW_TYPE" ]] && { [[ -n "$GIT_PROMPT_SHOW_TYPE" ]] && {
if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then if [[ "${GIT_REPO_INFO[0]}" == "true" ]]; then
GIT_PROMPT+="B:" GIT_PROMPT+="B:"
elif [[ "${GIT_REPO_INFO[3]}" == "true" ]]; then elif [[ "${GIT_REPO_INFO[1]}" == "true" ]]; then
GIT_PROMPT+="S:" GIT_PROMPT+="S:"
fi fi
} }
@ -107,7 +107,7 @@ __prompt_git_status() {
} }
# Add a marker if directory is ignored, there's unstaged files, uncommitted changes, untracked files or a stash. # Add a marker if directory is ignored, there's unstaged files, uncommitted changes, untracked files or a stash.
[[ -n "$GIT_PROMPT_SHOW_IGNORED" ]] && git check-ignore "${PWD#"${GIT_REPO_INFO[0]}/"}" >/dev/null 2>&1 && { [[ -n "$GIT_PROMPT_SHOW_IGNORED" ]] && git check-ignore . >/dev/null 2>&1 && {
GIT_PROMPT+=" !" GIT_PROMPT+=" !"
GIT_PROMPT_MARKER_SET=1 GIT_PROMPT_MARKER_SET=1
} }