Untested changes! Woo!

This commit is contained in:
Jack L. Frost 2014-10-04 12:45:31 +04:00
parent b27907f12a
commit 80ae0480b3

21
sup
View File

@ -58,9 +58,7 @@ sup.scrot() {
[[ "$flag_scrot_fullscreen" ]] || { scrot_args+=( '-s' ); } [[ "$flag_scrot_fullscreen" ]] || { scrot_args+=( '-s' ); }
[[ "$cfg_scrot_delay" ]] && { scrot_args+=( "-d $cfg_scrot_delay" ); } [[ "$cfg_scrot_delay" ]] && { scrot_args+=( "-d $cfg_scrot_delay" ); }
until [[ ! -e "${cfg_tmp_dir}/${tmp_file_name}" ]]; do tmp_file_name="$(sup.mktemp "${cfg_tmp_dir}" "${cfg_screenshot_ext}")"
tmp_file_name="${RANDOM}${RANDOM}.${cfg_screenshot_ext}"
done
scrot "${scrot_args[@]}" "${cfg_tmp_dir}/$tmp_file_name" || { scrot "${scrot_args[@]}" "${cfg_tmp_dir}/$tmp_file_name" || {
sup.err "Failed to take a screenshot." sup.err "Failed to take a screenshot."
@ -77,6 +75,21 @@ sup.exclude() {
sup.if_url() { echo "$1" | grep -oE "$cfg_url_regex" &>/dev/null; } sup.if_url() { echo "$1" | grep -oE "$cfg_url_regex" &>/dev/null; }
sup.mktemp() {
local tmp_file_name tmp_file_name_extra="$2" tmp_dir="$1"
[[ -d "$tmp_dir" ]] || {
sup.err "${tmp_dir} does not exist or is not a directory."
return 1
}
until [[ ! -e "${tmp_dir}/${tmp_file_name}" ]]; do
tmp_file_name="${RANDOM}${RANDOM}${tmp_file_name_extra}"
done
echo "${tmp_dir}/${tmp_file_name}"
}
main() { main() {
while [[ "$1" ]]; do while [[ "$1" ]]; do
case "$1" in case "$1" in
@ -104,7 +117,7 @@ main() {
target="${args[0]}"; [[ "$target" ]] || { sup.usage; exit 1; } target="${args[0]}"; [[ "$target" ]] || { sup.usage; exit 1; }
sup.if_url "$target" && { sup.if_url "$target" && {
file=`mktemp "$cfg_tmp_dir/sup_tmp_XXXXXX"` file=`sup.mktemp "$cfg_tmp_dir"`
curl -s "$target" > "$file" || { curl -s "$target" > "$file" || {
sup.err "Could not download file." sup.err "Could not download file."