aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data/scripts/download.sh
blob: 448e0866005793bc3af7f28879b8af6252c85b2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
#
# uzbl's example configuration sets this script up as its download_handler.
# when uzbl starts a download it runs this script.
# if the script prints a file path to stdout, uzbl will save the download to
# that path.
# if nothing is printed to stdout, the download will be cancelled.

. "$UZBL_UTIL_DIR/uzbl-dir.sh"

# the URL that is being downloaded
uri="$1"

safe_uri="$( printf "$uri" | sed -e 's/\W/-/g' )"

# a filename suggested by the server or based on the URL
suggested_filename="${2:-$safe_uri}"

# the mimetype of the file being downloaded
content_type="$3"

# the size of the downloaded file in bytes. this is not always accurate, since
# the server might not have sent a size with its response headers.
total_size="$4"

# just save the file to the default directory with the suggested name
printf "$UZBL_DOWNLOAD_DIR/$suggested_filename\n"