function t() {
local depth=2
if [[ $# -ge 1 && $1 -ge 1 ]]; then
depth=$1
# shift arguments
shift
fi
if [[ -x $(whence -p tree) ]]; then
command tree --gitignore -h -L $depth $@
elif [[ -x $(whence -p exa) ]]; then
command exa --tree --git-ignore -L $depth $@
elif [[ -x $(whence -p lsd) ]]; then
command lsd --tree -I node_modules --depth $@
else
echo 'there is no tree'
fi
}
터미널에서 가장 많이/자주 사용하는 명령이라면 단연 ls
일 것이다. 아마 그 다음은 tree
가 차지할 것이다.
최신 ls 프로그램들은 자체적으로 tree 기능을 지원한다. 하지만 역사와 전통의 tree 명령도 무시할 수 없는 수준으로 계속 발전하고 있다.
이들을 사용하는 zsh 용 함수를 만들어 보았다. zsh 용이라고 한 이유는 whence 때문이다.
사용된 문법을 좀 보면,
이 함수를 l1
, l2
, l3
정도 alias 해두 면 유용하다.