summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwgetpaste67
1 files changed, 37 insertions, 30 deletions
diff --git a/wgetpaste b/wgetpaste
index 42b1264..1903895 100755
--- a/wgetpaste
+++ b/wgetpaste
@@ -70,7 +70,7 @@ ca_POST=(s=Submit+Post name description type expiry "" content)
rafb_POST=("" nick desc lang "" cvt_tabs text)
osl_POST=(paste=Send poster "" format expiry "" code2)
sh_POST=("" poster "" "" "" "" code)
-# regex'es
+# regexes
ca_REGEX=('s|^\(http://[^/]\+/\)\([0-9]\+\)$|\1raw/\2|' 's|^.*content="[0-9]\+;\(http://[^/]\+/[0-9]\+\)".*$|\1|p')
rafb_REGEX=('s|html\?$|txt|')
osl_REGEX=('s|^\(http://[^/]\+/\)\([0-9]\+\)$|\1pastebin.php?dl=\2|')
@@ -134,8 +134,8 @@ EOF
show() {
echo "${1:0:1}${2:1}s supported by $(getrecipient) (case sensitive):"
local nr extra
- nr=$(eval "echo \"\${#${ENGINE}_${1}[@]}\"")
- [[ EXPIRATIONS == $1 ]] && extra=$(eval "echo \"\${${SERVICE}[3]}\"")
+ eval "nr=\"\${#{ENGINE}_${1}[@]}\""
+ [[ EXPIRATIONS == $1 ]] && eval "extra=\"\${${SERVICE}[3]}\""
[[ 0 = $nr ]] && echo -e "\n${extra}\"${SERVICE}\" has no support for setting ${2% *}." >&2
for ((i=0; i<${nr}; i++)); do
eval "echo \" \${${ENGINE}_${1}[i]}\""
@@ -144,7 +144,7 @@ show() {
show_services() {
echo "Services supported: (case sensitive):"
- local max arg IND INDV engine
+ local max arg IND INDV engine url
max=0
for arg in "${SERVICES[@]}"; do
[[ ${#arg} -gt $max ]] && max=${#arg}
@@ -153,14 +153,15 @@ show_services() {
if [[ $VERBOSE ]]; then
max=0
for s in "${SERVICES[@]}"; do
- arg=$(eval "echo \"\${${s}[1]}\"")
+ eval "arg=\"\${${s}[1]}\""
[[ ${#arg} -gt $max ]] && max=${#arg}
done
((INDV=3+${max}+${IND}))
fi
for ((i=0; i<${#SERVICES[*]}; i++)); do
[[ $VERBOSE ]] && eval "engine=$'\e'\"[${INDV}G- \${${SERVICES[i]}[0]}\""
- eval "echo -e \" ${SERVICES[i]} \e[${IND}G- \${${SERVICES[i]}[1]}${engine}\""
+ eval "url=\"\${${SERVICES[i]}[1]}\""
+ echo -e " ${SERVICES[i]} \e[${IND}G- ${url}${engine}"
done | sort
}
@@ -176,7 +177,8 @@ verify_service() {
}
verify() {
- local nr=$(eval "echo \"\${#${ENGINE}_${1}S[@]}\"")
+ local nr
+ eval "nr=\"\${#${ENGINE}_${1}S[@]}\""
if [[ $nr -gt 0 ]]; then
for ((i=0; i<${nr}; i++)); do
if [[ $(eval "echo \"\${${1}}\"") == $(eval "echo \"\${${ENGINE}_${1}S[i]}\"") ]]; then
@@ -201,19 +203,20 @@ verify() {
# get the url to post to for any given service
getrecipient() {
+ local target serv recip
if [[ RAW == $1 ]]; then
- local TARGET=$(eval "echo \"\${${SERVICE}[2]}\"")
+ eval "target=\"\${${SERVICE}[2]}\""
else
- local SERV="${SERVICE}: "
+ serv="${SERVICE}: "
fi
for s in "${SERVICES[@]}"; do
- [[ $s == $SERVICE ]] && eval "echo \"${SERV}\${${s}[1]}${TARGET}\"" && return 0
+ [[ $s == $SERVICE ]] && eval "recip=\"\${${s}[1]}\"" && echo "${serv}${recip}${target}" && return 0
done
die "Failed to get url for \"${SERVICE}\"."
}
# print a warning if failure is predictable due to the mere size of the paste. sh seems to be the most reliable
-# service in that regard. note that this is only a warning printed. it doesn't abort.
+# service in that regard. note that this is only a warning printed. it does not abort.
warnsize() {
warn() {
if [[ -n $2 && $1 -gt $2 ]]; then
@@ -227,45 +230,49 @@ warnsize() {
}
postdata() {
- local extra field sep nr
+ local extra field content
[[ 7 = $(eval "echo \"\${#${ENGINE}_POST[*]}\"") ]] || die "\"${SERVICE}\" is not supported by ${FUNCNAME}()."
- extra=$(eval "echo -n \"\${${ENGINE}_POST[0]}\"")
- nr=${#engines_POST[@]}
+ eval "extra=\"\${${ENGINE}_POST[0]}\""
[[ -n $extra ]] && echo -n "${extra}&"
- for ((i=1; i<${nr}; i++)); do
- field=$(eval "echo \"\${${ENGINE}_POST[i]}\"")
+ for ((i=1; i<6; i++)); do
+ eval "field=\"\${${ENGINE}_POST[i]}\""
[[ -z $field ]] && continue
- eval "echo -n ${field}=\"\${${engines_POST[i]}}&\""
+ eval "content=\"\${${engines_POST[i]}}\""
+ echo -n "${field}=${content}&"
done
- eval "echo \"\${${ENGINE}_POST[i]}=${INPUT}\""
+ eval "field=\"\${${ENGINE}_POST[i]}\""
+ echo "${field}=${INPUT}"
}
geturl() {
- local GET=$(eval "echo \"\${${ENGINE}_REGEX[1]}\"")
- if [[ -n $GET ]]; then
+ local regex
+ eval "regex=\"\${${ENGINE}_REGEX[1]}\""
+ if [[ -n $regex ]]; then
[[ needstdout == $1 ]] && return 0
- echo "$*" | sed -n "$GET"
+ echo "$*" | sed -n "$regex"
else
[[ needstdout == $1 ]] && return 1
echo "$*" | sed -n 's|^.*Location:\ \(http://[^\ ]\+\).*$|\1|p'
fi
}
-# verify that the pastebin service didn't return a known error url or print a helpful error message
+# verify that the pastebin service did not return a known error url or print a helpful error message
verifyurl() {
local urls i known
- (( urls=($(eval "echo \"\${#${ENGINE}_WARNS[@]}\"")-3)/2 ))
+ eval "urls=\"\${#${ENGINE}_WARNS[@]}\""
+ (( urls=(${urls}-3)/2 ))
for((i=0;i<urls;i++)); do
- known=$(eval "echo \"\${${ENGINE}_WARNS[3+2*i]}\"")
+ eval "known=\"\${${ENGINE}_WARNS[3+2*i]}\""
[[ -n $known && $known == $URL ]] && die "$(eval "echo \"\${${ENGINE}_WARNS[4+2*i]}\"")"
done
}
# if possible convert URL to raw
convert_to_raw() {
- local CONVERT=$(eval "echo \"\${${ENGINE}_REGEX[0]}\"")
- if [[ -n $CONVERT ]]; then
- RAWURL=$(echo "${URL}" | sed -e "$CONVERT")
+ local convert
+ eval "convert=\"\${${ENGINE}_REGEX[0]}\""
+ if [[ -n $convert ]]; then
+ RAWURL=$(echo "${URL}" | sed -e "$convert")
return 0
fi
echo "Raw download of pastes is not supported by $(getrecipient)." >&2
@@ -413,7 +420,7 @@ done
# set default service, nick, source and tabs convertion
SERVICE=${SERVICE:-${DEFAULT_SERVICE}}
-ENGINE=$(eval "echo \"\${${SERVICE}[0]}\"")
+eval "ENGINE=\"\${${SERVICE}[0]}\""
[[ -n $(eval "echo \"\${DEFAULT_NICK_${SERVICE}}\"") ]] && NICK=${NICK:-$(eval "echo \"\${DEFAULT_NICK_${SERVICE}}\"")}
NICK=${NICK:-$(escape "${DEFAULT_NICK}")}
[[ -z $SOURCE ]] && SOURCE="stdin" && FILES[${#FILES[*]}]="/dev/stdin"
@@ -503,7 +510,7 @@ EOF
fi
;;
files | stdin )
- # handle the case where the input source (defaulting to /dev/stdin) isn't readable verbosely
+ # handle the case where the input source (defaulting to /dev/stdin) is not readable verbosely
if [[ ${#FILES[*]} -gt 1 ]]; then
for f in "${FILES[@]}"; do
[[ -r $f ]] || \
@@ -567,7 +574,7 @@ fi
# get the url
URL=$(geturl "$OUTPUT")
-# verify that the pastebin service didn't return a known error url such as toofast.html from rafb
+# verify that the pastebin service did not return a known error url such as toofast.html from rafb
# uses ${SERVICE} and ${URL}.
verifyurl