Skip to content

Instantly share code, notes, and snippets.

@aramperes
Created June 3, 2023 19:43
Show Gist options
  • Save aramperes/a02fb3f8ee3fe71fb2a101beb19d015a to your computer and use it in GitHub Desktop.
Save aramperes/a02fb3f8ee3fe71fb2a101beb19d015a to your computer and use it in GitHub Desktop.
A leaner __git_ps1 function (~50%) for slow systems
# Original __git_ps1
$ time orig__git_ps1 || 0
(my-branch)
real 0m1.102s
user 0m0.000s
sys 0m0.140s
# Lean function
$ time __git_ps1 || 0
(my-branch)
real 0m0.586s
user 0m0.000s
sys 0m0.077s
# Keep original function definition
eval orig"$(declare -f __git_ps1)"
function __git_ps1 {
set -e
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
echo " ($branch)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment