<<< Date Index >>>     <<< Thread Index >>>

Re: attaching files from a list?



Hi Cameron!

On Tue, 27 May 2008, Cameron Simpson wrote:

> On 25May2008 11:16, Vladimir Marek <Vladimir.Marek@xxxxxxx> wrote:
> | > Is there some way, from the compose view in mutt, to attach given
> | > files whose paths/filenames I have previously collected in a text file?
> | 
> | Not exactly in compose view, but you may attach files directly when
> | editing the message. Just set "set edit_headers" in your
> | .muttrc, and then add files using new 'header' "Attach: filename".
> | 
> | Using vim it is pretty easy to generate list of "Attach: ..." lines,
> | using other editors I guess too.
> 
> To make this easy (getting readline to do filename completion) I do
> this:
> 
>   http://does-not-exist.org/mail-archives/mutt-users/msg12098.html

Additionally, using Vim, you could also make use of Vims scripting 
functionality. Out of curiosity I have written the attached script 
file, which makes attaching files within Vim easier.

Just source attach.vim when editing your mail. The script defines 2 
new commands :AttachFile and :AttachList.

If you want to attach a single file, use :AttachFile filename
The command will do filename completion.

If you rather want to attach all files listed within a file (as the OP 
originally asked for), you can use the :AttachList command. This also 
allows filename completion. So you could do this:
$ find . -type f > attachmentlist
[ call mutt, start editing your mail using vim, source attached 
script]
:AttachList ~/attachmentlist
and vim will include as many Attach: headers as there are files in 
your list file.

Be aware, that I did not thoroughly test the attached script. It 
should however work out of the box with a vim version > 7.

regards,
Christian
-- 
:wq!
function! Attach(Filename)
    normal magg}-
    let list =[]
    for line in readfile(a:Filename)
        let list+=['Attach: '.line]
    endfor
    call append(line('.'), list)
    normal `a
endfunction

command! -nargs=1 -complete=file AttachList :call Attach("<args>")
command! -nargs=1 -complete=file AttachFile exe "normal magg}-" | call 
append(line('.'), 'Attach: <args>') | normal `a