diff options
author | Bo Ørsted Andresen <bo.andresen@zlin.dk> | 2007-09-08 04:19:36 +0000 |
---|---|---|
committer | Bo Ørsted Andresen <bo.andresen@zlin.dk> | 2007-09-08 04:19:36 +0000 |
commit | 2ff69ce629fa9b98d11ba6f103a53e94f1c4f534 (patch) | |
tree | b3da0864f9120feb1c701345c4ea7e8010e44452 | |
parent | f6a4847122566742d8f444faa87162eff208acb2 (diff) | |
download | wgetpaste-2ff69ce629fa9b98d11ba6f103a53e94f1c4f534.tar.gz |
Kill every invocation of eval. This means that configuration variables for services and engines etc. can no longer be arrays. Instead they are now lists of strings separated by spaces and using underscores as spaces in each item. At the same time they have been renamed to increase consistency and reduce complexity.
-rwxr-xr-x | wgetpaste | 425 |
1 files changed, 257 insertions, 168 deletions
@@ -28,52 +28,73 @@ showurl() { INFO_COMMAND="emerge --info" INFO_ARGS="--ignore-default-opts" -### service definitions - -SERVICES=(ca rafb osl sh) - -# ENGINE URL RAW EXPIRE_INFO -ca=(ca http://pastebin.ca/) -rafb=(rafb http://rafb.net/paste/ paste.php "Pastes on rafb: http://rafb.net/paste/ expire after 24 hours.\n") -osl=(osl http://pastebin.osuosl.org/ pastebin.php) -sh=(sh http://sh.nu/p/) - -### engine definitions - -# languages -ca_LANGUAGES=(Plain\ Text Asterisk\ Configuration C C++ PHP Perl Java VB C\# Ruby Python Pascal \ -mIRC PL/I XML SQL Scheme ActionScript Ada Apache\ Configuration Assembly\ \(NASM\) ASP Bash CSS \ -Delphi HTML\ 4\.0\ Strict JavaScript LISP Lua Microprocessor\ ASM Objective\ C VB\.NET) -ca_LANGUAGE_COUNT=0 -rafb_LANGUAGES=(C C89 C99 C++ C\# Java Pascal Perl PHP PL\/I Python Ruby SQL VB Plain\ Text) -osl_LANGUAGES=(Plain\ Text ActionScript Ada Apache\ Log\ File AppleScript Assembly\ \(NASM\) \ -ASP Bash C C\ for\ Macs CAD\ DCL CAD\ Lisp C++ C\# ColdFusion CSS D Delphi Diff DOS Eiffel Fortran \ -FreeBasic Game\ Maker HTML\ 4\.0\ Strict INI\ file Java Javascript Lisp Lua MatLab Microprocessor\ ASM \ -MySQL NullSoft\ Installer Objective\ C OCaml Openoffice\.org\ BASIC Oracle\ 8 Pascal Perl PHP Python \ -QBasic Robots\.txt Ruby Scheme Smarty SQL TCL VB VB\.NET VisualFoxPro XML) -osl_LANGUAGE_VALUES=(text actionscript ada apache applescript asm asp bash c c\ mac caddcl \ +### SERVICES ### _s = a specific service ### +#ENGINE_s +#URL_s +#EXPIRATION_INFO_s +#DEFAULT_NICK_s DEFAULT_LANGUAGE_s DEFAULT_EXPIRATION_s +#SIZE_s LINES_s +#TOOFAST_s TOOBIG_s +### ENGINES ### _s = a specific engine ### +#LANGUAGES_e LANGUAGE_COUNT_e LANGUAGE_VALUES_e +#EXPIRATIONS_e EXPIRATION_COUNT_e EXPIRATION_VALUES_e +#POST_e +#REGEX_URL_e +#REGEX_RAW_e + +### services +SERVICES="ca rafb osl sh" +# ca +ENGINE_ca=ca +URL_ca="http://pastebin.ca/" +SIZE_ca="1024000 1_MB" +# rafb +ENGINE_rafb=rafb +URL_rafb="http://rafb.net/paste/ paste.php" +SIZE_rafb="800000 800_kB" +LINES_rafb=10000 +TOOFAST_rafb="http://rafb.net/p/toofast.html You must wait at least 10 seconds between each paste! Try again in 10 seconds." +TOOBIG_rafb="http://rafb.net/p/toobig.html The paste is too big. Try another service or paste smaller chunks of data." +EXPIRATION_INFO_rafb="Pastes on rafb: http://rafb.net/paste/ expire after 24 hours."$'\n' +# osl +ENGINE_osl=osl +URL_osl="http://pastebin.osuosl.org/ pastebin.php" +# sh +ENGINE_sh=sh +URL_sh="http://sh.nu/p/" + +### engines +# ca +LANGUAGES_ca="Plain_Text Asterisk_Configuration C C++ PHP Perl Java VB C# Ruby Python Pascal \ +mIRC PL/I XML SQL Scheme ActionScript Ada Apache_Configuration Assembly_(NASM) ASP Bash CSS \ +Delphi HTML_4.0_Strict JavaScript LISP Lua Microprocessor_ASM Objective_C VB.NET" +LANGUAGE_COUNT_ca=0 +EXPIRATIONS_ca="Never 5_minutes 10_minutes 15_minutes 30_minutes 45_minutes 1_hour 2_hours \ +4_hours 8_hours 12_hours 1_day 2_days 3_days 1_week 2_weeks 3_weeks 1_month 2_months \ +3_months 4_months 5_months 6_months 1_year" +POST_ca="s=Submit+Post name description type expiry _ content" +REGEX_URL_ca='s|^.*content="[0-9]\+;\(http://[^/]\+/[0-9]\+\)".*$|\1|p' +REGEX_RAW_ca='s|^\(http://[^/]\+/\)\([0-9]\+\)$|\1raw/\2|' +# rafb +LANGUAGES_rafb="C C89 C99 C++ C# Java Pascal Perl PHP PL/I Python Ruby SQL VB Plain_Text" +POST_rafb="_ nick desc lang _ cvt_tabs text" +REGEX_RAW_rafb='s|html\?$|txt|' +# osl +LANGUAGES_osl="Plain_Text ActionScript Ada Apache_Log_File AppleScript Assembly_(NASM) \ +ASP Bash C C_for_Macs CAD_DCL CAD_Lisp C++ C# ColdFusion CSS D Delphi Diff DOS Eiffel Fortran \ +FreeBasic Game_Maker HTML_4.0_Strict INI_file Java Javascript Lisp Lua MatLab Microprocessor_ASM \ +MySQL NullSoft_Installer Objective_C OCaml Openoffice.org_BASIC Oracle_8 Pascal Perl PHP Python \ +QBasic Robots.txt Ruby Scheme Smarty SQL TCL VB VB.NET VisualFoxPro XML" +LANGUAGE_VALUES_osl="text actionscript ada apache applescript asm asp bash c c_mac caddcl \ cadlisp cpp csharp cfm css d delphi diff dos eiffel fortran freebasic gml html4strict ini java \ javascript lisp lua matlab mpasm mysql nsis objc ocaml oobas oracle8 pascal perl php python \ -qbasic robots ruby scheme smarty sql tcl vb vbnet visualfoxpro xml) -# expirations -ca_EXPIRATIONS=(Never 5\ minutes 10\ minutes 15\ minutes 30\ minutes 45\ minutes 1\ hour 2\ hours \ -4\ hours 8\ hours 12\ hours 1\ day 2\ days 3\ days 1\ week 2\ weeks 3\ weeks 1\ month 2\ months \ -3\ months 4\ months 5\ months 6\ months 1\ year) -osl_EXPIRATIONS=(Never 1\ day 1\ month) -osl_EXPIRATION_VALUES=(f d m) -# warns - max_bytes human_readable max_lines known_failure known_failure_message known_failure2 known_failure2_message ... -ca_WARNS=(1024000 1\ MB) -rafb_WARNS=(800000 800\ kB 10000 http://rafb.net/p/toofast.html "You must wait at least 10 seconds between each paste! Try again in 10 seconds." http://rafb.net/p/toobig.html "The paste is too big. Try another service or paste smaller chunks of data.") -# POST data -engines_POST=(EXTRA NICK DESCRIPTION LANGUAGE EXPIRATION CVT_TABS) -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) -# 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|') +qbasic robots ruby scheme smarty sql tcl vb vbnet visualfoxpro xml" +EXPIRATIONS_osl="Never 1_day 1_month" +EXPIRATION_VALUES_osl="f d m" +POST_osl="paste=Send poster _ format expiry _ code2" +REGEX_RAW_osl='s|^\(http://[^/]\+/\)\([0-9]\+\)$|\1pastebin.php?dl=\2|' +# sh +POST_sh="_ poster _ _ _ _ code" ### defaults @@ -85,7 +106,7 @@ osl_REGEX=('s|^\(http://[^/]\+/\)\([0-9]\+\)$|\1pastebin.php?dl=\2|') # # Likewise if get_from_clipboard() is defined as a function in one of those files it will be # called to retrieve input from your clipboard when --xcut is used. -for f in {/etc/,~/.}wgetpaste{,/*.bash}; do +for f in {/etc/,~/.}wgetpaste{.d/*.bash,}; do [[ -f $f ]] && . "$f" done DEFAULT_NICK=${DEFAULT_NICK:-$(whoami)} @@ -99,22 +120,22 @@ DEFAULT_EXPIRATION=${DEFAULT_EXPIRATION:-1 month} usage() { cat <<EOF -Usage: ${0} [options] [file[s]] +Usage: $0 [options] [file[s]] Options: - -l, --language LANG set language (defaults to "${DEFAULT_LANGUAGE}") + -l, --language LANG set language (defaults to "$DEFAULT_LANGUAGE") -d, --description DESCRIPTION set description (defaults to "stdin" or filename) -n, --nick NICK set nick (defaults to your username)) - -s, --service SERVICE set service to use (defaults to "${DEFAULT_SERVICE}") - -e, --expiration EXPIRATION set when it should expire (defaults to "${DEFAULT_EXPIRATION}") + -s, --service SERVICE set service to use (defaults to "$DEFAULT_SERVICE") + -e, --expiration EXPIRATION set when it should expire (defaults to "$DEFAULT_EXPIRATION") -S, --list-services list supported pastebin services -L, --list-languages list languages supported by the specified service -E, --list-expiration list expiration setting supported by the specified service -c, --command COMMAND paste COMMAND and the output of COMMAND - -i, --info append the output of \`${INFO_COMMAND}\` - -I, --info-only paste the output of \`${INFO_COMMAND}\` only + -i, --info append the output of \`$INFO_COMMAND\` + -I, --info-only paste the output of \`$INFO_COMMAND\` only -x, --xcut read input from clipboard (requires configuration) -r, --raw show url for the raw paste (no syntax highlighting or html) @@ -125,77 +146,126 @@ Options: --version show version information Defaults (DEFAULT_{NICK,SERVICE,LANGUAGE,EXPIRATION}[_\${SERVICE}]) can be overridden -globally in /etc/wgetpaste{,/*.bash} or per user in ~/.wgetpaste{,/*.bash}. +globally in /etc/wgetpaste{.d/*.bash,} or per user in ~/.wgetpaste{.d/*.bash,}. EOF } ### show functions -show() { - echo "${1:0:1}${2:1}s supported by $(getrecipient) (case sensitive):" - local nr extra - 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]}\"" - done | ${3:-cat} -} - show_services() { echo "Services supported: (case sensitive):" - local max arg IND INDV engine url + local max s IND INDV engine url max=0 - for arg in "${SERVICES[@]}"; do - [[ ${#arg} -gt $max ]] && max=${#arg} + for s in $SERVICES; do + [[ ${#s} -gt $max ]] && max=${#s} done - ((IND=6+${max})) + ((IND=6+max)) if [[ $VERBOSE ]]; then max=0 - for s in "${SERVICES[@]}"; do - eval "arg=\"\${${s}[1]}\"" - [[ ${#arg} -gt $max ]] && max=${#arg} + for s in $SERVICES; do + s="URL_$s" + s=${!s% *} + [[ ${#s} -gt $max ]] && max=${#s} done - ((INDV=3+${max}+${IND})) + ((INDV=3+max+IND)) fi - for ((i=0; i<${#SERVICES[*]}; i++)); do - [[ $VERBOSE ]] && eval "engine=$'\e'\"[${INDV}G- \${${SERVICES[i]}[0]}\"" - eval "url=\"\${${SERVICES[i]}[1]}\"" - echo -e " ${SERVICES[i]} \e[${IND}G- ${url}${engine}" + for s in $SERVICES; do + [[ $VERBOSE ]] && engine="ENGINE_$s" && engine=$'\e'"[${INDV}G- ${!engine}" + url="URL_$s" + url=${!url% *} + echo " $s "$'\e'"[${IND}G- ${url}${engine}" + done | sort +} + +show_languages() { + echo "Languages supported by $(getrecipient) (case sensitive):" + local l lang + lang="LANGUAGES_$ENGINE" + [[ -z ${!lang} ]] && echo $'\n'"\"$ENGINE\" has no support for setting language" >&2 + for l in ${!lang}; do + echo " ${l//_/ }" done | sort } +show_expirations() { + echo "Expirations supported by $(getrecipient) (case sensitive):" + local e expiration info + expiration="EXPIRATIONS_$ENGINE" + info="EXPIRATION_INFO_$SERVICE" + [[ -z ${!expiration} ]] && echo $'\n'"${!info}\"$ENGINE\" has no support for setting expiration" >&2 + for e in ${!expiration}; do + echo " ${e//_/ }" + done +} + ### verify functions verify_service() { - for s in "${SERVICES[@]}"; do + for s in $SERVICES; do [[ $s == $* ]] && return 0 done - echo -e "\"$*\" is not a supported service.\n" >&2 + echo "\"$*\" is not a supported service."$'\n' >&2 show_services >&2 exit 1 } -verify() { - 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 - if [[ -n $(eval "echo \"\${${ENGINE}_${1}_COUNT}\"") ]]; then - ((i++)) - eval "${1}=\"${i}\"" - elif [[ -n $(eval "echo \"\${${ENGINE}_${1}_VALUES}\"") ]]; then - eval "${1}=\"\${${ENGINE}_${1}_VALUES[i]}\"" +verify_language() { + local i j l lang count v values + lang="LANGUAGES_$ENGINE" + count="LANGUAGE_COUNT_$ENGINE" + values="LANGUAGE_VALUES_$ENGINE" + if [[ -n ${!lang} ]]; then + ((i=0)) + for l in ${!lang}; do + if [[ $LANGUAGE == ${l//_/ } ]]; then + if [[ -n ${!count} ]]; then + ((LANGUAGE=i+1)) + elif [[ -n ${!values} ]]; then + ((j=0)) + for v in ${!values}; do + [[ i -eq j ]] && LANGUAGE=${v//_/ } && break + ((j++)) + done + fi + return 0 + fi + ((i++)) + done + else + [[ $LANGUAGE_SET = 0 ]] || return 0 + fi + echo "\"$LANGUAGE\" is not a supported language for $(getrecipient)."$'\n' >&2 + show_languages >&2 + exit 1 +} + +verify_expiration() { + local i j e expiration count v values + expiration="EXPIRATIONS_$ENGINE" + count="EXPIRATION_COUNT_$ENGINE" + values="EXPIRATION_VALUES_$ENGINE" + if [[ -n ${!expiration} ]]; then + ((i=0)) + for e in ${!expiration}; do + if [[ ${EXPIRATION} == ${e//_/ } ]]; then + if [[ -n ${!count} ]]; then + ((EXPIRATION=i+1)) + elif [[ -n {!values} ]]; then + ((j=0)) + for v in ${!values}; do + [[ i -eq j ]] && EXPIRATION=${e//_/ } && break + ((j++)) + done fi return 0 fi + ((i++)) done else - [[ $(eval "echo \"\${${1}_SET}\"") = 0 ]] || return 0 + [[ $EXPIRATION_SET = 0 ]] || return 0 fi - echo -e "\"$(eval "echo \"\${${1}}\"")\" is not a supported ${2} for $(getrecipient).\n" >&2 - show ${1}S "$2" >&2 + echo "\"$EXPIRATION\" is not a supported expiration option for $(getrecipient)."$'\n' >&2 + show_expirations >&2 exit 1 } @@ -203,76 +273,94 @@ verify() { # get the url to post to for any given service getrecipient() { - local target serv recip - if [[ RAW == $1 ]]; then - eval "target=\"\${${SERVICE}[2]}\"" - else - serv="${SERVICE}: " - fi - for s in "${SERVICES[@]}"; do - [[ $s == $SERVICE ]] && eval "recip=\"\${${s}[1]}\"" && echo "${serv}${recip}${target}" && return 0 + local urls target serv + for s in $SERVICES; do + if [[ $s == $SERVICE ]]; then + urls="URL_$SERVICE" + if [[ RAW == $1 ]]; then + [[ ${!urls} = ${!urls#* } ]] || target=${!urls#* } + else + serv="$SERVICE: " + fi + echo "${serv}${!urls% *}${target}" + return 0 + fi done - die "Failed to get url for \"${SERVICE}\"." + 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 does not abort. -warnsize() { +############################################################################### +warnings() { warn() { if [[ -n $2 && $1 -gt $2 ]]; then - echo "Pasting > ${3} often tend to fail with ${SERVICE}. Use --verbose or --debug to see the" + echo "Pasting > $3 often tend to fail with $SERVICE. Use --verbose or --debug to see the" echo "error output from wget if it fails. Alternatively use another pastebin service like e.g. sh." fi } - warn "$SIZE" "$(eval "echo \"\${${ENGINE}_WARNS[0]}\"")" "$(eval "echo \"\${${ENGINE}_WARNS[1]}\"")" - local LIMIT_LINES=$(eval "echo \"\${${ENGINE}_WARNS[2]}\"") - warn "$LINES" "$LIMIT_LINES" "${LIMIT_LINES} lines" + local size lines + size="SIZE_${SERVICE}" + lines="LINES_${SERVICE}" + warn "$SIZE" "${!size% *}" "${!size#* }" + warn "$LINES" "${!lines}" "${!lines} lines" } postdata() { - local extra field content - [[ 7 = $(eval "echo \"\${#${ENGINE}_POST[*]}\"") ]] || die "\"${SERVICE}\" is not supported by ${FUNCNAME}()." - eval "extra=\"\${${ENGINE}_POST[0]}\"" - [[ -n $extra ]] && echo -n "${extra}&" - for ((i=1; i<6; i++)); do - eval "field=\"\${${ENGINE}_POST[i]}\"" - [[ -z $field ]] && continue - eval "content=\"\${${engines_POST[i]}}\"" - echo -n "${field}=${content}&" - done - eval "field=\"\${${ENGINE}_POST[i]}\"" - echo "${field}=${INPUT}" + local post nr extra nick desc lang exp tabs text + post="POST_$ENGINE" + nr="${!post//[^ ]}" + [[ 6 = ${#nr} ]] || die "\"${SERVICE}\" is not supported by ${FUNCNAME}()." + extra="${!post%% *}" + [[ -n $extra ]] && echo -n "$extra&" + post="${!post#* }" + nick="${post%% *}" + [[ _ = $nick ]] || echo -n "$nick=$NICK&" + post="${post#* }" + desc="${post%% *}" + [[ _ = $desc ]] || echo -n "$desc=$DESCRIPTION&" + post="${post#* }" + lang="${post%% *}" + [[ _ = $lang ]] || echo -n "$lang=$LANGUAGE&" + post="${post#* }" + exp="${post%% *}" + [[ _ = $exp ]] || echo -n "$exp=$EXPIRATION&" + post="${post#* }" + tabs="${post%% *}" + [[ _ = $tabs ]] || echo -n "$tabs=$CVT_TABS&" + text="${post#* }" + echo "$text=$INPUT" } geturl() { local regex - eval "regex=\"\${${ENGINE}_REGEX[1]}\"" - if [[ -n $regex ]]; then - [[ needstdout == $1 ]] && return 0 - sed -n "$regex" <<< "$*" + regex="REGEX_URL_$ENGINE" + if [[ -n ${!regex} ]]; then + [[ needstdout = $1 ]] && return 0 + sed -n "${!regex}" <<< "$*" else - [[ needstdout == $1 ]] && return 1 + [[ needstdout = $1 ]] && return 1 sed -n 's|^.*Location:\ \(http://[^\ ]\+\).*$|\1|p' <<< "$*" fi } -# verify that the pastebin service did not return a known error url or print a helpful error message +# verify that the pastebin service did not return a known error url. otherwise print a helpful error message verifyurl() { - local urls i known - eval "urls=\"\${#${ENGINE}_WARNS[@]}\"" - (( urls=(${urls}-3)/2 )) - for((i=0;i<urls;i++)); do - eval "known=\"\${${ENGINE}_WARNS[3+2*i]}\"" - [[ -n $known && $known == $URL ]] && die "$(eval "echo \"\${${ENGINE}_WARNS[4+2*i]}\"")" + dieifknown() { + [[ -n ${!1%% *} && ${!1%% *} == $URL ]] && die "${!1#* }" + } + local t + for t in ${!TOO*}; do + [[ $t == TOO*_$SERVICE ]] && dieifknown "$t" done } # if possible convert URL to raw convert_to_raw() { - local convert - eval "convert=\"\${${ENGINE}_REGEX[0]}\"" - if [[ -n $convert ]]; then - RAWURL=$(sed -e "$convert" <<< "${URL}") + local regex + regex="REGEX_RAW_$ENGINE" + if [[ -n ${!regex} ]]; then + RAWURL=$(sed -e "$regex" <<< "$URL") return 0 fi echo "Raw download of pastes is not supported by $(getrecipient)." >&2 @@ -316,12 +404,12 @@ done set -- "${ARGS[@]}" noargument() { - die "${0}: option ${1} requires an argument" + die "$0: option $1 requires an argument" } getfilenames() { for f in "$@"; do - [[ -f $f ]] || die "${0}: ${f} No such file found." + [[ -f $f ]] || die "$0: $f No such file found." SOURCE="files" FILES[${#FILES[*]}]="$f" done @@ -398,17 +486,17 @@ while [[ -n $1 ]]; do shift ;; --version ) - echo "${0}, version ${VERSION}" && exit 0 + echo "$0, version $VERSION" && exit 0 ;; -x | --xcut ) SOURCE="xcut" shift ;; -* ) - die "${0}: unrecognized option \`${1}'" + die "$0: unrecognized option \`$1'" ;; *) - getfilenames "${1}" && shift + getfilenames "$1" && shift ;; esac done @@ -420,31 +508,32 @@ done # set default service, nick, source and tabs convertion SERVICE=${SERVICE:-${DEFAULT_SERVICE}} -eval "ENGINE=\"\${${SERVICE}[0]}\"" -[[ -n $(eval "echo \"\${DEFAULT_NICK_${SERVICE}}\"") ]] && NICK=${NICK:-$(eval "echo \"\${DEFAULT_NICK_${SERVICE}}\"")} +ENGINE=ENGINE_$SERVICE +ENGINE="${!ENGINE}" +default="DEFAULT_NICK_$SERVICE" && [[ -n ${!default} ]] && NICK=${NICK:-${!default}} NICK=${NICK:-$(escape "${DEFAULT_NICK}")} [[ -z $SOURCE ]] && SOURCE="stdin" && FILES[${#FILES[*]}]="/dev/stdin" CVT_TABS="No" # show languages if requested (needs to be done after the right service is selected) -[[ $LIST_LANGUAGES ]] && show LANGUAGES language sort && exit 0 +[[ $LIST_LANGUAGES ]] && show_languages && exit 0 # show expiration options if requested (needs to be done after the right service is selected) -[[ $LIST_EXPIRATION ]] && show EXPIRATIONS "expiration option" && exit 0 +[[ $LIST_EXPIRATION ]] && show_expirations && exit 0 # language needs to be verified before it is escaped but after service is selected -[[ -n $(eval "echo \"\${DEFAULT_LANGUAGE_${SERVICE}}\"") ]] && LANGUAGE=${LANGUAGE:-$(eval "echo \"\${DEFAULT_LANGUAGE_${SERVICE}}\"")} +default="DEFAULT_LANGUAGE_$SERVICE" && [[ -n ${!default} ]] && LANGUAGE=${LANGUAGE:-${!default}} LANGUAGE=${LANGUAGE:-${DEFAULT_LANGUAGE}} -# uses ${SERVICE} and ${LANGUAGE}. may change the value of the latter. -verify LANGUAGE language -LANGUAGE=$(escape "${LANGUAGE}") +# uses $SERVICE and $LANGUAGE. may change the value of the latter. +verify_language +LANGUAGE=$(escape "$LANGUAGE") # expiration needs to be verified before it is escaped but after service is selected -[[ -n $(eval "echo \"\${DEFAULT_EXPIRATION_${SERVICE}}\"") ]] && EXPIRATION=${EXPIRATION:-$(eval "echo \"\${DEFAULT_EXPIRATION_${SERVICE}}\"")} +default="DEFAULT_EXPIRATION_$SERVICE" && [[ -n ${!default} ]] && EXPIRATION=${EXPIRATION:-${!default}} EXPIRATION=${EXPIRATION:-${DEFAULT_EXPIRATION}} -# uses ${SERVICE} and ${EXPIRATION}. may change the value of the latter. -verify EXPIRATION "expiration option" -EXPIRATION=$(escape "${EXPIRATION}") +# uses $SERVICE and $EXPIRATION. may change the value of the latter. +verify_expiration +EXPIRATION=$(escape "$EXPIRATION") # set prompt if [[ 0 -eq $UID ]]; then @@ -457,12 +546,12 @@ fi if [[ -z $DESCRIPTION ]]; then case "$SOURCE" in info ) - DESCRIPTION="${PS1} ${INFO_COMMAND};" + DESCRIPTION="$PS1 $INFO_COMMAND;" ;; command ) DESCRIPTION="$PS1" for c in "${COMMANDS[@]}"; do - DESCRIPTION="${DESCRIPTION} ${c};" + DESCRIPTION="$DESCRIPTION $c;" done ;; files ) @@ -482,7 +571,7 @@ case "$SOURCE" in done ;; info ) - INPUT="${PS1} ${INFO_COMMAND}"$'\n'"$(${INFO_COMMAND} ${INFO_ARGS})" + INPUT="$PS1 $INFO_COMMAND"$'\n'"$($INFO_COMMAND $INFO_ARGS)" ;; xcut ) if [[ function == $(type -t get_from_clipboard) ]]; then @@ -500,7 +589,7 @@ Likewise if you want the resulting url stored in your clipboard using e.g. xclip define it like this: add_to_clipboard() { - xclip "\$*" + xclip <<< "\$*" } You may use whatever your window manager provides to alter your clipboard instead @@ -514,8 +603,8 @@ EOF if [[ ${#FILES[*]} -gt 1 ]]; then for f in "${FILES[@]}"; do [[ -r $f ]] || \ - die "The input source: \"${f}\" is not readable. Please specify a readable input source." - INPUT="${INPUT}${PS1} cat ${f}"$'\n'"$( < "$f" )"$'\n\n' + die "The input source: \"$f\" is not readable. Please specify a readable input source." + INPUT="${INPUT}${PS1} cat $f"$'\n'"$( < "$f" )"$'\n\n' done else INPUT=$( < "$FILES" ) @@ -524,10 +613,10 @@ EOF esac [[ -z $INPUT ]] && die "No input read. Nothing to paste. Aborting." -# append ${INFO_COMMAND} if needed +# append $INFO_COMMAND if needed if [[ $INFO ]]; then - DESCRIPTION="${DESCRIPTION} ${PS1} ${INFO_COMMAND};" - INPUT="${INPUT}"$'\n'"${PS1} ${INFO_COMMAND}"$'\n'"$(${INFO_COMMAND} ${INFO_ARGS})" + DESCRIPTION="$DESCRIPTION $PS1 $INFO_COMMAND;" + INPUT="$INPUT"$'\n'"$PS1 $INFO_COMMAND"$'\n'"$($INFO_COMMAND $INFO_ARGS)" fi # escape DESCRIPTION and INPUT @@ -537,14 +626,14 @@ INPUT=$(escape "$INPUT") # print a friendly warning if the size makes failure predictable for the specified pastebin service. SIZE=$(wc -c <<< "$INPUT") LINES=$(wc -l <<< "$INPUT") -warnsize >&2 +warnings >&2 # create temp file (wget is much more reliable reading large input from a file than from the cli directly TEMPFILE=$(mktemp /tmp/wgetpaste.XXXXXX) if [[ -f $TEMPFILE ]]; then # write paste data to the temporary file - postdata > "$TEMPFILE" || die "Failed to write to temporary file: \"${TEMPFILE}\"." - WGET_ARGS="--post-file=${TEMPFILE}" + postdata > "$TEMPFILE" || die "Failed to write to temporary file: \"$TEMPFILE\"." + WGET_ARGS="--post-file=$TEMPFILE" else # fall back to using --post-data if the temporary file could not be created # TABs and new lines need to be escaped for wget to interpret it as one string @@ -555,19 +644,19 @@ fi RECIPIENT=$(getrecipient RAW) # paste it -WGET_ARGS="--tries=5 --timeout=60 ${WGET_ARGS}" +WGET_ARGS="--tries=5 --timeout=60 $WGET_ARGS" if geturl needstdout || [[ $DEBUG || ! -w /dev/null ]]; then - OUTPUT=$(LC_ALL=C wget -O - ${WGET_ARGS} ${RECIPIENT} 2>&1) + OUTPUT=$(LC_ALL=C wget -O - $WGET_ARGS $RECIPIENT 2>&1) else - OUTPUT=$(LC_ALL=C wget -O /dev/null ${WGET_ARGS} ${RECIPIENT} 2>&1) + OUTPUT=$(LC_ALL=C wget -O /dev/null $WGET_ARGS $RECIPIENT 2>&1) fi # clean temporary file if it was created if [[ -f $TEMPFILE ]]; then if [[ $DEBUG ]]; then - echo "Left temporary file: \"${TEMPFILE}\" alone for debugging purposes." + echo "Left temporary file: \"$TEMPFILE\" alone for debugging purposes." else - rm "$TEMPFILE" || echo "Failed to remove temporary file: \"${TEMPFILE}\"." >&2 + rm "$TEMPFILE" || echo "Failed to remove temporary file: \"$TEMPFILE\"." >&2 fi fi @@ -575,7 +664,7 @@ fi URL=$(geturl "$OUTPUT") # verify that the pastebin service did not return a known error url such as toofast.html from rafb -# uses ${SERVICE} and ${URL}. +# uses $SERVICE and $URL. verifyurl # handle the case when there was no location returned |