Dedupe $PATH
For whatever reason, I was seeing duplication on my $PATH and it was really annoying me, as it would include binary paths more than once. I suspect the root cause was something in my messy (nearly 10 year old) Emacs config, but going through that was more pain than just hacking together a small dedupe path function and calling it as the last thing in my .bashrc.
dedupe_path() {
local p new=
local -a paths
IFS=: read -ra paths <<<"$PATH"
for p in "${paths[@]}"; do
if [[ -n "$p" && ":$new:" != *":$p:"* ]]; then
new="${new:+$new:}$p"
fi
done
export PATH="$new"
}
This works well, so where before I'd see 2 or 3 cargo programs in my path, now I just see the 1. Yes there are problems with this, there is no checking. But that can be a later problem to fix if at all.