Skip to content

Instantly share code, notes, and snippets.

@VarunAgw
Last active February 15, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VarunAgw/c8810062451151ceb696 to your computer and use it in GitHub Desktop.
Save VarunAgw/c8810062451151ceb696 to your computer and use it in GitHub Desktop.
A simple script to cache TLDR Node.JS client output to improve performance
Generally each command takes ~500ms, but with this, they will take ~10ms to execute. Add this into shell profile page
function tldr () {
mkdir -p /tmp/tldr_cache
if [ "--flush-cache" == $1 ]; then
rm /tmp/tldr_cache/*
return
fi
if [ "--" == "${1:0:2}" ]; then
command tldr $*
if [ "--help" = $1 ]; then
echo -e "To flush the custom caching\n"
echo -e " $ tldr --flush-cache"
fi
return
fi
if [ -f "/tmp/tldr_cache/$1" ]; then
cat /tmp/tldr_cache/$1
else
script -q -c "tldr $1" /tmp/tldr_cache/$1
sed '1d' /tmp/tldr_cache/$1 > /tmp/tldr_cache/$1.tmp;
mv /tmp/tldr_cache/$1.tmp /tmp/tldr_cache/$1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment