1
0
Fork 0

Improve less options

Remove silly message on logout

display non-success exit value for every command

Add first version of modules and load them up

Add more paths

Allow the sharing of prezto files by differentiating ZDOTDIR and where temp cache files will go: _ZDOTDIR/HOME

remove Vim swap files

Allow for both a shared and personal overriding .zpreztorc

In shared system, put .zcompdump in user's home

Fix path of .zcompdump

Fixed names of prompt

Support callbacks to override user & host value & style

Fix transpose* bindings for vi and ^Y for emacs

Fixed ordering of paths
pull/340/head
huyz 12 years ago
parent 036407ce8f
commit 3e5e108eaa

2
.gitignore vendored

@ -1,3 +1,5 @@
*.swp
*.swo
*.zwc *.zwc
*.zwc.old *.zwc.old
modules/*/cache.zsh modules/*/cache.zsh

@ -90,6 +90,10 @@ function pmodload {
if [[ -s "${ZDOTDIR:-$HOME}/.zpreztorc" ]]; then if [[ -s "${ZDOTDIR:-$HOME}/.zpreztorc" ]]; then
source "${ZDOTDIR:-$HOME}/.zpreztorc" source "${ZDOTDIR:-$HOME}/.zpreztorc"
fi fi
# huy: Let a shared zpreztorc file count first (where ZDOTDIR is the location of the shared files)
if [[ "${_ZDOTDIR:-$HOME}" != "${ZDOTDIR:-$HOME}" && -s "${_ZDOTDIR:-$HOME}/.zpreztorc" ]]; then
source "${_ZDOTDIR:-$HOME}/.zpreztorc"
fi
# Disable color and theme in dumb terminals. # Disable color and theme in dumb terminals.
if [[ "$TERM" == 'dumb' ]]; then if [[ "$TERM" == 'dumb' ]]; then

@ -15,7 +15,9 @@ fi
fpath=("${0:h}/external/src" $fpath) fpath=("${0:h}/external/src" $fpath)
# Load and initialize the completion system ignoring insecure directories. # Load and initialize the completion system ignoring insecure directories.
autoload -Uz compinit && compinit -i # huy: allow the sharing of prezto files
#autoload -Uz compinit && compinit -i
autoload -Uz compinit && compinit -i -d "${_ZDOTDIR:-$HOME}/.zcompdump"
# #
# Options # Options
@ -39,7 +41,9 @@ WORDCHARS='*?_-.[]~&;!#$%^(){}<>'
# Use caching to make completion for cammands such as dpkg and apt usable. # Use caching to make completion for cammands such as dpkg and apt usable.
zstyle ':completion::complete:*' use-cache on zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" # huy: use the user's home directory
#zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache"
zstyle ':completion::complete:*' cache-path "${_ZDOTDIR:-$HOME}/.zcompcache"
# Case-insensitive (all), partial-word, and then substring completion. # Case-insensitive (all), partial-word, and then substring completion.
if zstyle -t ':prezto:module:completion:*' case-sensitive; then if zstyle -t ':prezto:module:completion:*' case-sensitive; then

@ -18,7 +18,9 @@ fi
# Initialization # Initialization
# #
cache_file="${0:h}/cache.zsh" # huy: use the user's home directory
#cache_file="${0:h}/cache.zsh"
cache_file="${_ZDOTDIR:-$HOME}/.zprezto.fasd.cache.zsh"
if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then
# Set the base init arguments. # Set the base init arguments.
init_args=(zsh-hook) init_args=(zsh-hook)

@ -10,7 +10,9 @@
# Variables # Variables
# #
HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" # The path to the history file. # huy: use the user's home directory
#HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" # The path to the history file.
HISTFILE="${_ZDOTDIR:-$HOME}/.zhistory" # The path to the history file.
HISTSIZE=10000 # The maximum number of events to save in the internal history. HISTSIZE=10000 # The maximum number of events to save in the internal history.
SAVEHIST=10000 # The maximum number of events to save in the history file. SAVEHIST=10000 # The maximum number of events to save in the history file.

@ -0,0 +1,112 @@
# Huy's enhancement of Prezto's bindings
#
# In VI insert mode, these control-keys are still available.
# (Plus all the escape command such as \eM)
# ^Y
# ^N (not a useful binding right now)
# These bindings depend on and work in conjunction with prezto's 'editor' module.
pmodload 'editor'
#
# ZLE Widgets
#
#zle -N insert-nth-last-word
function insert-next-to-last-word() { zle insert-last-word -- -1 -2 }
zle -N insert-next-to-last-word
function insert-more-recent-last-word() { zle insert-last-word -- 1 -1 }
zle -N insert-more-recent-last-word
function insert-more-recent-next-to-last-word() { zle insert-last-word -- 1 -2 }
zle -N insert-more-recent-next-to-last-word
zle -C hist-complete complete-word _generic
zstyle ':completion:hist-complete:*' completer _history
#
# Reset prezto's annoying bindings
#
# Undo terrible bindings in 'completion' module
# https://github.com/sorin-ionescu/prezto/issues/338
bindkey -M viins -r "jk"
bindkey -M viins -r "kj"
# Undo prezto's zsh-history-substring-search bindings
bindkey -M vicmd 'k' up-line-or-history
bindkey -M vicmd 'j' down-line-or-history
#
# Some Emacs Key Bindings
# Copied from 'editor' module.
# NOTE: we can't take the ones that are ambiguous: ESC k could mean
# "go to cmd mode and go up" and this ambiguity slows down vi mode.
#
# Edit command in an external editor.
bindkey -M viins "$key_info[Control]X$key_info[Control]E" edit-command-line
if (( $+widgets[history-incremental-pattern-search-backward] )); then
bindkey -M viins "$key_info[Control]R" \
history-incremental-pattern-search-backward
bindkey -M viins "$key_info[Control]S" \
history-incremental-pattern-search-forward
fi
#
# Some Emacs and Vi Key Bindings (but for Vi command mode)
# Copied from 'editor' module.
#
for keymap in 'vicmd'; do
# Complete in the middle of word.
bindkey -M "$keymap" "$key_info[Control]I" expand-or-complete
# Use a more flexible push-line.
for key in "$key_info[Control]Q"
bindkey -M "$keymap" "$key" push-line-or-edit
done
#
# Custom bindings
#
# Just as with emacs
bindkey -M viins "$key_info[Control]T" transpose-chars
bindkey -M viins "$key_info[Escape]t" transpose-words
# Cancel the current completion (undo the <TAB> completion)
bindkey -M viins "$key_info[Control]Y" undo
# To be more like vim
bindkey -M vicmd 'J' vi-join
bindkey -M vicmd ':' execute-named-cmd
bindkey -M vicmd '_' execute-last-named-cmd
# Expand things
bindkey -M viins "$key_info[Control]P" hist-complete
# Pick out arguments from previous lines (in both directions)
bindkey -M viins "$key_info[Control]O" insert-last-word
bindkey -M viins "$key_info[Control]K" insert-more-recent-last-word
bindkey -M viins "$key_info[Control]E" insert-next-to-last-word
bindkey -M viins "$key_info[Control]A" insert-more-recent-next-to-last-word
# Complete on line-wise prefixes
bindkey -M viins "$key_info[Control]B" history-beginning-search-backward
bindkey -M vicmd "$key_info[Control]B" history-beginning-search-backward
bindkey -M viins "$key_info[Control]F" history-beginning-search-forward
bindkey -M vicmd "$key_info[Control]F" history-beginning-search-forward
# This allows you to edit your $PWD with the zle
for keymap in viins emacs
bindkey -M "$keymap" -s '^Z' $'cd $PWD\t'
#
# Marginally-useful bindigns
#
# Search in the history list for a line matching the current one and fetch
# the event following
bindkey '^N' infer-next-history # not very useful
unset key{map,}

@ -0,0 +1,10 @@
# This file is to undo or reset some of the bad defaults in Prezto
# Undo terrible bindings in 'completion' module
# https://github.com/sorin-ionescu/prezto/issues/338
bindkey -M viins -r "jk"
bindkey -M viins -r "kj"
# People will do -h if they want to
alias df='df -k'
alias du='du -k'

@ -0,0 +1,66 @@
# General utilities that should be useful for all of us
# Useful
setopt interactivecomments
setopt numericglobsort
setopt cshnullglob
# Report CPU usage stats if user+system > 5 seconds
REPORTTIME=5
# Minor
setopt histnostore
setopt kshoptionprint
##############################################################################
### Global alias
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
# Use at the end of the line to quickly redirect
alias -g 1NUL=">/dev/null"
alias -g 2NUL="2>/dev/null"
alias -g NUL=">/dev/null 2>&1"
##############################################################################
### Common commands
# Command line
function h {
history -d "${argv[1]:--$[ ${LINES:-24} - 3 ]}" "${(@)argv[2,-1]}" | $PAGER
}
### ls (which works on Linux, OS X, and OS X with GNU coreutils installed by Homebrew)
zstyle -s ':prezto:module:gnu-utility' prefix '_gnu_utility_p' || _gnu_utility_p='g'
if is-callable 'dircolors'; then
# GNU Core Utilities
_ls_color_flag=--color=always
else
# BSD Core Utilities
_ls_color_flag=-G
fi
# NOTE: The $_ls_color_flag goes after "$@" because prezto defines an alias which has
# --color=auto that we want to override
_gnu_utility_pcmd="${_gnu_utility_p}ls"
if (( ${+commands[${_gnu_utility_pcmd}]} )); then
_gnu_utility_ls="'${commands[${_gnu_utility_pcmd}]}'"
else
_gnu_utility_ls="command ls"
fi
eval "
function ls {
$_gnu_utility_ls -ACF \"\$@\" $_ls_color_flag | \$PAGER -e
}
"
alias ll="$aliases[ll] -a"
unset _gnu_utility_{p,cmds,cmd,pcmd,ls} _ls_color_flag
### Network commands
# Occasional commands
alias mtr='mtr --curses'

@ -12,7 +12,9 @@ fi
# Load NPM completion. # Load NPM completion.
if (( $+commands[npm] )); then if (( $+commands[npm] )); then
cache_file="${0:h}/cache.zsh" # huy: use the user's home directory
#cache_file="${0:h}/cache.zsh"
cache_file="${_ZDOTDIR:-$HOME}/.zprezto.node.cache.zsh"
if [[ "$commands[npm]" -nt "$cache_file" || ! -s "$cache_file" ]]; then if [[ "$commands[npm]" -nt "$cache_file" || ! -s "$cache_file" ]]; then
# npm is slow; cache its output. # npm is slow; cache its output.

@ -16,7 +16,9 @@ fi
if [[ "$OSTYPE" == darwin* ]]; then if [[ "$OSTYPE" == darwin* ]]; then
# Perl is slow; cache its output. # Perl is slow; cache its output.
cache_file="${0:h}/cache.zsh" # huy: use the user's home directory
#cache_file="${0:h}/cache.zsh"
cache_file="${_ZDOTDIR:-$HOME}/.zprezto.perl.cache.zsh"
perl_path="$HOME/Library/Perl/5.12" perl_path="$HOME/Library/Perl/5.12"
if [[ -f "$perl_path/lib/perl5/local/lib.pm" ]]; then if [[ -f "$perl_path/lib/perl5/local/lib.pm" ]]; then

@ -0,0 +1,229 @@
# Progressive theme that displays only relevant information as needed.
# Builds on both sorin and nicoulaj theme.
#
# Features:
# - Multiple verbosity styles:
# - One or multiple lines
# - In minimal style, shows user@hostname if connected through SSH.
# - toggle with aliases "P 0" ... "P 5"
# - VCS information in the right prompt.
# - Supports prezto's git-info if 'git' module is loaded, or zsh's default vcs_info otherwise
# - If using the default vcs_info module:
# - Only shows the path on the left prompt by default.
# - Crops the path to a defined length and only shows the path relative to
# the current VCS repository root.
# - Shows if logged in as root or not.
# - Shows number of jobs
# - Shows shell level if greater than 1
# - Colors work with Solarized 8-bit ANSI colors
# - Supports callbacks for customizing style and value of user and hostname
# Load dependencies.
pmodload 'helper'
function prompt_progressive_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
# Get Git repository information.
if (( $+functions[git-info] )); then
if git-info; then
# Some functionality not provided by git-info
#git_info[remote]="$(git remote -v | fgrep fetch | sed 's/.*[\/:]\([^:\/][^:\/]*\)\.git.*/\1/')"
git_info[repo]=$(basename $(git rev-parse --show-toplevel))
fi
else
vcs_info
fi
}
function prompt_progressive_load() {
uptime | sed 's/.*: *//;s/,//g'
}
# @param verbosity From 0 to 5 with 2 as default
function prompt_progressive_setup {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst)
# Load required functions.
autoload -Uz add-zsh-hook
# If git module is loaded, use that, otherwise get standard zsh vcs_info
if (( $+functions[git-info] )); then
# Set git-info parameters (from sorin prompt)
zstyle ':prezto:module:editor:info:completing' format '%F{magenta}...%f'
zstyle ':prezto:module:editor:info:keymap:primary' format '%#'
zstyle ':prezto:module:editor:info:keymap:alternate' format '%F{yellow}⎋%f'
zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format '%F{red}➨%f'
zstyle ':prezto:module:git:info:action' format '%F{yellow}%s%f%%b'
zstyle ':prezto:module:git:info:added' format ' %F{green}✚%f%%b'
zstyle ':prezto:module:git:info:ahead' format ' %F{yellow}⬆%f%%b'
zstyle ':prezto:module:git:info:behind' format ' %F{yellow}⬇%f%%b'
zstyle ':prezto:module:git:info:branch' format '%F{blue}%b%f'
zstyle ':prezto:module:git:info:commit' format '%F{blue}%.7c%f'
zstyle ':prezto:module:git:info:deleted' format ' %F{red}✖%f%%b'
zstyle ':prezto:module:git:info:modified' format ' %%B%F{magenta}✱%f%%b'
zstyle ':prezto:module:git:info:position' format '%F{blue}%p%f'
zstyle ':prezto:module:git:info:renamed' format ' %%B%F{magenta}➜%f%%b'
zstyle ':prezto:module:git:info:stashed' format ' %F{cyan}✭%f%%b'
zstyle ':prezto:module:git:info:unmerged' format ' %F{yellow}═%f%%b'
zstyle ':prezto:module:git:info:untracked' format ' %F{magenta}?%f%%b'
zstyle ':prezto:module:git:info:keys' format \
'prompt' '%F{green}${git_info[repo]:+$git_info[repo]:}%f$(coalesce "%b" "%p" "%c")%s' \
'rprompt' '%A%B%a%d%m%r%U%u%S'
# Our extensions
zstyle ':prezto:module:git:info:repo' format ':%%B%F{yellow}%R%f%%b'
else
autoload -Uz vcs_info
local vcs_info_color='%F{242}'
# Set vcs_info parameters.
zstyle ':vcs_info:*' enable git hg svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '%F{green}✚%{%}'
zstyle ':vcs_info:*' unstagedstr '%F{red}?%{%}'
# On OS X, see /usr/share/zsh/4.3.11/functions/VCS_INFO_formats for docs:
# %r: repo
# %s: VCS, e.g. 'git'
# %b: branch
# %u: unstaged
# %c: staged
#zstyle ':vcs_info:*' actionformats "%S" "%r/%s/%b %u%c (%a)"
#zstyle ':vcs_info:*' formats "%S" "%r/%s/%b %u%c"
zstyle ':vcs_info:*' actionformats "√%%S" "[%r:%B%F{magenta}%b%f %u%c (%a)"
zstyle ':vcs_info:*' formats "√%S" "[%r:%B%F{magenta}%b%{%} %u%c]"
zstyle ':vcs_info:*' nvcsformats "%~" ""
fi
# Add hook for calling vcs_info before each command.
add-zsh-hook precmd prompt_progressive_precmd
# Customizable parameters.
local max_path_chars=50
# Style
if [[ "$1" == --init ]]; then
local init=1
shift
fi
local style=''
case "$1" in
0) style=bare ;;
1) style=minimal ;;
3) style=unabbreviated ;;
4) style=multiline ;;
5) style=verbose ;;
2|) style=concise ;;
*) style="$1" ;;
esac
[[ -z "$init" ]] && print -P "Switching to '%F{blue}$style%f' style of '%F{green}progressive%f' prompt."
### Process username and hostname
local user host
user="%F{green}%n%f"
user_unformatted="%n"
if (( $+functions[prompt_map_user] )); then
prompt_map_user $USERNAME
user="$prompt_info_user"
user_unformatted="$prompt_info_user_unformatted"
fi
host="%m"
host_unformatted="%m"
if (( $+functions[prompt_map_host] )); then
prompt_map_host $HOST
host="$prompt_info_host"
host_unformatted="$prompt_info_host_unformatted"
fi
### Define prompt
if [[ $style == bare ]]; then
PS1='%# '
RPS1=''
return
fi
local P
if [[ $style == 'verbose' ]]; then
# Insert the time
P+='%F{blue}%*%f '
fi
if [[ $style != 'minimal' || -n "$SSH_TTY" ]]; then
# Username and host
P+="${user}@${host} "
fi
# Start coloring path
P+="%F{cyan}"
if [[ $style != (unabbreviated|multiline|verbose) ]]; then
# Limit the amount of space taken by the rest of the line
P+="%${max_path_chars}<…<"
fi
# Print up to 5 elements of the current directory
#P+="%5~%f"
if (( $+functions[git-info] )); then
P+='%~'
else
# Print current directory or, if inside repo, path relative to that
P+='${vcs_info_msg_0_}'
fi
# Stop coloring path
P+="%f"
# Number of background jobs
P+="%1(j. %jJ.)"
# Shell level if greater than 1
P+="%(2L/ L1/)"
if [[ $style == (multiline|verbose) ]]; then
P+="
"
else
# Separator
##P+=" "
fi
# Add names and titles to window and tab titles
# (not needed because that's handled by 'terminal' module)
#P+="%{]2;${user_unformatted}@${host_unformatted}: %~]1;%1~%}"
# Terminate the line with character that depends on mode
if (( $+functions[git-info] )); then
P+='${editor_info[overwrite]:-${editor_info[keymap]}} '
else
P+='%# '
fi
PS1="$P"
# Right prompt contains VCS info and maybe load
local R
if (( $+functions[git-info] )); then
R+='${git_info:+[${(e)git_info[prompt]}${git_info[rprompt]}]}'
else
R+="${vcs_info_color}"'${vcs_info_msg_1_}'"%f"
fi
if [[ $style == 'verbose' ]]; then
R+=" ($(prompt_progressive_load))"
fi
RPROMPT="$R"
}
# Allows quick switching of prompts at command line; e.g.
# P 0
# P 5
# P verbose
alias P='prompt_progressive_setup'
prompt_progressive_setup --init "$@"

