Skip to content

Commit

Permalink
feat(init): only run abbr commands in user file code...
Browse files Browse the repository at this point in the history
- Slurping instead of sourcing also cuts init time in half
- First update to the user abbreviations will lightly sanitize the user file
  • Loading branch information
olets committed Apr 7, 2020
1 parent 430d638 commit 93f2024
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions zsh-abbr.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ _zsh_abbr() {
return
fi

abbreviation="${(q)1%%=*}"
expansion="${(q)1#*=}"
abbreviation=${1%%=*}
expansion=${1#*=}
if ! (( ZSH_ABBR_INITIALIZING )); then
abbreviation=${(q)abbreviation}
expansion=${(q)expansion}
fi

if ! [[ $abbreviation && $expansion && $abbreviation != $1 ]]; then
_zsh_abbr:util_error " add: Requires abbreviation and expansion"
Expand Down Expand Up @@ -807,7 +811,6 @@ _zsh_abbr_init() {
{
(( ZSH_ABBR_DEBUG )) && echo "_zsh_abbr_init"

local line
local job
local shwordsplit_on

Expand Down Expand Up @@ -840,6 +843,9 @@ _zsh_abbr_init() {
function _zsh_abbr_init:seed() {
(( ZSH_ABBR_DEBUG )) && echo "_zsh_abbr_init:seed"

local arguments
local program

if [[ $options[shwordsplit] = on ]]; then
shwordsplit_on=1
fi
Expand All @@ -848,7 +854,15 @@ _zsh_abbr_init() {
if [ -f $ZSH_ABBR_USER_PATH ]; then
unsetopt shwordsplit

source $ZSH_ABBR_USER_PATH
while read -r line; do
program="${line%% *}"
arguments="${line#* }"

# Only execute abbr commands
if [[ $program == "abbr" && $program != $line ]]; then
abbr ${(z)arguments}
fi
done < $ZSH_ABBR_USER_PATH

if (( shwordsplit_on )); then
setopt shwordsplit
Expand Down

0 comments on commit 93f2024

Please sign in to comment.