I'm making some command line tools that output progress information as it runs to STDERR, like
found document
using cached version
analyzing
etc.
Should I output full sentences with capitalized first letters 开发者_StackOverflow中文版and periods at the end, or is this kind of terse uncapitalized output OK? What's the expert consensus on this?
My favorite method to denote progress is a 'spinner'. Here is one I implemented using bash
. The first parameter is the PID of the process you want to track and the second parameter is an optional message. The PID is most easily passed via $(pgrep <some_process_name>)
#!/bin/bash
spinner() {
[[ -n "$2" ]] && echo -n "$2 "
if [[ ! $1 =~ ^[[:digit:]]+$ ]]; then
return
fi
while [[ -d /proc/$1 ]]; do
for c in '/' '-' '\' '|'; do
printf "%c\b" "$c"
sleep 0.1
done
done
printf " \n"
}
du /usr > /dev/null 2>&1 & # Example program to monitor
spinner $(pgrep du) "Optional Message Here"
精彩评论