#!/bin/bash
# rtree 2.0
# 1.使用dotglob代替(.* *)
# 2.将修饰内容定向到stderr
# 可用rtree 2>/dev/null显示单色文本
shopt -s dotglob # 允许以.开头的文件被*匹配
##Functions
lines() {
line=
for t in `eval echo {0..$level}`;do
line="${line}\t|"
done
}
list_files() {
files=(*)
for file in ${files[@]};do
if [ ! "$file" = '*' ];then # 如果目录下没有文件,*保留字符意义
if [ -d "$file" ];then
echo -ne "$line"
echo -ne "\e[34;1m">&2
echo -ne "$file"
echo -ne "\e[0m/">&2
echo
change_dir
elif [ -L "$file" ];then
echo -ne "$line"
echo -ne "\e[36;1m">&2
echo -ne "$file"
echo -ne "\e[0m@">&2
echo
elif [ -p "$file" ];then
echo -ne "$line"
echo -ne "\e[33m">&2
echo -ne "$file"
echo -ne "\e[0m|">&2
echo
elif [ -x "$file" ];then
echo -ne "$line"
echo -ne "\e[1;32m">&2
echo -ne "$file"
echo -ne "\e[0m*">&2
echo
else
echo -ne "$line"
echo -ne "$file"
echo
fi
fi
done
}
change_dir() {
if [ -d "$file" ];then
cd "$file"
((level++))
lines
list_files
cd ..
((level--))
lines
fi
}
##Start
t=0
level=0
lines
cd "$*"
echo "$PWD"
list_files
exit