1
0
Fork 0
mirror of https://github.com/sbrl/bin.git synced 2018-01-10 21:33:46 +00:00

Add quote-get

This commit is contained in:
Starbeamrainbowlabs 2017-09-23 11:18:05 +01:00
parent 4e0ff4f617
commit 7e627fb53a
2 changed files with 52 additions and 1 deletions

View file

@ -45,7 +45,7 @@ Here's a list of the most interesting ones, along with what they do and where th
- recvdir - The counterpart to the above that receives the directory sent.
- brightness.sh - Another small script I've written that controls the brightness of my screen. It works for me, but it may not work for you.
- ptr - A small script I wrote that uses `dig` to do PTR (reverse DNS) lookups, since I have to keep looking the command up every time :P
- *clip
- * clip
- setclip - Sets the clipboard to the contents of the standard input
- getclip - Sends the current clipboard contents out of the standard output
- listenclip - Listens on localhost:5556 and pipes any data recieved into the clipboard. Make sure you're firewall is working correctly!
@ -55,6 +55,7 @@ Here's a list of the most interesting ones, along with what they do and where th
- [colortrans](https://gist.github.com/MicahElliott/719710) - Convert rgb colours to xterm ones
- nautilus-here - A quick command that opens nautilus in the current directory. For lazy people :P
- ssh-retry - I forget where it came from, but this command reepeatedly calls ssh until it succeeds in connecting.
- quote-get - Displays a random quote from a remote file. The quote stays the same until the following day. The remote file is cached locally for convenience :smiley_cat:
## cloudsurfer.sh
`cloudsurfer.sh` is a new script I'm writing to bring some of the customisations I store here in this repository to terminals on shared machines - where I can't modify `.bashrc`, for example.

50
quote-get Executable file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env bash
quotes_cache_file="${HOME}/.cache/quotes.txt";
update_cache_every="1 day";
if [[ "$#" -lt "1" ]]; then
echo -e "Quote generation tool"
echo -e "By Starbeamrainbowlabs"
echo -e ""
echo -e "Downloads and caches a quote file and picks out a random (per day) quote."
echo -e ""
echo -e "Usage:"
echo -e " quote-get {quote-file-url}"
exit 1;
fi
quotes_url="$1";
if [ ! -d "$(dirname "${quotes_cache_file}")" ]; then
mkdir -p "${quotes_cache_file}";
fi
function download_quotes {
#echo -ne "> Downloading quotes file - " 1>&2;
curl -o "${quotes_cache_file}" -L ${quotes_url} 2>/dev/null;
#echo -e "done" 1>&2;
}
# Download the quotes file if it doesn't exist already
if [ ! -f "${quotes_cache_file}" ]; then
download_quotes;
fi
# Update the quotes file if it's out of date
oldest_allowed=$(date -d "now - ${update_cache_every}" +%s);
cache_filemtime=$(date -r "${quotes_cache_file}" +%s);
if (( $cache_filemtime <= $oldest_allowed )); then
download_quotes;
fi
# Generate a quote
quote_count=$(cat "${quotes_cache_file}" | wc -l);
# Set the random number generator seed to ensure we give the same quote on a per-day basis
RANDOM=$(date +%Y-%m-%d);
quote_line=$((( $RANDOM % ${quote_count} )));
sed -n ${quote_line}p "${quotes_cache_file}";