mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
Cosmetic changes and comments for sprunge.
This commit is contained in:
parent
c83ecd5d1a
commit
5905845abd
1 changed files with 11 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ HERE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (( $+commands[python] )); then
|
if (( $+commands[python] )); then
|
||||||
|
# use python to attempt to detect the syntax
|
||||||
sprunge_syntax() {
|
sprunge_syntax() {
|
||||||
echo "try:
|
echo "try:
|
||||||
from pygments.lexers import get_lexer_for_filename
|
from pygments.lexers import get_lexer_for_filename
|
||||||
|
|
@ -24,6 +25,7 @@ except:
|
||||||
print('text')" | python
|
print('text')" | python
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
# if we happen to lack python, just report everything as text
|
||||||
sprunge_syntax() { echo 'text' }
|
sprunge_syntax() { echo 'text' }
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -32,14 +34,16 @@ sprunge() {
|
||||||
|
|
||||||
urls=()
|
urls=()
|
||||||
|
|
||||||
if [[ ! -t 0 || $#argv -eq 0 ]]; then
|
if [[ $1 == '-h' || $1 == '--help' ]]; then
|
||||||
url=$(curl -s -F 'sprunge=<-' http://sprunge.us <& 0)
|
# print usage information
|
||||||
urls=(${url//[[:space:]]})
|
|
||||||
elif [[ $1 == '-h' || $1 == '--help' ]]; then
|
|
||||||
sprunge_usage
|
sprunge_usage
|
||||||
return 0
|
return 0
|
||||||
|
elif [[ ! -t 0 || $#argv -eq 0 ]]; then
|
||||||
|
# read from stdin
|
||||||
|
url=$(curl -s -F 'sprunge=<-' http://sprunge.us <& 0)
|
||||||
|
urls=(${url//[[:space:]]})
|
||||||
else
|
else
|
||||||
# Use python to attempt to detect the syntax
|
# treat arguments as a list of files to upload
|
||||||
for file in $@; do
|
for file in $@; do
|
||||||
if [[ ! -f $file ]]; then
|
if [[ ! -f $file ]]; then
|
||||||
echo "$file isn't a file" >&2
|
echo "$file isn't a file" >&2
|
||||||
|
|
@ -55,14 +59,14 @@ sprunge() {
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# output
|
# output each url on its own line
|
||||||
for url in $urls
|
for url in $urls
|
||||||
echo $url
|
echo $url
|
||||||
|
|
||||||
# don't copy to clipboad if piped
|
# don't copy to clipboad if piped
|
||||||
[[ ! -t 1 ]] && return 0
|
[[ ! -t 1 ]] && return 0
|
||||||
|
|
||||||
# copy urls to primary and clipboard (middle-mouse & shift+ins/Ctrl+v)
|
# copy urls to primary and secondary clipboards
|
||||||
if (( $+commands[xclip] )); then
|
if (( $+commands[xclip] )); then
|
||||||
echo -n $urls | xclip -sel primary
|
echo -n $urls | xclip -sel primary
|
||||||
echo -n $urls | xclip -sel clipboard
|
echo -n $urls | xclip -sel clipboard
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue