2015-04-01 22:26:37 -07:00
|
|
|
#!/usr/bin/env bash
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-07-29 10:40:15 -07:00
|
|
|
: $((SOURCING+=1))
|
2021-07-29 05:44:12 -07:00
|
|
|
. ~/sh/ea # FIXME: don't do this? somehow?
|
2021-07-29 10:40:15 -07:00
|
|
|
: $((SOURCING-=1))
|
2015-04-01 22:26:37 -07:00
|
|
|
|
|
|
|
sc_shorten() {
|
|
|
|
REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# http://stackoverflow.com/a/10797966
|
|
|
|
uri_encode() {
|
|
|
|
REPLY="$(echo -En "$@" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "")"
|
|
|
|
REPLY="${REPLY:2}"
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_scr() {
|
|
|
|
local fn="$1"
|
|
|
|
local short="$(basename $fn)"
|
|
|
|
local r='20\d\d-\d\d-\d\d_\d\d\d\d\d\d\d\d.(png|jpg)'
|
|
|
|
grep -Pq "$r" <<<"$short" || return 1
|
|
|
|
|
2017-03-02 23:24:01 -08:00
|
|
|
eaput "$fn" "$short"
|
2015-04-01 22:26:37 -07:00
|
|
|
sc_shorten "$short"
|
|
|
|
uri_encode "$REPLY"
|
2017-03-02 23:24:01 -08:00
|
|
|
REPLY="$_REMOTE_DOMAIN/s/$REPLY"
|
2015-04-01 22:26:37 -07:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_tmp() {
|
|
|
|
local fn="$1"
|
|
|
|
local short="$(basename "$fn")"
|
|
|
|
|
2017-03-02 23:24:01 -08:00
|
|
|
eaput "$fn" "$short"
|
2015-04-01 22:26:37 -07:00
|
|
|
uri_encode "$short"
|
2017-03-02 23:24:01 -08:00
|
|
|
REPLY="$_REMOTE_DOMAIN/t/$REPLY"
|
2015-04-01 22:26:37 -07:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
sc() {
|
|
|
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
|
|
|
# syntax is too different to bother tbh
|
|
|
|
echo "please run with bash"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
which xsel &>/dev/null || {
|
|
|
|
echo "please install xsel"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
local clipboard=""
|
|
|
|
for f; do
|
|
|
|
f="$(readlink -f "$f")"
|
|
|
|
if [ ! -e "$f" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
copy_scr "$f" || copy_tmp "$f"
|
|
|
|
clipboard="$clipboard"$'\n'"$REPLY"
|
|
|
|
done
|
|
|
|
xsel -b <<<"${clipboard:1}"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-07-29 05:44:12 -07:00
|
|
|
[ "${SOURCING:-0}" -gt 0 ] || sc "$@"
|