diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2011-03-09 23:23:59 -0500 |
---|---|---|
committer | Brendan Taylor <whateley@gmail.com> | 2011-03-13 22:17:35 -0600 |
commit | 8572aefe9cfd0e58e3fa4021183285095670a6fa (patch) | |
tree | 67694efd4d3bc312172254415ef97ce9bfeadd74 /examples/data/scripts/download.sh | |
parent | 3cc75534065c0775dfea171b1b96cc3d2b7243a0 (diff) |
Add a skeleton so users can improve downloads
Diffstat (limited to 'examples/data/scripts/download.sh')
-rwxr-xr-x | examples/data/scripts/download.sh | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 7753bd6..ca8728c 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,5 +1,4 @@ #!/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 @@ -10,18 +9,43 @@ # the URL that is being downloaded uri="$1" +shift safe_uri="$( echo "$uri" | sed -e 's/\W/-/g' )" # a filename suggested by the server or based on the URL -suggested_filename="${2:-$safe_uri}" +suggested_filename="${1:-$safe_uri}" +shift # the mimetype of the file being downloaded -content_type="$3" +content_type="$1" +shift # 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" +total_size="$1" +shift -# just save the file to the default directory with the suggested name -echo "$UZBL_DOWNLOAD_DIR/$suggested_filename" +case "$suggested_filename" in + # Default case + *) + path="$UZBL_DOWNLOAD_DIR/$suggested_filename" + ;; +esac + +# Do nothing if we don't want to save the file +[ -z "$path" ] && exit 0 + +# Check if the file exists +if [ ! -e "$path" ]; then + echo "$path" + exit 0 +fi + +# Try to make a unique filename +count=1 +while [ -e "$path.$count" ]; do + count=$(( $count + 1 )) +done + +echo "$path.$count" |