Permalink
Browse files

walk: add -f(iles-only) option

  • Loading branch information...
1 parent 17f2ed4 commit e37e9d66b40f2b04cfc2970457fd4ff3af75422e @falconindy committed May 30, 2012
Showing with 14 additions and 5 deletions.
  1. +14 −5 walk
View
19 walk
@@ -9,6 +9,7 @@ shopt -s nullglob
indent=0
ind_sz=3
dirs_first=0
+files_only=0
printentry() {
printf "%*s%s\n" "$indent" "" "$1"
@@ -26,24 +27,32 @@ get_pwd_contents() {
walk() {
local dir_contents
- printentry "$(printf "\e[0;34m%s\e[0m" "$1")"
- (( indent += ind_sz ))
+ if (( !files_only )); then
+ printentry "$(printf "\e[0;34m%s\e[0m" "$1")"
+ (( indent += ind_sz ))
+ fi
+
pushd "$1" &>/dev/null
(( dirs_first )) && get_pwd_contents || dir_contents=(*)
for entry in "${dir_contents[@]}"; do
- [[ -d $entry && ! -L $entry ]] && walk "$entry" || printentry "$entry"
+ if [[ -d $entry && ! -L $entry ]]; then
+ walk "$entry"
+ else
+ printentry "$entry"
+ fi
done
- (( indent -= ind_sz ))
+ (( !files_only )) && (( indent -= ind_sz ))
popd &>/dev/null
}
-while getopts "ad" opt; do
+while getopts "afFd" opt; do
case $opt in
a) shopt -s dotglob ;;
d) dirs_first=1 ;;
+ f) files_only=1 ;;
esac
done
shift $(( OPTIND - 1 ))

0 comments on commit e37e9d6

Please sign in to comment.