diff --git a/.bashrc b/.bashrc index 01d593a..ea9cbb7 100644 --- a/.bashrc +++ b/.bashrc @@ -192,7 +192,7 @@ function paruuu () { } function skill () { - if [ -n "${1-}" ] ; then + while [ -n "${1:-}" ] ; do # shellcheck disable=SC2046,SC2009 2>/dev/null kill -9 \ -- $(ps auxww | grep -v grep | grep "${1-}" | awk '{print $2}') \ @@ -201,10 +201,7 @@ function skill () { 2>/dev/null sudo kill -9 \ -- $(ps auxww | grep "${1-}" | grep -v grep | awk '{print $2}') || { echo "Couldn't kill process"; return 3; } - else - echo 'Please provide one argument' - return 1; - fi + done } function wpa_restart () { diff --git a/.local/bin/pub b/.local/bin/pub index ac196db..5e409a5 100755 --- a/.local/bin/pub +++ b/.local/bin/pub @@ -1,36 +1,58 @@ #! /bin/sh - +######################## PREAMBLE ########################## err () { - printf '\033[31m%s\033[m\n' "$*" + printf '\033[31m%s\033[m\n' "$*" >&2 } -trap 'rm -f "$file"' EXIT +curl () { + output=$(timeout 5 curl -sfSL "$@") # strip trailing newline + err=$? # save exit status + printf '%s\n' "${output}" # add trailing newline + [ $err = 0 ] && exit 0 # exit early, we got what we wanted + while [ -n "$1" ] && [ "${1}" = "$(printf %s "$1" | tr -d .)" ] ; do shift; done # find domain + [ -z "$1" ] && domain="" || domain="$1" # didn't find domain? + [ $err = 124 ] && err "Timed out" # from timeout 5 + err "$domain pastebin failed!" # generic error + return $err # specifically for chris titus hastebin +} -[ ! -t 0 ] && [ -z "$1" ] && file=$(mktemp) && cat >"$file" || [ -n "$1" ] && file="$1" +trap 'rm -f "$file"' EXIT # clean up tmpfile -# mia's 0x0.st -- fast! -- prints \n -# curl -sfSL -F"file=@$file" 0x0.st && exit 0 ; err "Mia's (0x0.st) pastebin failed!" +file=$(mktemp --tmpdir pubtmpXXXXXXXXXXXXXXX) # must not contain dot . +if [ -z "$1" ]; then + cat >"$file" # `pub` or `