X-Git-Url: http://www.git.stargrave.org/?p=torn.git;a=blobdiff_plain;f=torn.zsh;fp=torn.zsh;h=bc23537e603335664187ee70bf70925641a31ba4;hp=700d33b4f666e3041726e8d804329e7558fd5c04;hb=69f734abb273f95e7238c380502cc605884fba57;hpb=df1313d20a5f0337981d99a0c3ce908886f7fd13 diff --git a/torn.zsh b/torn.zsh index 700d33b..bc23537 100755 --- a/torn.zsh +++ b/torn.zsh @@ -10,6 +10,7 @@ # to be used with zsh'es glob expansion. # # * transliterates everything +# * replaces non FAT-compatible characters with underscores # * replaces spaces with underscores # * lowercases file's extension # * replaces "_-_" with single dash @@ -28,6 +29,8 @@ # $ torn # assume that it is not autoloaded # $ zmv "*" '`tornt $f`' # +# torna() replaces non FAT-compatible characters with underscores. +# # Recursively dive into subdirectories: # $ zmv -Q "(**/)*(.)" '`torn $f`' @@ -62,8 +65,20 @@ tornm() { print -- $n } +torna() { + local n=$1 + setopt REMATCH_PCRE + for i ({1..${#n}}) { + [[ ${n[$i]} =~ "[[:ascii:]]" ]] || n[$i]=_ + [[ ${n[$i]} =~ "[[:print:]]" ]] || n[$i]=_ + [[ ${n[$i]} =~ "[^,+/:;<=>?[]|]" ]] || n[$i]=_ + } + print -- $n +} + [[ -n $1 ]] || exit local n=${1:t} n=`tornm $n` n=`tornt $n` +n=`torna $n` print -- ${1:h}/$n