Add readwwwlog
This commit is contained in:
parent
fc206f88b0
commit
1c77fccff6
7
.config/zsh/completions/_readwwwlog
Normal file
7
.config/zsh/completions/_readwwwlog
Normal file
|
@ -0,0 +1,7 @@
|
|||
#compdef readwwwlog
|
||||
|
||||
_arguments '-h[short help text]' '*:url:_urls'
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# End:
|
33
.config/zsh/functions/readwwwlog
Executable file
33
.config/zsh/functions/readwwwlog
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env zsh
|
||||
# Open log files from paste services in a terminal. If the URL doesm't seem to
|
||||
# be plain text, open in ${default_cmd} instead
|
||||
|
||||
setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL
|
||||
|
||||
zmodload zsh/zutil
|
||||
local -a o_help=()
|
||||
zparseopts -D -K -- h=o_help
|
||||
if [[ ${#o_help} -ne 0 || ! -v 1 ]]; then
|
||||
ret=$(( ${#o_help} ^ 1 ))
|
||||
print -u $(( 1 + ${ret} )) "usage: ${0} [-h] <URL> …"
|
||||
return ${ret}
|
||||
fi
|
||||
local -a urls=(${@})
|
||||
|
||||
local default_cmd="firefox"
|
||||
|
||||
for url in ${urls}; do
|
||||
if [[ ${url} =~ 'dpaste\.com' && ! ${url[-4,-1]} == ".txt" ]]; then
|
||||
url+=".txt"
|
||||
fi
|
||||
|
||||
if curl --silent --location --head ${url} | grep -q 'text/plain'; then
|
||||
sleep 1 # dpaste.com workaround
|
||||
local file="$(mktemp)"
|
||||
curl --silent --location --output ${file} ${url}
|
||||
${TERMINAL} -e less ${file}
|
||||
rm ${file}
|
||||
else
|
||||
${default_cmd} ${url}
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user