* enum-files and change-ext
@ 2019-03-23 19:49 Emanuel Berg
2019-03-23 20:02 ` Emanuel Berg
0 siblings, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2019-03-23 19:49 UTC (permalink / raw)
To: zsh-users
Hello, I just wrote this. [1]
Is it any good? :)
TIA
enumerate-files () {
local -a files
files=($@)
local number=1
for f in $files; do
if [[ -f $f ]]; then
mv $f ${number}.${f:e}
number=$(( $number + 1 ))
else
no-file-msg $f # http://user.it.uu.se/~embe8573/conf/.zsh/error
fi
done
}
alias enum-files=enumerate-files
change-extention () {
local new_extention=$1
shift
local -a files
files=($@)
for f in $files; do
if [[ -f $f ]]; then
mv $f ${f:r}.$new_extention
else
no-file-msg $f
fi
done
}
alias change-ext=change-extention
[1] lines 11-42 @ http://user.it.uu.se/~embe8573/conf/.zsh/files-fs
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: enum-files and change-ext
2019-03-23 19:49 enum-files and change-ext Emanuel Berg
@ 2019-03-23 20:02 ` Emanuel Berg
2019-03-24 17:52 ` Daniel Shahaf
0 siblings, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2019-03-23 20:02 UTC (permalink / raw)
To: zsh-users
> Hello, I just wrote this. [1]
>
> Is it any good? :)
No they are not! "enumerate-files" only works
once, if you then remove some files you can't
run it again... OK, I'm on it...
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: enum-files and change-ext
2019-03-23 20:02 ` Emanuel Berg
@ 2019-03-24 17:52 ` Daniel Shahaf
2019-03-26 5:29 ` Emanuel Berg
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2019-03-24 17:52 UTC (permalink / raw)
To: zsh-users
Emanuel Berg wrote on Sat, 23 Mar 2019 20:06 +00:00:
> > Hello, I just wrote this. [1]
> >
> > Is it any good? :)
>
> No they are not! "enumerate-files" only works
> once, if you then remove some files you can't
> run it again... OK, I'm on it...
See also 'zmv' in zshcontrib(1), as well as vidir(1) from moreutils.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: enum-files and change-ext
2019-03-24 17:52 ` Daniel Shahaf
@ 2019-03-26 5:29 ` Emanuel Berg
0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2019-03-26 5:29 UTC (permalink / raw)
To: zsh-users
This seems to do better... so far.
#! /bin/zsh
# This file: http://user.it.uu.se/~embe8573/conf/.zsh/files-fs
enumerate-files () {
local -a files
files=($@)
local number=1
local new_name
local ext
for f in $files; do
if [[ -f $f ]]; then
ext=${f:e}
[[ $ext ]] && ext=.$ext
new_name=$number$ext
if [[ -f $new_name ]]; then
files+=($f)
else
mv $f $new_name
fi
number=$(( $number + 1 ))
else
no-file-msg $f # http://user.it.uu.se/~embe8573/conf/.zsh/error
fi
done
}
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-26 5:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-23 19:49 enum-files and change-ext Emanuel Berg
2019-03-23 20:02 ` Emanuel Berg
2019-03-24 17:52 ` Daniel Shahaf
2019-03-26 5:29 ` Emanuel Berg
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).