[zsh] Do a bunch of profiling and clean up all my init functions -- shell init is so much faster now!

This commit is contained in:
Eryn Wells 2022-01-22 10:13:05 -08:00
parent 7e126fe703
commit 1c2e9025cf
11 changed files with 135 additions and 185 deletions

View file

@ -1,8 +1,7 @@
#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>
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 "$@"

View file

@ -1,9 +1,6 @@
#!/usr/bin/env zsh
# vim:ft=zsh:
# Eryn Wells <eryn@erynwells.me>
function init_env
{
export PAGER="less"
export MANPAGER=$PAGER
export EDITOR="vim"
@ -14,6 +11,3 @@ function init_env
# Make sure gpg2 knows what to do with the curses-based smartcard PIN prompt.
export GPG_TTY=`tty`
}
init_env "$@"

View file

@ -5,8 +5,6 @@
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`
@ -31,6 +29,3 @@ function init_env_darwin
fi
export PYTHONPATH
}
init_env_darwin "$@"

View file

@ -1,9 +1,6 @@
#!/usr/bin/env zsh
# vim:ft=zsh:
# Eryn Wells <eryn@erynwells.me>
function init_env_python
{
local pythonRoot
local python27SitePackages
@ -29,6 +26,3 @@ function init_env_python
export WORKON_HOME="$HOME/src/py/.envs"
source `which virtualenvwrapper.sh`
fi
}
init_env_python "$@"

View file

@ -1,8 +1,6 @@
#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>
function init_rc_configure_completion
{
autoload -U compinit
compinit
@ -33,9 +31,3 @@ function init_rc_configure_completion
# 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 "$@"

View file

@ -1,8 +1,6 @@
#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>
function init_rc_configure_prompt
{
local theme=$1
if [[ -z "$1" ]]; then
theme=loquacious
@ -18,9 +16,6 @@ function init_rc_configure_prompt
# 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_}
}
@ -29,6 +24,3 @@ function init_rc_configure_prompt
autoload -U promptinit
promptinit
prompt $theme
}
init_rc_configure_prompt "$@"

View file

@ -1,10 +1,8 @@
#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>
autoload binary_exists
autoload -Uz binary_exists
function init_rc_darwin
{
alias acls='command ls -le'
# These things might have been installed by Homebrew, and I like the GNU
@ -22,15 +20,18 @@ function init_rc_darwin
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
open -R "$1"
}
alias -s app='open'
alias -s xcodeproj='open -a Xcode'
}
init_rc_darwin "$@"

View file

@ -3,8 +3,6 @@
autoload load_module
function init_zsh_functions
{
local myfpath="$HOME/.zsh/func"
for func in $myfpath/*; do
@ -14,8 +12,5 @@ function init_zsh_functions
[[ "$functionName" =~ "prompt_*" ]] && continue
[[ "$functionName" =~ "init_*" ]] && continue
autoload +X $functionName
autoload -Uz $functionName
done
}
init_zsh_functions "$@"

View file

@ -1,11 +1,6 @@
#!/usr/bin/zsh
# vim:sw=4:sts=4:
#
# A wordy prompt theme.
#
#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>
function prompt_loquacious_help
{
cat <<EOF
@ -21,7 +16,6 @@ current directory is in a repo.
EOF
}
function prompt_loquacious_setup
{
typeset -ga precmd_functions
@ -41,10 +35,8 @@ function prompt_loquacious_setup
prompt_opts=(cr subst percent)
# Set up vcs_info
zstyle ':vcs_info:git:loquacious_chpwd:*' formats \
'%F{cyan}%r%f'
zstyle ':vcs_info:git:loquacious_precmd:*' formats \
'(%F{blue}%b%f)'
zstyle ':vcs_info:git:loquacious_chpwd:*' formats '%F{cyan}%r%f'
zstyle ':vcs_info:git:loquacious_precmd:*' formats '(%F{blue}%b%f)'
PS1='${PS1_NAME}${PS1_HOST}${PS1_CWD}${PS1_REPO}${PS1_BRANCH}${PS1_STATUS}${PS1_ZLE_MODE}
$PS1_LINE'
@ -52,13 +44,11 @@ $PS1_LINE'
zle -N zle-keymap-select on_keymap_select
}
function prompt_loquacious_preview
{
# TODO: Implement prompt preview.
}
#
# HELPER FUNCTIONS
#
@ -76,7 +66,6 @@ function print_newline
echo
}
function set_repo_name
{
vcs_info loquacious_chpwd
@ -87,7 +76,6 @@ function set_repo_name
fi
}
function set_prompt_info
{
PS1_HISTORY="`prompt_colorize -b -f 'green' '%h'`"
@ -121,7 +109,6 @@ function set_prompt_info
PS1_LINE='%# '
}
function set_xterm_title
{
local title=''
@ -141,7 +128,6 @@ function set_xterm_title
fi
}
function set_zle_mode_info
{
if [[ -z "$1" || "$1" == 'viins' || "$1" == 'main' ]]; then
@ -153,7 +139,6 @@ function set_zle_mode_info
fi
}
function on_keymap_select
{
# Regenerate the prompt with the new mode
@ -163,6 +148,5 @@ function on_keymap_select
zle reset-prompt
}
# Finally, run setup to get everything going
prompt_loquacious_setup "$@"

3
zshenv
View file

@ -18,7 +18,6 @@ init_path
init_env
init_env_python
autoload +X init_env_$SYS
if [[ $? ]]; then
if autoload +X init_env_$SYS; then
init_env_$SYS
fi

8
zshrc
View file

@ -17,7 +17,6 @@ init_rc_configure_zle emacs
init_rc_configure_completion
init_zsh_options
init_zsh_history
init_zsh_functions
init_app_environments
autoload +X init_rc_$SYS
@ -28,5 +27,8 @@ if ! alias ls 2>&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