Two of the most expensive things a shell does are call fork
and call execve
for an external program. pwd
is a builtin (at least for bash) but the former still applies. $PWD
exists even if you don’t want that shortening; just like your backticks be sure to quote it once so it doesn’t get expanded when assigning to PS1.
In general, for most things you might want to do, you can arrange for variables to be set ahead of time and simply expanded at use time, rather than recalculating them every time. For example, you can hook cd
/pushd
/popd
to get an actually-fast git
prompt. Rather than var=$(some_function)
you should have some_function
output directly to a variable (possibly hard-coded - REPLY
is semi-common; you can move the value later); printf -v
is often useful. Indirection should almost always be avoided (unless you do the indirect-unset bash-specific hack or don’t have any locals) due to shadowing problems (you have to hard-code variable name assumptions anyway so you might as well be explicit).
I’ve only ever seen two parts of git that could arguably be called unintuitive, and they both got fixes:
git reset
seems to do 2 unrelated things for some people. Nowadaysgit restore
exists.a..b
anda...b
commit ranges in various commands. This is admittedly obscure enough that I would have to look up the manual half the time anyway.man git foo
didn’t used to work unintuitive I guess.The tooling to integrate
git submodule
into normal tree operations could be improved though. But nowadays there’sgit subtree
for all the people who want to do it wrong but easily.The only reason people complain so much about git is that it’s the only VCS that’s actually widely used anymore. All the others have worse problems, but there’s nobody left to complain about them.