You are not logged in.
Hey guys,
Over the past few days I've been using nopaste more and more -- it's a great tool for pastebinning, but I always thought the URLs were a bit long. For my own needs I wrote a very simple script that would take the output of nopaste, put it into a URL shortener, and pass out the old and new URLs. A few people expressed to me that they might be interested in this, so I have been polishing it a bit today, and have made it fit for release.
cush accepts input in a few ways:
It can take input from stdin (newline delimiter for URLs):
lspci | nopaste | cush
It can also take input as arguments (space delimiter for URLs):
cush www.one.com www.two.com www.three.com
Cush is available on the AUR:
I'd appreciate any feedback you might have!
Last edited by neurolysis (2011-05-04 20:17:49)
Offline
Offline
Interesting.
Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.
Offline
I've written such a tool for several url shortening services myself, including is.gd.
A little suggestion is that you should not assume URLs to be of http:// protocal. Actually, is.gd doesn't check for protocal at all. You can pass to it "http://google.com" "https://google.com" or "google.com", and it won't complain on any of them.
This silver ladybug at line 28...
Offline
You might be interested to know about '[[ -t', which will tell you if a given file descriptor is open on a tty, rather than checking for positional parameters -- your script won't just appear to hang without a prompt when a user doesn't supply any parameters, and you can print usage instead.
Example of checking for stdin being open...
checkstdin() {
if [[ -t 0 ]]; then
printf 'no data on stdin\n'
else
printf 'data found on stdin\n'
while read -r line; do printf '%s\n' "$line"; done
fi
}
checkstdin
printf 'foo\nbar\nbaz\n' | checkstdin
Offline
Thanks a lot for the feedback everyone! The following changes have been committed to git (and will be committed to AUR at the end of the day):
Features changed/added:
- Don't assume http protocol
- Better checking for presence of stdin
Bugs fixed:
- You can now specify arguments when taking input from stdin
There is one more bug I want to fix, but I'm trying to work out how best to approach it:
[[ "${_urls[@]: -1}" != "${_url}" ]] && sleep "${_sleeptime-1}"
That checks for the last argument, and doesn't sleep when it is detected to be the same as the one currently being shortened. I'm trying to work out how best to do the same for stdin.
I guess mapfile is the best option. Will try some things out.
Offline
Updated to 1.01, changes:
- No longer assumes HTTP
- Better stdin detection (thanks, falconindy)
- Addition of -- to specify everything following is not an operator
- Sleep detection now working for stdin content
Offline
1.02 removes curl as a dependency (not sure why I used it in the first place when wget works just fine and is in base).
Offline
1.03 shipped, only change is versioning errata.
Offline
1.04 shipped, now with j.mp support! Changelog:
- Add -j/--jmp switches to use j.mp instead of is.gd
- Some performance enhancements
- Now supports configs at /etc/cush.conf and $XDG_CONFIG_HOME/cush/cush.conf
There is a sample config at /usr/share/cush/config, which looks like this:
# Sample cush config file
# /usr/share/cush/config
#
# Global config: /etc/cush.conf
# User config: $XDG_CONFIG_HOME/cush/cush.conf
## Use j.mp shortening by default
#service=jmp
## j.mp username
#jmp_username=foo
## j.mp API key
#jmp_apikey=bar
service - The URL shortening service you want to use by default. Currently supported values are 'isgd' and 'jmp'.
jmp_username - Your username on j.mp
jmp_apikey - Your j.mp API key. Required to use j.mp URL shortening.
Offline
1.05 shipped, now removes perl as a dependency (uses printf for URL encoding).
Offline
You may want to check out the --data-urlencode option of curl.
This silver ladybug at line 28...
Offline
I'm aware of it -- I don't want to introduce curl as a dependency again.
Offline
1.06 shipped, changelog:
Features:
* Add URL expansion capability ( -e, --expand ), cush can expand URLs you give it with the same syntax you'd use to shorten them.
* Allows reading from the command line and STDIN at the same time
Other
* URL encoding efficiency changes (thanks, falconindy)
* Fixed a bug that would report the service available even if it wasn't
Last edited by neurolysis (2011-04-26 16:05:23)
Offline
1.07 shipped, changelog:
Features:
* RFC 3986 compliance
Offline