From 541d8de23d796b289ff51f407b789d89461ea899 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Sun, 2 Sep 2018 11:23:53 +0100 Subject: [PATCH] Load Bash quicker by deferring completion loading until the end and backgrounding --- .bashrc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.bashrc b/.bashrc index 95c4dcc..d1cf43f 100755 --- a/.bashrc +++ b/.bashrc @@ -81,11 +81,13 @@ fi #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- -# Add bash completion scripts +# Add bash completion scripts (deferred until the end and backgrounded) #-------------------------------------------------------------------------------- -if [ -f $(brew --prefix 2>/dev/null)/etc/bash_completion ]; then - . $(brew --prefix 2>/dev/null)/etc/bash_completion -fi +function _deferred { + if [ -f $(brew --prefix 2>/dev/null)/etc/bash_completion ]; then + . $(brew --prefix 2>/dev/null)/etc/bash_completion + fi +} #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- @@ -165,3 +167,10 @@ fi #-------------------------------------------------------------------------------- [ -f ~/.bashrc_local ] && source ~/.bashrc_local #-------------------------------------------------------------------------------- + +#-------------------------------------------------------------------------------- +# Kick off the _deferred() function and background it (speeding up Bash loading) +#-------------------------------------------------------------------------------- +trap '_deferred 2>/dev/null; trap USR1' USR1 +{ sleep 0.1 ; builtin kill -USR1 $$ ; } & disown +#--------------------------------------------------------------------------------