Major cleanup and restructuring
- remove custom module loader, use zplug for own plugins - move config parts from modules to files - move other module parts to separate zsh plugins
This commit is contained in:
parent
98a86e6b70
commit
d0598c2838
README.mdbindings.zshcompletion.zsh
modules
plugins
zplug.zshzshenvzshrc
48
README.md
48
README.md
|
@ -4,45 +4,9 @@ crater's zsh config
|
|||
Installation:
|
||||
-------------
|
||||
|
||||
*system-wide config*: Put repository contents in `/etc/zsh`.
|
||||
|
||||
*user config*: copy `env_template` to $HOME/.zshenv. Change value of `$ZDOTDIR` in
|
||||
that file to the path, where the repository resides.
|
||||
Note that this file is read before any other config files, so if any variables
|
||||
you set in there have wrong values, they are probably overwritten in another
|
||||
file.
|
||||
|
||||
modules:
|
||||
--------
|
||||
|
||||
This zsh configuration is modular. A module consists of a folder in the modules/
|
||||
directory, containing a script file named `init` and an optional `depend` file.
|
||||
More files may be included in the folder, they will be ignored by the module
|
||||
loader. The name of the module is the name of its directory.
|
||||
|
||||
The `init` file is executed, when a module is loaded. When and if a module is
|
||||
loaded is determined by its `depend` file and the environment variables
|
||||
`$ZMODLOAD_ONLY` and `$ZMODLOAD_BLACKLIST`.
|
||||
|
||||
`$ZMODLOAD_BLACKLIST` is a list of modules, that will not be loaded.
|
||||
|
||||
`$ZMODLOAD_ONLY` works as a whitelist. If it is set, only modules in this list
|
||||
and modules required by them will be loaded.
|
||||
|
||||
A `depend` file contains the requirements for loading a module. It should
|
||||
contain lines of the form `<type> <module>`. There are 3 types for
|
||||
dependencies:
|
||||
|
||||
- `depend <module>`: `<module>` will be loaded before the depending
|
||||
module (the module whose `depend` file contains this rule), regardless
|
||||
of `$ZMODLOAD_ONLY`. If the module is blacklisted, it and the depending
|
||||
module are not loaded. Note that already queued dependencies of the depending
|
||||
module will be loaded anyways.
|
||||
|
||||
- `after <module>`: `<module>` will be loaded before the depending
|
||||
module, if it would be loaded anyways. If it is either blacklisted or
|
||||
`$ZMODLOAD_ONLY` is non-empty but does not contain `<module>`, it is not
|
||||
loaded. This does not affect loading of the depending module.
|
||||
|
||||
- `block <module>`: abort loading of the depending module, if `<module>`
|
||||
is already loaded or contained in `$ZMODLOAD_ONLY`.
|
||||
From the checked out repo:
|
||||
```
|
||||
ln -s $PWD/zshenv $HOME/.zshenv
|
||||
```
|
||||
The zshenv file sets the location to the rest of the config (`$ZDOTDIR`)
|
||||
automatically, based on the link target.
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# Allow <esc>:q in vim mode to exit the shell
|
||||
exit(){builtin exit;}
|
||||
zle -N q exit
|
||||
bindkey -v
|
||||
|
||||
typeset -A key
|
||||
|
||||
|
@ -17,15 +15,6 @@ key[Right]=${terminfo[kcuf1]}
|
|||
key[PageUp]=${terminfo[kpp]}
|
||||
key[PageDown]=${terminfo[knp]}
|
||||
|
||||
bindkey -M vicmd ! edit-command-line-tmux
|
||||
|
||||
#unicode input
|
||||
autoload -U insert-unicode-char
|
||||
zle -N insert-unicode-char
|
||||
bindkey "^Vu" insert-unicode-char
|
||||
|
||||
bindkey "\e." insert-last-word
|
||||
|
||||
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
|
||||
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
|
||||
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" yank
|
||||
|
@ -37,17 +26,24 @@ bindkey "\e." insert-last-word
|
|||
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" history-beginning-search-backward
|
||||
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" history-beginning-search-forward
|
||||
|
||||
bindkey "^[e" expand-cmd-path # C-e for expanding path of typed command.
|
||||
bindkey " " magic-space # Do history expansion on space.
|
||||
bindkey $'\177' backward-delete-char #backspace
|
||||
bindkey $'\10' backward-delete-word #C-backspace
|
||||
bindkey "^[e" expand-cmd-path # C-e for expanding path of typed command.
|
||||
bindkey " " magic-space # Do history expansion on space.
|
||||
bindkey $'\177' backward-delete-char # backspace
|
||||
bindkey $'\10' backward-delete-word # C-backspace
|
||||
|
||||
bindkey -M vicmd ! edit-command-line-tmux
|
||||
|
||||
#unicode input
|
||||
autoload -U insert-unicode-char
|
||||
zle -N insert-unicode-char
|
||||
bindkey "^Vu" insert-unicode-char
|
||||
|
||||
bindkey "\e." insert-last-word
|
||||
|
||||
bindkey "\e[1;5D" vi-backward-blank-word
|
||||
bindkey "\e[1;5C" vi-forward-blank-word
|
||||
#bindkey . rationalise-dot
|
||||
|
||||
bindkey $'\20' push-line-or-edit
|
||||
bindkey -s "^F" "fuck\n"
|
||||
|
||||
# Finally, make sure the terminal is in application mode, when zle is
|
||||
# active. Only then are the values from $terminfo valid.
|
||||
|
@ -60,9 +56,8 @@ local function zle-line-finish () {
|
|||
zle -N zle-line-init
|
||||
zle -N zle-line-finish
|
||||
|
||||
insert_sudo () { zle beginning-of-line; zle -U "sudo " }
|
||||
insert_sudo () { zle beginning-of-line; zle -U "sudo "; zle end-of-line }
|
||||
zle -N insert-sudo insert_sudo
|
||||
|
||||
bindkey "^[s" insert-sudo
|
||||
|
||||
local function accept-or-recall-and-infer-history() {
|
||||
|
@ -89,5 +84,3 @@ if exists incstring; then
|
|||
zle -N inc-last-command
|
||||
bindkey "^A" inc-last-command
|
||||
fi
|
||||
|
||||
bindkey "\eb" zle-bookmarks
|
|
@ -48,3 +48,4 @@ zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | un
|
|||
compdef _command fork
|
||||
compdef _command detach
|
||||
compdef _command ontv
|
||||
compdef _notmuch nmfind=notmuch-search
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
need autoloader
|
|
@ -1,77 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
autoload -U colors && colors
|
||||
|
||||
. $MPATH/spectrum
|
||||
reset="%{${reset_color}%}"
|
||||
|
||||
#
|
||||
# 256-color-term or rxvt with wrong tput output
|
||||
#
|
||||
if [[ "`tput colors`" == "256" ]] || [[ "`tput colors`" == "88" ]] ; then
|
||||
pathcolor="%{${FG[27]}%}"
|
||||
ropathcolor="%{${FG[92]}%}"
|
||||
|
||||
gitdirty="%{${FX[bold]}${FG[160]}%}"
|
||||
gitstaged="%{${FX[bold]}${FG[34]}%}"
|
||||
gitclean="%{${FG[240]}%}"
|
||||
stycolor="%{${FG[240]}%}"
|
||||
exitcolor=$gitdirty
|
||||
rpscolor="%{${FG[238]}%}"
|
||||
gituntracked="%{$FX[bold]$FG[253]%}●%{$reset$rpscolor%}"
|
||||
|
||||
local usercolor_base
|
||||
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
|
||||
usercolor_base=196
|
||||
usercolor_mod=30
|
||||
else
|
||||
usercolor_base=47
|
||||
usercolor_mod=28
|
||||
|
||||
fi
|
||||
if [ ! -z $SSH_CLIENT ] || [ ! -z $SSH_CONNECTION ]; then
|
||||
usercolor_base=$((usercolor_base + usercolor_mod))
|
||||
hostcolor="%{${FG[226]}%}"
|
||||
else
|
||||
hostcolor=$gitclean
|
||||
fi
|
||||
usercolor="%{${FX[bold]}${FG[$usercolor_base]}%}"
|
||||
|
||||
for colorfile in /etc/DIR_COLORS.256 \
|
||||
/etc/DIR_COLORS.256color \
|
||||
/etc/colors/DIR_COLORS.256 \
|
||||
/etc/colors/DIR_COLORS.256color; do
|
||||
if [ -e $colorfile ] ; then
|
||||
eval "$(dircolors $colorfile)"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
else
|
||||
pathcolor="%{$fg_bold[blue]}%}"
|
||||
|
||||
gitdirty="%{${fg[yellow]}%}"
|
||||
gitstaged="%{${fg[green]}%}"
|
||||
gitclean="%{${fg[white]}%}"
|
||||
vcs_revision="%{${fg_bold[black]}%}"
|
||||
|
||||
exitcolor="$gitdirty"
|
||||
rpscolor="%{$fg_bold[black]}%}"
|
||||
|
||||
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
|
||||
if [ ! -z $SSH_CLIENT ]; then
|
||||
usercolor="%{${fg_bold[yellow]}%}"
|
||||
hostcolor="%{${fg_no_bold[blue]}%}"
|
||||
else
|
||||
usercolor="%{${fg_bold[red]}%}"
|
||||
hostcolor="%{${fg_bold[black]}%}"
|
||||
fi
|
||||
else
|
||||
if [ ! -z $SSH_CLIENT ]; then
|
||||
usercolor="%{${fg_bold[blue]}%}"
|
||||
hostcolor="%{${fg_no_bold[blue]}%}"
|
||||
else
|
||||
usercolor="%{${fg_bold[green]}%}"
|
||||
hostcolor="%{${fg_bold[black]}%}"
|
||||
fi
|
||||
fi
|
||||
fi
|
|
@ -1,19 +0,0 @@
|
|||
#! /bin/zsh
|
||||
# A script to make using 256 colors in zsh less painful.
|
||||
# P.C. Shyamshankar <sykora@lucentbeing.com>
|
||||
|
||||
typeset -Ag FX FG BG
|
||||
|
||||
FX=(
|
||||
reset "[00m"
|
||||
bold "[01m" no-bold "[22m"
|
||||
italic "[03m" no-italic "[23m"
|
||||
underline "[04m" no-underline "[24m"
|
||||
blink "[05m" no-blink "[25m"
|
||||
reverse "[07m" no-reverse "[27m"
|
||||
)
|
||||
|
||||
for color in {0..255}; do
|
||||
FG[$color]="[38;5;${color}m"
|
||||
BG[$color]="[48;5;${color}m"
|
||||
done
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
typeset -Ax conf_locations
|
||||
|
||||
conf() {
|
||||
if [[ $1 == -r ]]; then
|
||||
local confconf=$(zdotfile confs)
|
||||
if [[ -e $confconf ]]; then
|
||||
conf_locations[conf]=$confconf
|
||||
conf_locations+=( $(<$confconf) )
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -z $1 ]]; then
|
||||
echo "Available configs:"
|
||||
for k v in ${(kv)conf_locations}; do
|
||||
printf "%-20s %s\n" ${k}: ${(e)v}
|
||||
done
|
||||
return 1
|
||||
fi
|
||||
|
||||
local target=${(e)conf_locations[${1}]}
|
||||
if [[ -d ${target} ]]; then
|
||||
cd ${target}
|
||||
if ! [[ -w ${target} ]]; then
|
||||
su
|
||||
fi
|
||||
elif [[ -f ${target} ]]; then
|
||||
if ! [[ -w ${target} ]]; then
|
||||
sudoedit ${target}
|
||||
else
|
||||
$EDITOR ${target}
|
||||
fi
|
||||
elif [[ -n ${target} ]]; then
|
||||
echo "Conf target for $1 missing: $target"
|
||||
else
|
||||
echo "Unknown conf target: $1"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
conf -r
|
|
@ -1,6 +0,0 @@
|
|||
if exists fast; then
|
||||
eval "$(fasd --init auto)"
|
||||
bindkey '^X^A' fasd-complete # C-x C-a to do fasd-complete (fils and directories)
|
||||
bindkey '^X^F' fasd-complete-f # C-x C-f to do fasd-complete-f (only files)
|
||||
bindkey '^X^D' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories)
|
||||
fi
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
istrue() {
|
||||
case "$1" in
|
||||
yes|yeah|on|true|1|y)
|
||||
return 0;;
|
||||
esac
|
||||
return 1;
|
||||
}
|
||||
|
||||
in_array() {
|
||||
local needle=$1
|
||||
shift
|
||||
arr=( "${@}" )
|
||||
(( $arr[(i)$needle] != ${#arr} + 1 ))
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 76ea9e1df3166209d5f937f57a0833f26b1a01bd
|
|
@ -1,221 +0,0 @@
|
|||
#################################################################################
|
||||
# ZSH modular config
|
||||
#################################################################################
|
||||
#
|
||||
# Helps you split up your config into modules and reuse modules from other
|
||||
# people.
|
||||
#
|
||||
# Modules are stored in the "modules" folder in your configuration directory
|
||||
# (default: /etc/zsh, if you want to use this in a user configuration file, set
|
||||
# the variable $ZDOTDIR to your zsh configuration directory in ~/.zshenv)
|
||||
#
|
||||
# Each module should have a file called "init". This file is sourced, when the
|
||||
# module is loaded and is responsible for sourcing any other files needed by the
|
||||
# module.
|
||||
#
|
||||
# The module can use $MPATH variable, which contains the module's directory.
|
||||
|
||||
|
||||
#################################
|
||||
# INTERNAL MODULE LOADING STUFF #
|
||||
#################################
|
||||
|
||||
# Path to module directory
|
||||
if [[ -z $ZMODPATH ]]; then
|
||||
ZMODPATH=( ${ZDOTDIR:+$ZDOTDIR/modules} )
|
||||
[[ -d /etc/zsh/modules ]] && ZMODPATH+=/etc/zsh/modules
|
||||
fi
|
||||
|
||||
local mod_path() {
|
||||
for dir in $ZMODPATH; do
|
||||
if [[ -e $dir/$1 ]]; then
|
||||
echo "$dir/$1"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
. $(mod_path helpers.zsh)
|
||||
errdetails=""
|
||||
|
||||
modqueue=( )
|
||||
|
||||
# Adds a module to the loading queue
|
||||
#
|
||||
# This function adds a module for later loading, if it is not already queued.
|
||||
# It calls mod_deps for dependency checking. If dependencies are not satisfied,
|
||||
# the module is not loaded.
|
||||
#
|
||||
# Parameters:
|
||||
# 1: module name
|
||||
# 2: if loaded as a dependency: is_dep
|
||||
# otherwise empty
|
||||
# 3: if loaded as a dependency: the depending module
|
||||
#
|
||||
mod_queue() {
|
||||
local module="$1"
|
||||
local modsource=$(mod_path $module)
|
||||
|
||||
if ! mod_exists "$module" ; then
|
||||
if [[ "$2" == "is_dep" ]]; then
|
||||
echo "$3: Unsatisfied dependency \"$module\"";
|
||||
return 1
|
||||
else
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
|
||||
in_array "$module" "${(@)modqueue}" && return 0
|
||||
|
||||
if mod_deps "$modsource"; then
|
||||
modqueue=( "${(@)modqueue}" "$module" )
|
||||
else
|
||||
case $? in
|
||||
1) echo "module $module not loaded because of missing dependencies: $errdetails";;
|
||||
2) echo "module $module not loaded because of blocking module: $errdetails";;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
mod_exists() {
|
||||
mod_path "$1" &> /dev/null
|
||||
}
|
||||
|
||||
# Checks for module dependencies
|
||||
#
|
||||
# Reads the "depend" file for a module and tries to queue all dependencies for
|
||||
# loading. If any fails, it returns 1;
|
||||
#
|
||||
# Parameters:
|
||||
# 1: Path to module
|
||||
#
|
||||
mod_deps() {
|
||||
modpath=$1
|
||||
! [ -e $modpath/depend ] && return 0;
|
||||
|
||||
while read relation dep; do
|
||||
mod_check_dep $modpath $relation $dep
|
||||
[ $? -gt 0 ] && return $?;
|
||||
done < "$modpath/depend"
|
||||
return 0;
|
||||
}
|
||||
|
||||
mod_check_dep() {
|
||||
modpath=$1
|
||||
relation=$2
|
||||
dep=$3
|
||||
|
||||
#legacy entry compatibility
|
||||
if [ -z "$dep" ]; then
|
||||
dep="$relation"
|
||||
relation="need"
|
||||
fi
|
||||
|
||||
if in_array "$dep" "${(@)modqueue}" && [[ "$relation" != "block" ]]; then
|
||||
return 0;
|
||||
fi
|
||||
|
||||
case "$relation"; in
|
||||
"need")
|
||||
if ! mod_queue "$dep" is_dep ${modpath}; then
|
||||
errdetails="$dep"
|
||||
return 1;
|
||||
fi
|
||||
;;
|
||||
"after")
|
||||
if ([ -z "$ZMODLOAD_ONLY" ] \
|
||||
|| in_array "$dep" "${(@)ZMODLOAD_ONLY}") \
|
||||
&& ! in_array "$dep" "${(@)ZMODLOAD_BLACKLIST}"; then
|
||||
mod_queue "$dep"
|
||||
fi ;;
|
||||
"block")
|
||||
if in_array "$dep" "${(@)ZMODLOAD_ONLY}" \
|
||||
|| in_array "$dep" "${(@)modqueue}"; then
|
||||
errdetails="$dep"
|
||||
return 2
|
||||
fi;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Loads all queued modules
|
||||
#
|
||||
# After queueing all modules and dependency modules, this function calls their
|
||||
# init-scripts, if existent (if not, the module is ignored for now)
|
||||
#
|
||||
mod_load() {
|
||||
local MPATH
|
||||
for module in "${(@)modqueue}"; do
|
||||
MPATH=$(mod_path $module)
|
||||
[ -e "$(mod_path $module)/init" ] && . "$(mod_path $module)/init"
|
||||
done
|
||||
}
|
||||
|
||||
# Begins module loading procedure
|
||||
#
|
||||
# Queues all modules in the module directory or, if set, only modules listed in
|
||||
# $ZMODLOAD_ONLY
|
||||
|
||||
mod_init() {
|
||||
|
||||
if [ -n "$ZMODLOAD_ONLY" ]; then
|
||||
for module in "${(@)ZMODLOAD_ONLY}"; do
|
||||
[ -d "$(mod_path $module)" ] && mod_queue "$module"
|
||||
done
|
||||
else
|
||||
for moddir in $ZMODPATH; do
|
||||
for module in $moddir/*(/N); do
|
||||
if [ -z "$ZMODLOAD_BLACKLIST" ] \
|
||||
|| ! in_array ${module:t} ${(@)ZMODLOAD_BLACKLIST}; then
|
||||
mod_queue "${module:t}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
mod_load
|
||||
}
|
||||
|
||||
# return 0 if all given modules were loaded (i.e. in the load queue)
|
||||
mod_loaded() {
|
||||
for i in "$@"; do
|
||||
in_array $i ${(@)modqueue} || return 1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
#################################################################################
|
||||
# Utility functions for modules
|
||||
#################################################################################
|
||||
|
||||
#
|
||||
# Register hook functions
|
||||
# see 'SPECIAL FUNCTIONS' section in zshmisc(1) for more information
|
||||
#
|
||||
|
||||
precmd_hook() {
|
||||
[[ -z $precmd_functions ]] && precmd_functions=()
|
||||
precmd_functions=($precmd_functions $*)
|
||||
}
|
||||
|
||||
chpwd_hook() {
|
||||
[[ -z $chpwd_functions ]] && chpwd_functions=()
|
||||
chpwd_functions=($chpwd_functions $*)
|
||||
}
|
||||
|
||||
preexec_hook() {
|
||||
[[ -z $preexec_functions ]] && preexec_functions=()
|
||||
preexec_functions=($preexec_functions $*)
|
||||
}
|
||||
|
||||
zshaddhistory_hook() {
|
||||
[[ -z $zshaddhistory_functions ]] && zshaddhistory_functions=()
|
||||
zshaddhistory_functions=($zshaddhistory_functions $*)
|
||||
}
|
||||
|
||||
zshexit_hook() {
|
||||
[[ -z $zshexit_functions ]] && zshexit_functions=()
|
||||
zshexit_functions=($zshexit_functions $*)
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
load_localrc() {
|
||||
local dir=${1:-$PWD}
|
||||
if [[ -f $dir/.lzshrc ]]; then source $dir/.lzshrc
|
||||
elif [[ "$dir" != "/" ]]; then load_localrc ${dir:h}
|
||||
fi
|
||||
}
|
||||
|
||||
chpwd_hook load_localrc
|
|
@ -1,4 +0,0 @@
|
|||
need color
|
||||
after vcs
|
||||
after todo
|
||||
after work
|
|
@ -1,151 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
autoload -U colors && colors
|
||||
autoload -U promptinit
|
||||
|
||||
PROMPT_UNICODE=${PROMPT_UNICODE:-yes}
|
||||
setopt prompt_subst
|
||||
|
||||
PVPREFIX="╼╢"
|
||||
PVSUFFIX="╟╾"
|
||||
PR_HBAR='─'
|
||||
PR_VBAR='│'
|
||||
CORNER_LU='╭'
|
||||
CORNER_LD='╰'
|
||||
CORNER_RU='╮'
|
||||
CORNER_RD='╯'
|
||||
ARR_LEFT='◀'
|
||||
|
||||
if [[ "$PROMPT_UNICODE" != "yes" ]]; then
|
||||
PVPREFIX="["
|
||||
PVSUFFIX="]"
|
||||
PR_HBAR='-'
|
||||
PR_VBAR='|'
|
||||
CORNER_LU=','
|
||||
CORNER_LD="'"
|
||||
CORNER_RU=','
|
||||
CORNER_RD="'"
|
||||
ARR_LEFT='<'
|
||||
fi
|
||||
|
||||
|
||||
# Show screen STY and tmux number
|
||||
sty () {
|
||||
local sty=$?
|
||||
echo -n "${SIG_PROMPT_PREFIX}"
|
||||
echo -n "${STY:+"SCREEN:"}${(S)STY/#*./}${STY+" - "}"
|
||||
echo -n "${TMUX:+"TMUX:"}${TMUX/*,/}${TMUX+" - "}"
|
||||
echo -n "%y${SIG_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
# show number of attached and detached screens
|
||||
screennum() {
|
||||
local att
|
||||
local det
|
||||
local dead
|
||||
if [ -x /usr/bin/screen ]; then
|
||||
att=`screen -ls | grep -c Attached`
|
||||
det=`screen -ls | grep -c Detached`
|
||||
dead=`screen -ls | grep -c Dead `
|
||||
echo "A:$att|D:$det|?:$dead"
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_precmd {
|
||||
if mod_loaded vcs; then
|
||||
vcs_info
|
||||
fi
|
||||
setprompt
|
||||
RPS1='$usercolor${ARR_LEFT}%(?::$exitcolor${PVPREFIX})$(exitstatus)%(?::${PVSUFFIX})${stycolor}${PVPREFIX}$(sty)${rpscolor}${PVSUFFIX}${CORNER_RD}$reset'
|
||||
}
|
||||
|
||||
precmd_hook prompt_precmd
|
||||
|
||||
# Executed after a command has been read and is to be executed.
|
||||
function prompt_preexec {
|
||||
# if running gnu screen, set the window name to the last run command
|
||||
# FIXME any way to make this not change certain window titles (by window
|
||||
# number or if a title isn't already set?)
|
||||
if [[ -n "$TMUX" ]] \
|
||||
&& ! tmux show -w | grep -q "automatic-rename off"; then
|
||||
local CMD=${1[(wr)^(*=*|ssh|sudo|-*)]}
|
||||
echo -ne "\ek$CMD\e\\"
|
||||
fi
|
||||
}
|
||||
|
||||
if mod_loaded todo; then
|
||||
function todo_to_read_info() {
|
||||
count=$(todo_count all ${TO_READ_FILE:-$HOME/.to_read})
|
||||
if [ "$count" -gt 1 ]; then
|
||||
echo -n "${PVPREFIX}${pathcolor}To read: $((count -1)) ${rpscolor}${PVSUFFIX}"
|
||||
elif [ "$count" -lt 0 ]; then
|
||||
echo -n "${PVPREFIX}${pathcolor}no todo${rpscolor}${PVSUFFIX}"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
preexec_hook prompt_preexec
|
||||
|
||||
function setprompt() {
|
||||
local -a lines infoline middleline
|
||||
local x i filler i_width
|
||||
|
||||
infoline+=( "${rpscolor}${CORNER_LU}" )
|
||||
|
||||
### First, assemble the top line
|
||||
# Current dir
|
||||
[[ -w $PWD ]] && infoline+=( ${pathcolor} ) || infoline+=( ${ropathcolor} )
|
||||
infoline+=( "${PVPREFIX} %(5~|%-1~/.../|)%3~ ${PVSUFFIX}${rpscolor}${PR_HBAR}" )
|
||||
|
||||
if [[ -n "$VIRTUAL_ENV" ]] then
|
||||
local venvname=${VIRTUAL_ENV:t}
|
||||
if [[ $venvname == "venv" ]]; then
|
||||
venvname=${VIRTUAL_ENV:h:t}/${VIRTUAL_ENV:t}
|
||||
fi
|
||||
infoline+=( "${usercolor}${PVPREFIX}venv: ${venvname}${PVSUFFIX}${rpscolor}" )
|
||||
fi
|
||||
[[ -n "$CONDA_DEFAULT_ENV" ]] && infoline+=( "${usercolor}${PVPREFIX}conda: ${CONDA_DEFAULT_ENV}${PVSUFFIX}${rpscolor}" )
|
||||
|
||||
# Username & host
|
||||
infoline+=( "%(1j.${PVPREFIX} ${gitdirty}Jobs: %j${rpscolor} ${PVSUFFIX}.)" )
|
||||
infoline+=( "${PVPREFIX} ${usercolor}%n${reset}@${hostcolor}%m${rpscolor} ${PVSUFFIX}" )
|
||||
|
||||
i_width=${(S)infoline//\%\{*\%\}} # search-and-replace color escapes
|
||||
i_width=${(%)i_width} # expand all escapes and count the chars
|
||||
i_width=${#i_width} # expand all escapes and count the chars
|
||||
((i_width += 2)) # workaround off by one, unknown reason
|
||||
|
||||
if [[ "$PROMPT_UNICODE" = "yes" ]]; then
|
||||
filler="${rpscolor}${(l:$(( $COLUMNS - $i_width + 2))::─:)}"
|
||||
else
|
||||
filler="${rpscolor}${(l:$(( $COLUMNS - $i_width + 2))::-:)}"
|
||||
fi
|
||||
infoline[3]=( "${infoline[3]}${PR_HBAR}${filler}${PR_HBAR}" )
|
||||
infoline+=( "${rpscolor}${CORNER_RU}" )
|
||||
|
||||
#middle info line
|
||||
|
||||
middleline+=( "${rpscolor}${PR_VBAR} ")
|
||||
|
||||
if mod_loaded vcs && [[ -n ${vcs_info_msg_0_} ]]; then
|
||||
middleline+=( "$(vcs_char) ${vcs_info_msg_0_}${reset}" )
|
||||
fi
|
||||
|
||||
if mod_loaded project && [[ -n $ZPROJECT ]]; then
|
||||
middleline+=( "${pathcolor}❰${ZPROJECT[name]}❱${reset}" )
|
||||
fi
|
||||
|
||||
i_width=${(S)middleline//\%\{*\%\}} # search-and-replace color escapes
|
||||
i_width=${#${(%)i_width}} # expand all escapes and count the chars
|
||||
filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 2)):: :)}${reset}"
|
||||
|
||||
### Now, assemble all prompt lines
|
||||
lines+=( ${(j::)infoline} )
|
||||
|
||||
|
||||
[[ $#middleline > 1 ]] && lines+=( "${middleline}${filler}${rpscolor}${PR_VBAR}" )
|
||||
lines+=( "${CORNER_LD}${PVPREFIX} %(1j.${rpscolor}%j${reset} .)${usercolor}%#${reset} " )
|
||||
|
||||
### Finally, set the prompt
|
||||
PROMPT=${(F)lines}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/zsh
|
||||
if command -v todo >/dev/null; then
|
||||
todo_count() {
|
||||
if [ -n "$2" ]; then
|
||||
file="--database $2"
|
||||
else
|
||||
file="-G"
|
||||
fi
|
||||
todo ${=file} -f +${1:-high} | wc -l
|
||||
}
|
||||
chpwd_hook todo
|
||||
else
|
||||
todo_count() {
|
||||
echo -1
|
||||
}
|
||||
fi
|
131
modules/vcs/init
131
modules/vcs/init
|
@ -1,131 +0,0 @@
|
|||
#!/bin/zsh
|
||||
# vcs-info config
|
||||
#
|
||||
# Partly based on Seth House's zsh promp
|
||||
|
||||
|
||||
autoload -Uz vcs_info
|
||||
|
||||
# Set up VCS_INFO
|
||||
zstyle ':vcs_info:*' enable git hg svn
|
||||
zstyle ':vcs_info:(hg*|git*):*' get-revision true
|
||||
zstyle ':vcs_info:(hg*|git*):*' check-for-changes true
|
||||
|
||||
zstyle ':vcs_info:hg*' formats "(%s)[%i%u %b %m]" # rev+changes branch misc
|
||||
zstyle ':vcs_info:hg*' actionformats "(%s|${white}%a${rpscolor})[%i%u %b %m]"
|
||||
|
||||
zstyle ':vcs_info:hg*:netbeans' use-simple true
|
||||
zstyle ':vcs_info:hg*:*' get-bookmarks true
|
||||
zstyle ':vcs_info:hg*:*' get-mq true
|
||||
|
||||
zstyle ':vcs_info:hg*:*' get-unapplied true
|
||||
zstyle ':vcs_info:hg*:*' patch-format "mq(%g):%n/%c %p"
|
||||
zstyle ':vcs_info:hg*:*' nopatch-format "mq(%g):%n/%c %p"
|
||||
|
||||
zstyle ':vcs_info:hg*:*' hgrevformat "%r" # only show local rev.
|
||||
zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch
|
||||
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b$vcs_revision:%f%r%f"
|
||||
|
||||
if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] {
|
||||
zstyle ':vcs_info:git*' formats "(%s) %12.12i %c%u %b%m" # hash changes branch misc
|
||||
zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m"
|
||||
} else {
|
||||
zstyle ':vcs_info:git*' formats "(%s) %12.12i %c%u${gituntracked} %b%m" # hash changes branch misc
|
||||
zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m"
|
||||
}
|
||||
|
||||
|
||||
zstyle ':vcs_info:*' stagedstr "$gitstaged●$rpscolor"
|
||||
zstyle ':vcs_info:*' unstagedstr "$gitdirty●$rpscolor"
|
||||
|
||||
# zstyle ':vcs_info:hg:*:-all-' command fakehg
|
||||
# zstyle ':vcs_info:*+*:*' debug true
|
||||
|
||||
zstyle ':vcs_info:hg*+set-hgrev-format:*' hooks hg-hashfallback
|
||||
zstyle ':vcs_info:hg*+set-message:*' hooks mq-vcs
|
||||
zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash
|
||||
zstyle ':vcs_info:*+pre-get-data:*' hooks vcs-detect
|
||||
|
||||
disable_pattern=()
|
||||
for i in $MPATH/filter/*(N); do
|
||||
filter="$(readlink -f $i)(|/*)"
|
||||
disable_pattern=("${disable_pattern[@]}" "$filter");
|
||||
done
|
||||
zstyle ':vcs_info:*' disable-patterns "${disable_pattern[@]}"
|
||||
|
||||
+vi-vcs-detect() {
|
||||
export VCS_DETECTED=$vcs
|
||||
}
|
||||
|
||||
vcs_char() {
|
||||
case $VCS_DETECTED in
|
||||
git) echo '±';;
|
||||
hg) echo '☿';;
|
||||
svn) echo '☣';;
|
||||
*) echo '#';;
|
||||
esac
|
||||
}
|
||||
|
||||
exitstatus () {
|
||||
local exitstatus=$?
|
||||
|
||||
if [ $exitstatus -ne 0 ] ; then
|
||||
if [ $exitstatus -gt 128 -a $exitstatus -lt 163 ] ; then
|
||||
echo "${SIG_PROMPT_PREFIX}SIG$signals[$exitstatus-127]${SIG_PROMPT_SUFFIX}"
|
||||
else
|
||||
echo "${SIG_PROMPT_PREFIX}${exitstatus}${SIG_PROMPT_SUFFIX}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
### Dynamically set hgrevformat based on if the local rev is available
|
||||
# We don't always know the local revision, e.g. if use-simple is set
|
||||
# Truncate long hash to 12-chars but also allow for multiple parents
|
||||
function +vi-hg-hashfallback() {
|
||||
if [[ -z ${hook_com[localrev]} ]] ; then
|
||||
local -a parents
|
||||
|
||||
parents=( ${(s:+:)hook_com[hash]} )
|
||||
parents=( ${(@r:12:)parents} )
|
||||
hook_com[rev-replace]="${(j:+:)parents}"
|
||||
|
||||
ret=1
|
||||
fi
|
||||
}
|
||||
|
||||
# Show remote ref name and number of commits ahead-of or behind
|
||||
function +vi-git-st() {
|
||||
local ahead behind remote
|
||||
local -a gitstatus
|
||||
|
||||
# Are we on a remote-tracking branch?
|
||||
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
|
||||
--symbolic-full-name --abbrev-ref 2>/dev/null)}
|
||||
|
||||
if [[ -n ${remote} ]] ; then
|
||||
# for git prior to 1.7
|
||||
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
|
||||
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
|
||||
(( $ahead )) && gitstatus+=( "${gitstaged}+${ahead}${rpscolor}" )
|
||||
|
||||
# for git prior to 1.7
|
||||
# behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
|
||||
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
|
||||
(( $behind )) && gitstatus+=( "${gitdirty}-${behind}${rpscolor}" )
|
||||
|
||||
hook_com[branch]="${hook_com[branch]} [ ${remote}${gitstatus:+ }${gitstatus} ]"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Show count of stashed changes
|
||||
function +vi-git-stash() {
|
||||
local -a stashes
|
||||
|
||||
if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
|
||||
stashes=$(git stash list 2>/dev/null | wc -l)
|
||||
hook_com[misc]+=" (${stashes} stashed)"
|
||||
fi
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
. /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
|
||||
|
||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
|
||||
|
||||
if [[ "`tput colors`" == "256" ]] || [[ "`tput colors`" == "88" ]] ; then
|
10
zplug.zsh
10
zplug.zsh
|
@ -1,7 +1,13 @@
|
|||
source $(zdotfile zplug/init.zsh)
|
||||
|
||||
zplug "MichaelAquilina/zsh-you-should-use"
|
||||
zplug 'jreese/zsh-titles'
|
||||
|
||||
zplug 'crater2150-zsh/fzf-widgets'
|
||||
zplug 'crater2150-zsh/conf'
|
||||
zplug 'crater2150-zsh/chroma-z', as:theme
|
||||
|
||||
zplug $ZDOTDIR/plugins/autoloader, from:local
|
||||
|
||||
zplug 'molovo/revolver', \
|
||||
as:command, \
|
||||
|
@ -11,8 +17,10 @@ zplug 'zunit-zsh/zunit', \
|
|||
use:zunit, \
|
||||
hook-build:'./build.zsh'
|
||||
|
||||
zplug load
|
||||
zplug "zsh-users/zsh-syntax-highlighting", defer:2
|
||||
zplug $ZDOTDIR/plugins/highlight-config, from:local, defer:3
|
||||
|
||||
zplug load
|
||||
|
||||
if zplug check 'crater2150-zsh/fzf-widgets'; then
|
||||
# Map widgets to key
|
||||
|
|
2
zshenv
2
zshenv
|
@ -1,4 +1,4 @@
|
|||
export ZDOTDIR=${XDG_CONFIG_HOME:-$HOME/.config}/zsh
|
||||
export ZDOTDIR="${$(readlink $HOME/.zshenv):h:a}"
|
||||
|
||||
for i in $ZDOTDIR/env/*.zsh; do
|
||||
. $i
|
||||
|
|
17
zshrc
17
zshrc
|
@ -31,30 +31,25 @@ try-source() {
|
|||
fi
|
||||
done
|
||||
}
|
||||
exists() { command -v "$@" >/dev/null }
|
||||
|
||||
local dirfile=$(zdotfile dirs)
|
||||
try-source $dirfile
|
||||
|
||||
. $(zdotfile completion.zsh)
|
||||
|
||||
source $(zdotfile zplug.zsh)
|
||||
|
||||
bindkey -v
|
||||
|
||||
function exists { command -v "$@" >/dev/null }
|
||||
ZMODLOAD_BLACKLIST=( ssh-agent )
|
||||
. $(zdotfile bindings.zsh)
|
||||
|
||||
stty -ixon
|
||||
|
||||
. $(zdotfile modules/loader.zsh) && mod_init
|
||||
|
||||
for i in ${ZDOTDIR:+$ZDOTDIR/aliases/*~*.zwc(N)} /etc/zsh/aliases/*~*.zwc(N); do
|
||||
. $i
|
||||
done
|
||||
|
||||
echo $PATH | grep -q 'local' || . /etc/zsh/zprofile
|
||||
echo $PATH | grep -q 'sbin' || . /etc/zsh/zprofile
|
||||
|
||||
if ! (grep -q 'local' <<<$PATH && grep -q 'sbin' <<<$PATH); then
|
||||
. /etc/zsh/zprofile
|
||||
fi
|
||||
|
||||
FZF_ALT_C_COMMAND="fd -t d"
|
||||
|
||||
exists todo && todo
|
||||
|
|
Loading…
Reference in a new issue