@ -8,7 +8,9 @@
# Execute code that does not affect the current session in the background. # Execute code that does not affect the current session in the background.
{ {
# Compile the completion dump to increase startup speed. # Compile the completion dump to increase startup speed.
zcompdump="${ZDOTDIR:-$HOME}/.zcompdump" # huy: use the user's home directory
#zcompdump="${ZDOTDIR:-$HOME}/.zcompdump"
zcompdump="${_ZDOTDIR:-$HOME}/.zcompdump"
if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then
zcompile "$zcompdump" zcompile "$zcompdump"
fi fi

@ -6,9 +6,9 @@
# #
# Print the message. # Print the message.
cat <<-EOF #cat <<-EOF
#
Thank you. Come again! #Thank you. Come again!
-- Dr. Apu Nahasapeemapetilon # -- Dr. Apu Nahasapeemapetilon
EOF #EOF

@ -24,6 +24,8 @@ zstyle ':prezto:*:*' color 'yes'
# Set the Prezto modules to load (browse modules). # Set the Prezto modules to load (browse modules).
# The order matters. # The order matters.
zstyle ':prezto:load' pmodule \ zstyle ':prezto:load' pmodule \
'gnu-utility' \
\
'environment' \ 'environment' \
'terminal' \ 'terminal' \
'editor' \ 'editor' \
@ -32,7 +34,21 @@ zstyle ':prezto:load' pmodule \
'spectrum' \ 'spectrum' \
'utility' \ 'utility' \
'completion' \ 'completion' \
'prompt' 'prompt' \
\
'command-not-found' \
'syntax-highlighting' \
'history-substring-search' \
'archive' \
'git' \
'screen' \
'python' \
'node' \
'dpkg' \
'fasd' \
'huy-reset' \
'huy-editor' \
'huy-utility' \
# #
# Editor # Editor

@ -36,7 +36,9 @@ fi
# Set the default Less options. # Set the default Less options.
# Mouse-wheel scrolling has been disabled by -X (disable screen clearing). # Mouse-wheel scrolling has been disabled by -X (disable screen clearing).
# Remove -X and -F (exit if the content fits on one screen) to enable it. # Remove -X and -F (exit if the content fits on one screen) to enable it.
export LESS='-F -g -i -M -R -S -w -X -z-4' export LESS='-F -i -M -R -w -X -z-4'
# huy: improve less options
export LESS="${${LESS/-g /}/-S /} -j4"
# Set the Less input preprocessor. # Set the Less input preprocessor.
if (( $+commands[lesspipe.sh] )); then if (( $+commands[lesspipe.sh] )); then
@ -98,3 +100,31 @@ if [[ -d "$TMPDIR" ]]; then
fi fi
fi fi
#
# huy: more paths
#
typeset -T NODE_PATH node_path
typeset -U path manpath fpath classpath pythonpath perl5lib node_path
# Add some other paths
for path_dir in \
/opt/local/bin \
/opt/local/sbin \
/brew/bin \
/brew/sbin \
/brew/share/npm/bin \
~/bin \
; do
[[ -d $path_dir ]] && path=($path_dir $path)
done
# Add some other paths
for path_dir in \
/opt/local/man \
/brew/share/man \
~/man \
; do
[[ -d $path_dir ]] && manpath=($path_dir $manpath)
done
unset path_dir

@ -12,3 +12,6 @@ fi
# Customize to your needs... # Customize to your needs...
# huy: display non-success exit value for every command
# This cannot be put in a module as it's always scoped to the enclosing function
setopt printexitvalue

Loading…
Cancel
Save