Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 76 lines (55 sloc) 2.22 KB
#! /bin/bash
set -eu
echo "Generating vim startup profile..."
logfile="vim.log"
if [ -f $logfile ]; then
# clear the log file first
rm $logfile
fi
vim --startuptime $logfile -c q
echo 'Assuming your vimfiles folder as `~/.config/nvim/`'
vimfilesDir="$HOME/.config/nvim/"
plugDir=""
if [ -d "${vimfilesDir}plugged" ]; then
echo "vim-plug has been detected."
plugDir="plugged"
elif [ -d "${vimfilesDir}bundle" ]; then
echo "NeoBundle/Vundle/Pathogen has been detected."
plugDir="bundle"
else
echo "Cannot tell your plugin-manager. Adjust this bash script\n"
echo "to meet your own needs for now."
echo 'Cue: `plugDir` variable would be a good starting place.'
exit 1
fi
echo "Parsing vim startup profile..."
#logfile=hi.log
grep $plugDir $logfile > tmp.log
awk -F\: '{print $1}' tmp.log > tmp1.log
# awk -F\: '{print $2}' tmp.log | awk -F\: '{print $2}' tmp.log | sed "s/.*${plugDir}\///g"|sed 's/\/.*//g' > tmp2.log
awk -F\: '{print $2}' tmp.log | awk -F\: '{print $2}' tmp.log | perl -pe 's|.*?bundle/(.*?)/.*|\1|' | perl -pe 's|.*/(.*)|\1|' > tmp2.log
paste -d ',' tmp1.log tmp2.log | tr -s ' ' ',' > profile.csv
# rm tmp.log tmp1.log tmp2.log
# Let's do the R magic!
echo "Crunching data and generating profile plot ..."
# Check if R is available
echo " "
type R > /dev/null 2>&1 || { echo -e >&2 "Package R is required but it's not installed. \nPlease install R using your package manager, \nor check out cran.r-project.org for instructions. \nAborting."; exit 1; }
# Still here? Great! Let's move on!
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
R --vanilla --quiet --slave --file="$DIR/vim-plugins-profile-plot.R"
#R --vanilla --file="vim-plugins-profile-plot.R" # or use this for debugging
# we use result.csv, which is saved from R
# delete profile.csv since it is used to feed into R
rm profile.csv
echo " "
echo 'Your plugins startup profile graph is saved '
echo 'as `result.png` under current directory.'
echo " "
echo "=========================================="
echo "Top 10 Plugins That Slows Down Vim Startup"
echo "=========================================="
cat -n result.csv |head -n 10 # change this 10 to see more in this `Top List`
echo "=========================================="
echo "Done!"
echo " "