mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
copy sprunge $url to clipboard automatically if user has xclip or xsel
installed
This commit is contained in:
parent
bfe6d22bda
commit
404ffffc0e
1 changed files with 22 additions and 4 deletions
|
|
@ -32,7 +32,7 @@ sprunge () {
|
||||||
print(get_lexer_for_filename('$*').aliases[0])
|
print(get_lexer_for_filename('$*').aliases[0])
|
||||||
except:
|
except:
|
||||||
print('text')" | python)
|
print('text')" | python)
|
||||||
url=$(curl -F 'sprunge=<-' http://sprunge.us < "$*")
|
url=$(curl -s -F 'sprunge=<-' http://sprunge.us < "$*")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
cat << HERE
|
cat << HERE
|
||||||
|
|
@ -40,6 +40,11 @@ except:
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
Upload data and fetch URL from the pastebin http://sprunge.us
|
Upload data and fetch URL from the pastebin http://sprunge.us
|
||||||
|
|
||||||
|
In addition to printing the returned URL, if the xset or xsel
|
||||||
|
programs are available (on $PATH), the URL will also be copied to the
|
||||||
|
PRIMARY selection and the CLIPBOARD selection (allowing to quickly
|
||||||
|
paste the url into IRC client for example).
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
$0 filename.txt
|
$0 filename.txt
|
||||||
$0 < filename.txt
|
$0 < filename.txt
|
||||||
|
|
@ -80,12 +85,25 @@ HERE
|
||||||
syntax="text" # We're dumb in this mode. So, dumb syntax highlighting!
|
syntax="text" # We're dumb in this mode. So, dumb syntax highlighting!
|
||||||
url=$(while read -r line ; do
|
url=$(while read -r line ; do
|
||||||
echo $line
|
echo $line
|
||||||
done | curl -F 'sprunge=<-' http://sprunge.us)
|
done | curl -s -F 'sprunge=<-' http://sprunge.us)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$syntax" != "text" ]]; then
|
if [[ "$syntax" != "text" ]]; then
|
||||||
echo "$url?$syntax"
|
# if stdout is not a tty, suppress trailing newline
|
||||||
|
if [[ ! -t 1 ]] ; then local flags='-n' ; fi
|
||||||
|
echo $flags "$url?$syntax"
|
||||||
else
|
else
|
||||||
echo $url
|
# if stdout is not a tty, suppress trailing newline
|
||||||
|
if [[ ! -t 1 ]] ; then local flags='-n' ; fi
|
||||||
|
echo $flags $url
|
||||||
|
fi
|
||||||
|
|
||||||
|
#copy url to primary and clipboard (middle-mouse & shift+ins/Ctrl+v)
|
||||||
|
if (( $+commands[xclip] )); then
|
||||||
|
echo -n "$url?$syntax" | xclip -sel primary
|
||||||
|
echo -n "$url?$syntax" | xclip -sel clipboard
|
||||||
|
elif (( $+commands[xsel] )); then
|
||||||
|
echo -n "$url?$syntax" | xsel -ip #primary
|
||||||
|
echo -n "$url?$syntax" | xsel -ib #clipboard
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue