The zsh :t modifier works like basename, but executes much faster (because it's a builtin).
I ran this a few times and saw an average speed increase of 50x.
~
➜ time (for k in `seq 1000`; do echo $(basename $foo) >/dev/null; done; )
( for k in `seq 1000`; do; echo $(basename $foo) > /dev/null; done; ) 0.03s user 0.27s system 28% cpu 1.071 total
~
➜ time (for k in `seq 1000`; do echo $foo:t >/dev/null; done; )
( for k in `seq 1000`; do; echo $foo:t > /dev/null; done; ) 0.01s user 0.00s system 85% cpu 0.019 total
~
➜ echo $foo && echo $(basename $foo) && echo $foo:t # basename & :t are equivalent
a/b/c
c
c
Thank you @nfischer for this wonderful info.
Currently basename is used only in venv segment. Could you please send a PR ?
@sfarzy I would love to send a PR, but my company strongly prefers that any project I contribute to includes a LICENSE file in the top-level of the repo (they consider it to be safer legally-speaking than a one-liner in the README). Would that be something you and the maintainers (@denysdovhan) would be interested in adding?
@nfischer Now we've separate LICENSE file in project 🎉
Most helpful comment
@nfischer Now we've separate LICENSE file in project 🎉