Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So after some time of searching on google and superuser (and scanning man pages) I was unable to find an answer to something that (I think) should be simple:

If you go here: http://www.vim.org/scripts/script.php?script_id=2340 and try to download the theme: http://www.vim.org/scripts/download_script.php?src_id=9750

like so:

wget http://www.vim.org/scripts/download_script.php?src_id=9750

you'll probably end up with a file called "download_script.php?src_id=9750"

But I want it to be called "molokai.vim", which is what would happen if I used a browser to download this file.

Question: what options do I need to specify for wget for the desired effect?

I'd also be ok with a curl command. Thanks

share|improve this question

3 Answers 3

up vote 33 down vote accepted
-O file
--output-document=file

The documents will not be written to the appropriate files, but all will be concatenated together and written to file. If - is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.)

So,

wget -O somefile.extension http://www.vim.org/scripts/download_script.php?src_id=9750

Or you may be able to get wget to work this out using the --content-disposition option if supported by your version.

wget --content-disposition http://www.vim.org/scripts/download_script.php?src_id=9750

Caveats as per the man page,

--content-disposition

If this is set to on, experimental (not fully-functional) support for "Content-Disposition" headers is enabled. This can currently result in extra round-trips to the server for a "HEAD" request, and is known to suffer from a few bugs, which is why it is not currently enabled by default.

This option is useful for some file-downloading CGI programs that use "Content-Disposition" headers to describe what the name of a downloaded file should be.

You can achieve the same automated behaviour with curl, using,

curl -J -O http://www.vim.org/scripts/download_script.php?src_id=9750

-O uses the remote name, and -J forces the -O to get that name from the content-disposition header rather than the URL.

share|improve this answer
    
I should've specified that this needs to be automatic –  audio.zoom Jun 23 '11 at 12:05
    
As I understand it, wget relies on the web page to correctly inform it if the URL points to a file and it needs to be saved with something different, using the content disposition header, which wget may or may not fully support. So you can't do it automagically with wget. Curl may have more or less success depending on the web page. –  EightBitTony Jun 23 '11 at 12:08
    
the point is to be able to script these things without complicated parsing, curl is fine but so far i haven't been able to collect decent options for that either –  audio.zoom Jun 23 '11 at 12:14
    
So, running wget -S you can see the page does return a content disposition entry, Content-Disposition: attachment; filename=molokai.vim, which suggests it's not fixable. wget just isn't coping. –  EightBitTony Jun 23 '11 at 12:19
1  
Aha - I'm wrong, see updated answer. This is why stackexchange sites work well - everyone learns something, even people answering the questions! –  EightBitTony Jun 23 '11 at 12:20

Just fyi curl redirects well, so using the following should work, I think, for what you are looking for.

curl -o molokai.vim http://www.vim.org/scripts/download_script.php?src_id=9750

share|improve this answer

With wget you can do this:

wget --trust-server-names <url> 

to save the file using the last file name the server gives you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.