本次输入法使用: 手心输入法 for Mac 1.0版
测试环境为:Ubuntu 14.14.2 LTS updates
测试时间为:2015年5月28日,感觉死亡将至的夜晚,独自一人坐在一个角落,戴着耳机盖着帽子,穿着衬衫的那一天,外面下着雨,不小不大,不紧不慢,却分外的让人不自然,写到这里放的歌是:苏运莹的《野子》
主要解决了特殊用法(为制定参数,. ,..,*的使用)
-d 检测是否为directory时,如果参数为空,也会被错误的认为目录,这是bash的一个诟病吗?应该吧,不过结合-z选项就可以解决。但是问题的关键是我以为-d是会识别的,其实我高估了-d,[see line 34-36]
function lz() {
function du_dir() {
echo -e "\033[01;33m$1\033[00m" # $((RANDOM%6+1))
(cd $; ls - >/dev/null | sed -e 's/^/"/' -e 's/$/"/'| xargs du -h -d >/dev/null)
}
function du_file() {
(ls -lha $ | awk '{print $5,$9}')
}
function getpath() { # support . and .. as the special path
cd $
echo `pwd`
}
function usage(){
echo -e " \033[01;37musage:\033[00m le [dir]/[file] ..."
echo " if no arguement is given, 'lz' will print the current working dir"
echo " .(current dir), ..(parent dir), *(metachar) are supported"
echo -e "\n -V/-h for this help page"
echo -e " \n--------------------------------------------------\n lz v0.1 by Ray Lee - March 30, 2015"
echo -e " updates:\n 1.clone 'le' as 'lz', new feature added\n 2.empty parameter doesn't work"
echo -e " ^\n lz v0.2 by Ray Lee - may 28, 2015"
echo -e " updates: \n 1.make the empty arg work, printing the current directory\n 2.-V and -h works\n 3.add comments for code block\n 4.modify the help page"
}
default='.'
args=($@)
if [[ ${#args[@]} -gt ]]; then
## the * meta means all the things in the current directory, length of it is gt 1 when current dir contains
## more than 1 thing, 1 if there is only one thing, le 1 when empty
28 ##
for each in ${args[@]}; do
[ -d $each ] && du_dir `getpath $each` || du_file `getpath $each`
done
elif [ ! -z $ ]; then
## The oddness of the -d option for file test is that it recognises the empty as a directory
34 ## So the -z should be used to make -d solid for empty args.
35 ##
if [ -d $ ]; then # support . and .. as the special path
du_dir `getpath $`
elif [[ $ == '-V' ]]; then
usage
elif [[ $ == '-h' ]]; then
usage
fi
else
du_dir `getpath "."`
fi
}
Results:
Reference:
1. http://www.cnblogs.com/raybiolee/p/4240363.html