commit 8ca1af0abf986b0881b38c32ed283bc07ba78d2a
parent 648306b85ad72c21716ada5626d8983d62efb155
Author: William Casarin <bill@casarin.me>
Date: Mon, 22 Feb 2016 16:20:33 -0800
hashname
Diffstat:
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/hashname b/hashname
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+hash=$(sha1sum "$1" | awk '{ print $1 }')
+hashlen=${2:-16}
+shorthash=${hash:0:$hashlen}
+filename=$(basename "$1")
+if [[ $filename == *.* ]]; then
+ ext="${filename##*.}"
+ sfilename="${shorthash}.${ext}"
+else
+ sfilename="${shorthash}"
+fi
+echo $sfilename
diff --git a/hashshare b/hashshare
@@ -1,8 +0,0 @@
-#!/usr/bin/env bash
-hash=$(sha1sum "$1" | awk '{ print $1 }')
-hashlen=${2:-16}
-shorthash=${hash:0:$hashlen}
-filename=$(basename "$1")
-ext="${filename##*.}"
-sfilename="${shorthash}.${ext}"
-sharefile -n $sfilename $1
diff --git a/sharefile b/sharefile
@@ -29,9 +29,6 @@ missing_env() {
while getopts "h?n:u:d:" opt; do
case "$opt" in
- h|\?)
- show_help
- ;;
n)
name="$OPTARG"
;;
@@ -41,6 +38,8 @@ while getopts "h?n:u:d:" opt; do
u)
SHAREFILE_URL="$OPTARG"
;;
+ h)
+ shouldHashName=1
esac
done
@@ -56,6 +55,8 @@ file="$1"
name="${name:-"$(basename "$file")"}"
dest="${SHAREFILE_HOST}\"${name}\""
+[[ $shouldHashName == 1 ]] && name="$(hashname "$file")"
+
rsync -zq --chmod=a=r "$file" "$dest"
-echo "${SHAREFILE_URL}$(urlencode "$(basename "${name}")")"
+echo "${SHAREFILE_URL}$(urlencode "$(basename "$name")")"