[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:
		
							parent
							
								
									7e126fe703
								
							
						
					
					
						commit
						1c2e9025cf
					
				
					 11 changed files with 135 additions and 185 deletions
				
			
		|  | @ -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 "$@" | ||||
|  |  | |||
|  | @ -1,19 +1,13 @@ | |||
| #!/usr/bin/env zsh | ||||
| # vim:ft=zsh: | ||||
| # Eryn Wells <eryn@erynwells.me> | ||||
| 
 | ||||
| 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` | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -1,34 +1,28 @@ | |||
| #!/usr/bin/env zsh | ||||
| # vim:ft=zsh: | ||||
| # Eryn Wells <eryn@erynwells.me> | ||||
| 
 | ||||
| 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 | ||||
|  |  | |||
|  | @ -1,41 +1,33 @@ | |||
| #!/usr/bin/env zsh | ||||
| # Eryn Wells <eryn@erynwells.me> | ||||
| 
 | ||||
| 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 | ||||
|  |  | |||
|  | @ -1,34 +1,26 @@ | |||
| #!/usr/bin/env zsh | ||||
| # Eryn Wells <eryn@erynwells.me> | ||||
| 
 | ||||
| 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 | ||||
|  |  | |||
|  | @ -1,36 +1,37 @@ | |||
| #!/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' | ||||
| 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' | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								zshenv
									
										
									
									
									
								
							|  | @ -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
									
										
									
									
									
								
							
							
						
						
									
										8
									
								
								zshrc
									
										
									
									
									
								
							|  | @ -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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue