From 1c2e9025cfaaf213f4a97774f3e626f9c84baf2d Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 22 Jan 2022 10:13:05 -0800 Subject: [PATCH] [zsh] Do a bunch of profiling and clean up all my init functions -- shell init is so much faster now! --- zsh/func/g | 6 ++-- zsh/func/init_env | 24 +++++-------- zsh/func/init_env_darwin | 45 +++++++++++------------ zsh/func/init_env_python | 48 +++++++++++-------------- zsh/func/init_rc_configure_completion | 52 ++++++++++++--------------- zsh/func/init_rc_configure_prompt | 44 ++++++++++------------- zsh/func/init_rc_darwin | 47 ++++++++++++------------ zsh/func/init_zsh_functions | 21 +++++------ zsh/func/prompt_loquacious_setup | 22 ++---------- zshenv | 3 +- zshrc | 8 +++-- 11 files changed, 135 insertions(+), 185 deletions(-) diff --git a/zsh/func/g b/zsh/func/g index 75cd46a..a4c1e86 100644 --- a/zsh/func/g +++ b/zsh/func/g @@ -1,8 +1,7 @@ #!/usr/bin/env zsh # Eryn Wells -function g -{ +function g { if [[ $# -gt 0 ]]; then git $@ else @@ -11,4 +10,7 @@ function g return $? } +# Use git completion for the g function +compdef g='git' + g "$@" diff --git a/zsh/func/init_env b/zsh/func/init_env index 3cadb17..564f49b 100644 --- a/zsh/func/init_env +++ b/zsh/func/init_env @@ -1,19 +1,13 @@ #!/usr/bin/env zsh -# vim:ft=zsh: # Eryn Wells -function init_env -{ - export PAGER="less" - export MANPAGER=$PAGER - export EDITOR="vim" - export VISUAL=$EDITOR - export LESSHISTFILE="-" - export GREP_OPTIONS="--color=auto" - export GREP_COLOR="1;32" +export PAGER="less" +export MANPAGER=$PAGER +export EDITOR="vim" +export VISUAL=$EDITOR +export LESSHISTFILE="-" +export GREP_OPTIONS="--color=auto" +export GREP_COLOR="1;32" - # Make sure gpg2 knows what to do with the curses-based smartcard PIN prompt. - export GPG_TTY=`tty` -} - -init_env "$@" +# Make sure gpg2 knows what to do with the curses-based smartcard PIN prompt. +export GPG_TTY=`tty` diff --git a/zsh/func/init_env_darwin b/zsh/func/init_env_darwin index 296aac6..4022238 100644 --- a/zsh/func/init_env_darwin +++ b/zsh/func/init_env_darwin @@ -5,32 +5,27 @@ autoload append_to_path autoload prepend_to_path -function init_env_darwin -{ - export OSBUILD=`sysctl -n kern.osversion` - export OSVERSION=`sysctl -n kern.osproductversion` - export HWMODEL=`sysctl -n hw.model` +export OSBUILD=`sysctl -n kern.osversion` +export OSVERSION=`sysctl -n kern.osproductversion` +export HWMODEL=`sysctl -n hw.model` - local pythonRoot - local python27SitePackages +local pythonRoot +local python27SitePackages - pythonRoot="$HOME/Library/Python" - if [[ -d "$pythonRoot" ]]; then - for f in `ls "$pythonRoot"`; do - prepend_to_path "$pythonRoot/$f/bin" - done +pythonRoot="$HOME/Library/Python" +if [[ -d "$pythonRoot" ]]; then + for f in `ls "$pythonRoot"`; do + prepend_to_path "$pythonRoot/$f/bin" + done +fi + +python27SitePackages="$pythonroot/2.7/lib/python/site-packages" +if [[ -d "$python27SitePackages" ]]; then + if [[ ! -z $PYTHONPATH ]]; then + PYTHONPATH=$python27SitePackages:$PYTHONPATH + else + PYTHONPATH=$python27SitePackages fi +fi - python27SitePackages="$pythonroot/2.7/lib/python/site-packages" - if [[ -d "$python27SitePackages" ]]; then - if [[ ! -z $PYTHONPATH ]]; then - PYTHONPATH=$python27SitePackages:$PYTHONPATH - else - PYTHONPATH=$python27SitePackages - fi - fi - - export PYTHONPATH -} - -init_env_darwin "$@" +export PYTHONPATH diff --git a/zsh/func/init_env_python b/zsh/func/init_env_python index f5d2625..620a696 100644 --- a/zsh/func/init_env_python +++ b/zsh/func/init_env_python @@ -1,34 +1,28 @@ #!/usr/bin/env zsh -# vim:ft=zsh: # Eryn Wells -function init_env_python -{ - local pythonRoot - local python27SitePackages +local pythonRoot +local python27SitePackages - pythonRoot="$HOME/Library/Python" - if [[ -d "$pythonRoot" ]]; then - for f in `ls "$pythonRoot"`; do - prepend_to_path "$pythonRoot/$f/bin" - done +pythonRoot="$HOME/Library/Python" +if [[ -d "$pythonRoot" ]]; then + for f in `ls "$pythonRoot"`; do + prepend_to_path "$pythonRoot/$f/bin" + done +fi + +python27SitePackages="$pythonroot/2.7/lib/python/site-packages" +if [[ -d "$python27SitePackages" ]]; then + if [[ ! -z $PYTHONPATH ]]; then + PYTHONPATH=$python27SitePackages:$PYTHONPATH + else + PYTHONPATH=$python27SitePackages fi +fi - python27SitePackages="$pythonroot/2.7/lib/python/site-packages" - if [[ -d "$python27SitePackages" ]]; then - if [[ ! -z $PYTHONPATH ]]; then - PYTHONPATH=$python27SitePackages:$PYTHONPATH - else - PYTHONPATH=$python27SitePackages - fi - fi +export PYTHONPATH - export PYTHONPATH - - if which virtualenvwrapper.sh 1>/dev/null 2>&1; then - export WORKON_HOME="$HOME/src/py/.envs" - source `which virtualenvwrapper.sh` - fi -} - -init_env_python "$@" +if which virtualenvwrapper.sh 1>/dev/null 2>&1; then + export WORKON_HOME="$HOME/src/py/.envs" + source `which virtualenvwrapper.sh` +fi diff --git a/zsh/func/init_rc_configure_completion b/zsh/func/init_rc_configure_completion index d967133..cd96926 100644 --- a/zsh/func/init_rc_configure_completion +++ b/zsh/func/init_rc_configure_completion @@ -1,41 +1,33 @@ #!/usr/bin/env zsh # Eryn Wells -function init_rc_configure_completion -{ - autoload -U compinit - compinit +autoload -U compinit +compinit - # Cache completions - zstyle ':completion::complete:*' use-cache 1 - zstyle ':completion::complete:*' cache-path ~/.zsh/cache +# Cache completions +zstyle ':completion::complete:*' use-cache 1 +zstyle ':completion::complete:*' cache-path ~/.zsh/cache - zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} - # For rm, cp, and mv don't complete if file is on the line already - zstyle ':completion:*:rm:*' ignore-line yes - zstyle ':completion:*:cp:*' ignore-line yes - zstyle ':completion:*:mv:*' ignore-line yes +# For rm, cp, and mv don't complete if file is on the line already +zstyle ':completion:*:rm:*' ignore-line yes +zstyle ':completion:*:cp:*' ignore-line yes +zstyle ':completion:*:mv:*' ignore-line yes - # Remove trailing slashes in directory arguments - zstyle ':completion:*' squeeze-slashes true +# Remove trailing slashes in directory arguments +zstyle ':completion:*' squeeze-slashes true - # Never select parent directory - zstyle ':completion:*:cd:*' ignore-parents parent pwd +# Never select parent directory +zstyle ':completion:*:cd:*' ignore-parents parent pwd - # Expand partial paths - zstyle ':completion:*' expand 'yes' +# Expand partial paths +zstyle ':completion:*' expand 'yes' - # Show a pretty menu of killable processes - zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' - zstyle ':completion:*:*:kill:*' menu yes select +# Show a pretty menu of killable processes +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' +zstyle ':completion:*:*:kill:*' menu yes select - # Complete man pages by section - zstyle ':completion:*:manuals' separate-sections true - zstyle ':completion:*:manuals.*' insert-sections true - - # Use git completion for the g function - compdef g='git' -} - -init_rc_configure_completion "$@" +# Complete man pages by section +zstyle ':completion:*:manuals' separate-sections true +zstyle ':completion:*:manuals.*' insert-sections true diff --git a/zsh/func/init_rc_configure_prompt b/zsh/func/init_rc_configure_prompt index b96eb41..fb37858 100644 --- a/zsh/func/init_rc_configure_prompt +++ b/zsh/func/init_rc_configure_prompt @@ -1,34 +1,26 @@ #!/usr/bin/env zsh # Eryn Wells -function init_rc_configure_prompt -{ - local theme=$1 - if [[ -z "$1" ]]; then - theme=loquacious - fi +local theme=$1 +if [[ -z "$1" ]]; then + theme=loquacious +fi - autoload -U add-zsh-hook - autoload -Uz vcs_info +autoload -U add-zsh-hook +autoload -Uz vcs_info - zstyle ':vcs_info:*' disable p4 bzr cdv darcs mtn svk tla cvs svn - zstyle ':vcs_info:*' enable git - zstyle ':vcs_info:git:general:*' formats '%b' +zstyle ':vcs_info:*' disable p4 bzr cdv darcs mtn svk tla cvs svn +zstyle ':vcs_info:*' enable git +zstyle ':vcs_info:git:general:*' formats '%b' - # Export the current Git branch before every prompt. - function export_gitbranch { - vcs_info general - if [[ "$gitbranches[1]" != "${vcs_info_msg_0_}" ]]; then - export gitbranches=(${vcs_info_msg_0_} $gitbranches[1,4]) - fi - export gitbranch=${vcs_info_msg_0_} - } - - add-zsh-hook precmd export_gitbranch - - autoload -U promptinit - promptinit - prompt $theme +# Export the current Git branch before every prompt. +function export_gitbranch { + vcs_info general + export gitbranch=${vcs_info_msg_0_} } -init_rc_configure_prompt "$@" +add-zsh-hook precmd export_gitbranch + +autoload -U promptinit +promptinit +prompt $theme diff --git a/zsh/func/init_rc_darwin b/zsh/func/init_rc_darwin index 06a7177..173e43f 100644 --- a/zsh/func/init_rc_darwin +++ b/zsh/func/init_rc_darwin @@ -1,36 +1,37 @@ #!/usr/bin/env zsh # Eryn Wells -autoload binary_exists +autoload -Uz binary_exists -function init_rc_darwin -{ - alias acls='command ls -le' +alias acls='command ls -le' - # These things might have been installed by Homebrew, and I like the GNU - # versions better. - binary_exists gdircolors && alias dircolors='gdircolors' - binary_exists gfind && alias find='gfind' - binary_exists gnuindent && alias indent='gnuindent' +# These things might have been installed by Homebrew, and I like the GNU +# versions better. +binary_exists gdircolors && alias dircolors='gdircolors' +binary_exists gfind && alias find='gfind' +binary_exists gnuindent && alias indent='gnuindent' - binary_exists gls && init_rc_configure_ls `which gls` +binary_exists gls && init_rc_configure_ls `which gls` - # ldd doesn't exist on OS X, but otool -L does the same thing. - alias ldd='otool -L' +# ldd doesn't exist on OS X, but otool -L does the same thing. +alias ldd='otool -L' - local sounds=/System/Library/Sounds - alias glass="afplay $sounds/Glass.aiff" - alias funk="afplay $sounds/Funk.aiff" +local sounds=/System/Library/Sounds +alias glass="afplay $sounds/Glass.aiff" +alias funk="afplay $sounds/Funk.aiff" - autoload +X darwin_init_once - autoload +X darwin_icloud_drive_path - autoload +X darwin_configure_screenshots_directory +autoload -Uz darwin_init_once +autoload -Uz darwin_icloud_drive_path +autoload -Uz darwin_configure_screenshots_directory - # Open a file/folder in Finder - alias reveal='open -R' +# Open a file or folder in Finder. +function finder { + if [[ -z "$1" ]]; then + open -R . + fi - alias -s app='open' - alias -s xcodeproj='open -a Xcode' + open -R "$1" } -init_rc_darwin "$@" +alias -s app='open' +alias -s xcodeproj='open -a Xcode' diff --git a/zsh/func/init_zsh_functions b/zsh/func/init_zsh_functions index 76f9c9c..5f53b8b 100644 --- a/zsh/func/init_zsh_functions +++ b/zsh/func/init_zsh_functions @@ -3,19 +3,14 @@ autoload load_module -function init_zsh_functions -{ - local myfpath="$HOME/.zsh/func" +local myfpath="$HOME/.zsh/func" - for func in $myfpath/*; do - [[ ! -e "$func" || -d "$func" ]] && continue +for func in $myfpath/*; do + [[ ! -e "$func" || -d "$func" ]] && continue - local functionName=`basename $func` - [[ "$functionName" =~ "prompt_*" ]] && continue - [[ "$functionName" =~ "init_*" ]] && continue + local functionName=`basename $func` + [[ "$functionName" =~ "prompt_*" ]] && continue + [[ "$functionName" =~ "init_*" ]] && continue - autoload +X $functionName - done -} - -init_zsh_functions "$@" + autoload -Uz $functionName +done diff --git a/zsh/func/prompt_loquacious_setup b/zsh/func/prompt_loquacious_setup index b6d9620..9a0f567 100644 --- a/zsh/func/prompt_loquacious_setup +++ b/zsh/func/prompt_loquacious_setup @@ -1,11 +1,6 @@ -#!/usr/bin/zsh -# vim:sw=4:sts=4: -# -# A wordy prompt theme. -# +#!/usr/bin/env zsh # Eryn Wells - function prompt_loquacious_help { cat <&1 1>/dev/null; then init_configure_ls `which ls` fi -autoload g -autoload vi +autoload -Uz g +autoload -Uz nethack +autoload -Uz pw +autoload -Uz up +autoload -Uz vi