=== modified file 'bin/fslist' --- bin/fslist 2013-09-26 20:16:05 +0000 +++ bin/fslist 2013-09-26 20:09:40 +0000 @@ -32,61 +32,60 @@ delim='' } -fnames=( ) for arg in "${@:-$PWD}"; do - fnames+=( $arg:a ) - [[ -d $arg ]] && fnames+=( $arg:a/**/* ) -done - -for fname in $fnames; do - zstat -LH s $fname || continue - ftype=$(( [##16] $s[mode] >> 12 )) - fmode=$(( [##8] $s[mode] & 8#7777 )) - t=$ftypes[$ftype] - - if [[ $fname == *$'\t'* || $fname == *$'\n'* ]]; then - statement $'P\t'$fname $'\t' + if [[ -d $arg ]]; then + fnames=( $arg:a/**/* ) else - statement $fname + fnames=( $arg:a ) fi + for fname in $fnames; do + zstat -LH s $fname || continue + ftype=$(( [##16] $s[mode] >> 12 )) + fmode=$(( [##8] $s[mode] & 8#7777 )) + t=$ftypes[$ftype] - if [[ $t != d && $s[nlink] -gt 1 ]]; then - id=$s[device]:$s[inode] - if (($+hardlinks[$id])); then - statement $'H\t'$hardlinks[$id] $'\n' - continue + if [[ $fname == *$'\t'* || $fname == *$'\n'* ]]; then + statement $'P\t'$fname $'\t' else - hardlinks[$id]=$fname - fi - fi - - if [[ $t == [BC] ]]; then - statement $t$(( $s[rdev] >> 8 )):$(( $s[rdev] & 255 )) - elif [[ $t == l ]]; then - statement $'l\t'$s[link] $'\t' - elif [[ $t == f ]]; then - IFS= read -r -d '' content <$fname - flags='' - if [[ $content == *$'\n' ]]; then - content=${content%$'\n'} + statement $fname + fi + + if [[ $t != d && $s[nlink] -gt 1 ]]; then + id=$s[device]:$s[inode] + if (($+hardlinks[$id])); then + statement $'H\t'$hardlinks[$id] $'\n' + continue + else + hardlinks[$id]=$fname + fi + fi + + if [[ $t == [BC] ]]; then + statement $t$(( $s[rdev] >> 8 )):$(( $s[rdev] & 255 )) + elif [[ $t == l ]]; then + statement $'l\t'$s[link] $'\t' + elif [[ $t == f ]]; then + IFS= read -r -d '' content <$fname + flags='' if [[ $content == *$'\n' ]]; then - # force appending newline - flags+=n - fi - else - flags+=N - fi - if [[ $content == *$'\t'* || $content == *$'\n'* ]]; then - statement C$flags$'\t'$content $'\n' - else - statement c$flags$'\t'$content $'\n' - fi - else - statement $t - fi - statement o$s[uid]:$s[gid] - statement m$fmode - statement_end + content=${content%$'\n'} + if [[ $content == *$'\n' ]]; then + # force appending newline + flags+=n + fi + else + flags+=N + fi + if [[ $content == *$'\t'* || $content == *$'\n'* ]]; then + statement C$flags$'\t'$content $'\n' + else + statement c$flags$'\t'$content $'\n' + fi + fi + statement o$s[uid]:$s[gid] + statement m$fmode + statement_end + done done # while getopts omcaOMC o