Last active
February 15, 2016 16:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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