Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: removing spaces from a file name



On 30/01/2008, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 30/01/2008, zzapper <david@xxxxxxxxxx> wrote:
> > Hi
> > I still dislike spaces in file names:-
> >
> > mv Licence\ to\ Print\ Money.pdf !#^:gs/ //
> >
> > Is there a better/other way?
>
> You could define a function in your .zshrc (or make a script in your
> ~/bin or something) that does it for you
> function renamespaces() { for a ($@) {mv $a ${a// } } }

If you're the kind of person who likes keybinds, I guess this works
too, if you have copy-earlier-word bound somewhere too.

autoload -U modify-current-argument
function _stripspaces() { modify-current-argument '${ARG//\\ }' }
zle -N _stripspaces
bindkey 'somekey' _stripspaces
bindkey 'anotherkey' copy-earlier-word

To use it you just type mv file\ with\ spaces as usual, then press
anotherkey and somekey, and you should end up with mv file\ with\
spaces filewithspaces
an obvious weakness of this solution is it depends on the type of
quoting used in the previous word. Maybe better to change to
${(q)${(Q)ARG// }}

The only good thing about this solution is it isn't specific to moving
files, you can use it for cp, ln -s, or whatever you want. That isn't
so hard to achieve with the function now that i think about it:
function nospace() {
  cmd=$1
  shift
  for a ($@) {$cmd $a ${a// } } }
}

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author