diff --git a/zlogin b/zlogin deleted file mode 100644 index 53049eac..00000000 --- a/zlogin +++ /dev/null @@ -1,10 +0,0 @@ -# Executes commands at login post-zshrc. - -# Execute code that does not affect the current session in the background. -{ - # Compile the completion dump to increase startup speed. - zcompdump="${ZDOTDIR:-$HOME}/.zcompdump" - if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then - zcompile "$zcompdump" - fi -} &! diff --git a/zsh/aliases b/zsh/aliases new file mode 100644 index 00000000..b6501817 --- /dev/null +++ b/zsh/aliases @@ -0,0 +1,28 @@ +load aliases + +alias ?='since @$last' + +# Fast directory navigation +if is-callable 'fasd' && is-callable 'fzf'; then + + # TODO Jump to folder in project + alias ,='fzf -d "$(project-root)"' + alias /='fzf -f "$(project-root)"' + + # alias v='vim' + + # -() { + # local d; d=$(echo ${dirstack:gs/ /\\n/} | fzf-tmux +s -e -1 --query="$*") && cd - + # } +fi +# see functions/commacd +# alias ,,,='cd ${$(find ~/Dropbox/work -maxdepth 2 -type d | fzf):-.}' +# alias ,-='[[ -n "$dirstack" ]] && cd $(echo "${dirstack:gs/ /\\n/}" | fzf) || echo "Nothing in the stack"' +# alias ,/='fzf_project_root' + +zman() { PAGER="less -g -s '+/^ "$1"'" man zshall; } + +# Compilers, interpretors 'n builders +alias rk="noglob ${aliases[rk]:-rake}" +alias rkg="noglob ${aliases[rkg]:-rake -g}" + diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh deleted file mode 100644 index 64b71f3b..00000000 --- a/zsh/aliases.zsh +++ /dev/null @@ -1,183 +0,0 @@ -alias q=exit -alias clr=clear -alias sudo='sudo ' - -alias ..="cd .." -alias ...="cd ../.." -alias ....="cd ../../.." -alias -- -='cd -' - -# Tools -alias ag='nocorrect noglob ag' -alias l="ls -l" -alias ll="ls -1" -alias la="ls -la" -alias ln="ln -v" # Verbose ln -alias wget='wget -c' # Resume dl if possible -alias rsyncd='rsync -va --delete' # Hard sync two directories -alias mkdir='mkdir -p' -alias gurl='curl --compressed' -zman() { PAGER="less -g -s '+/^ "$1"'" man zshall; } -take() { mkdir "$1" && cd "$1"; } -compdef take=mkdir - -alias ip="dig +short myip.opendns.com @resolver1.opendns.com" -alias localip="ipconfig getifaddr en0" -alias ips="ifconfig -a | grep -o 'inet6\? \(\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\|[a-fA-F0-9:]\+\)' | sed -e 's/inet6* //'" - -# View HTTP traffic -alias sniff="sudo ngrep -d 'en0' -t '^(GET|POST) ' 'tcp and port 80'" -alias httpdump="sudo tcpdump -i en0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" -# URL-encode strings -alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' -# Make URL REQUEST shortcuts -for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do - alias "$method"="lwp-request -m '$method'" -done - -# find conflicted dropbox files -alias findc="find . -iname '*conflicted*' -type f" - -# Send to sprunge.us -alias bin="curl -s -F 'sprunge=<-' http://sprunge.us | head -n 1 | tr -d '\r\n ' | pbcopy" - -if is-callable 'bd'; then - alias b="bd" - alias bb='cd "$(git root)"' -fi -if is-callable 'fasd'; then - j() { - local fasd_ret="$(fasd -i -d "$@")" - [[ -d "$fasd_ret" ]] && cd "$fasd_ret" || print "$fasd_ret" - } -fi - -# transmission-remote -if is-callable 'transmission-remote'; then - alias bt='transmission-remote server' - alias bt-clear='bt -t all -r' - - # pretty print torrent list on remote server - btl() { - local results=`transmission-remote server -l | \ - awk 'NR > 1 { s = ""; for (i = 10; i <= NF; i++) s = s $i " "; print $9 " | " s }' | \ - sed '$d' | \ - perl -pe 's/\s\[[a-zA-Z0-9]+\]\s/ /g'` - - [ -z "$results" ] && echo "No torrents!" || echo "$results" - } -fi - -# Editors -alias emacs='emacs -nw' -is-callable 'nvim' && alias vim='nvim' -v() { vim ${@:-.}; } # Open in vim -e() { # Open in emacs (daemon) - if pgrep Emacs 2>&1 >/dev/null; then - emacsclient -n ${@:-.}; - else - /Applications/Emacs.app/Contents/MacOS/Emacs ${@:-.} & - fi -} -ee() { # emacs in project root - git root 2>/dev/null && e "$(git rev-parse --show-toplevel)" || e . -} -ediff() { - e --eval "(ediff-files \"$1\" \"$2\")" -} - -# Compilers, interpretors 'n builders -alias va='vagrant' -alias py='python' -alias pye='pyenv' -alias rb='ruby' -alias rbe='rbenv' -alias bu='bundle' -alias bue='bundle exec' -alias bui='bundle install -path vendor' -alias ans='ansible' -alias ansp='ansible-playbook' -alias fabg='noglob fab -f ~/.dotfiles/ansible/fabfile.py' -alias rk='noglob rake' -alias rkg='noglob rake -g' -alias m='make' -alias dk='docker' -alias exe='exercism' - -# GIT -is-callable 'hub' && alias git='hub' -g() { [ $# -eq 0 ] && git status --short || git $* } -compdef _git g=git - -alias gi='git init' -alias gs='git status' -alias gsu='git submodule' -alias gsq='git squash' -alias gco='git checkout' -alias gc='git commit' -alias gcm='noglob git commit -m' -alias gcma='noglob git commit --amend -m' -alias gd='git diff' -alias gp='git push' -alias gpb='git push origin' -alias gpt='git push --follow-tags' -alias gpl='git pull' -alias ga='git add' -alias gau='git add -u' -alias gb='git branch' -alias gbd='git branch -D' -alias gap='git add --patch' -alias gr='git reset HEAD' -alias gt='git tag' -alias gtd='git tag -d' -alias gt!='git tag -a' -alias gls='git ls-files' - -# Tmux -if is-callable 'tmux'; then - alias t='tmux' - alias ta='tmux attach' - - if [ -n $TMUX ]; then - # Detach all other clients to this session - alias takeover='tmux detach -a' - fi - - # Start new session or create a grouped session so I'm not simply watching - # the same session in both windows. - tdup() {tmux new-session -t $1} -fi - -if is-mac; then - alias ls="ls -G" - - alias c11='clang++ -std=c++11' - alias eclimd='/Applications/eclipse/eclimd' - - # Homebrew - alias br='brew' - alias bru='brew update && brew upgrade --all' - alias brc='brew cask' - alias codekit='open -a CodeKit' -elif is-cygwin; then - alias open='cygstart' - alias pbcopy='tee > /dev/clipboard' - alias pbpaste='cat /dev/clipboard' -else - alias open='xdg-open' - alias ls="ls --color=auto" - - if (( $+commands[xclip] )); then - alias pbcopy='xclip -selection clipboard -in' - alias pbpaste='xclip -selection clipboard -out' - elif (( $+commands[xsel] )); then - alias pbcopy='xsel --clipboard --input' - alias pbpaste='xsel --clipboard --output' - fi -fi -alias c='pbcopy' -alias p='pbpaste' - -# By default, open cwd -o() { open ${@:-.}; } -compdef o=open diff --git a/zsh/completion.zsh b/zsh/completion similarity index 94% rename from zsh/completion.zsh rename to zsh/completion index 37606d75..923e1014 100644 --- a/zsh/completion.zsh +++ b/zsh/completion @@ -1,6 +1,3 @@ -# Return if requirements are not found. -[[ "$TERM" == 'dumb' ]] && return 1 - ## Options setopt COMPLETE_IN_WORD # Complete from both ends of a word. setopt PATH_DIRS # Perform path search even on command names with slashes. @@ -16,7 +13,7 @@ unsetopt CASE_GLOB # Use caching to make completion for commands such as dpkg and apt usable. zstyle ':completion::complete:*' use-cache on -zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zgen/.zcompcache" +zstyle ':completion::complete:*' cache-path "${CACHE_DIR}/zcompcache" # Case-insensitive (all), partial-word, and then substring completion. zstyle ':completion:*' matcher-list '' \ @@ -54,6 +51,7 @@ zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters # Directories zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:*:cd:*' ignore-parents parent pwd zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories zstyle ':completion:*:*:cd:*:directory-stack' menu yes select zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand' @@ -117,3 +115,15 @@ zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hos zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*' + + +## Custom compdefs ####################### + +mycompdef() { is-callable "$1" && compdef ${@[2,-1]} } + +mycompdef fasd _fasd_zsh_word_complete_d z=fasd +mycompdef g _hub g=hub +mycompdef o o=open +mycompdef take take=mkdir +mycompdef t t=tmux + diff --git a/zsh/completion/_tmuxinator b/zsh/completion/_tmuxinator deleted file mode 100755 index 4c76c94a..00000000 --- a/zsh/completion/_tmuxinator +++ /dev/null @@ -1,30 +0,0 @@ -#compdef tmuxinator mux - -_tmuxinator() { - local commands projects - commands=(${(f)"$(tmuxinator commands zsh)"}) - projects=(${(f)"$(tmuxinator completions start)"}) - - if (( CURRENT == 2 )); then - _describe -t commands "tmuxinator subcommands" commands - _describe -t projects "tmuxinator projects" projects - elif (( CURRENT == 3)); then - case $words[2] in - copy|debug|delete|open|start) - _arguments '*:projects:($projects)' - ;; - esac - fi - - return -} - -_tmuxinator - -# Local Variables: -# mode: Shell-Script -# sh-indentation: 2 -# indent-tabs-mode: nil -# sh-basic-offset: 2 -# End: -# vim: ft=zsh sw=2 ts=2 et diff --git a/zsh/config.zsh b/zsh/config similarity index 97% rename from zsh/config.zsh rename to zsh/config index 012d1b2b..b95dab74 100644 --- a/zsh/config.zsh +++ b/zsh/config @@ -1,5 +1,4 @@ autoload -U zmv -autoload -U colors && colors # # General @@ -38,7 +37,7 @@ setopt HASH_LIST_ALL # History # -HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" +HISTFILE="${CACHE_DIR}/zhistory" HISTSIZE=10000 # Max events to store in internal history. SAVEHIST=10000 # Max events to store in history file. diff --git a/zsh/completion/_lsarchive b/zsh/functions/_lsarchive similarity index 100% rename from zsh/completion/_lsarchive rename to zsh/functions/_lsarchive diff --git a/zsh/completion/_unarchive b/zsh/functions/_unarchive similarity index 100% rename from zsh/completion/_unarchive rename to zsh/functions/_unarchive diff --git a/zsh/functions/cache b/zsh/functions/cache deleted file mode 100755 index fe2fec50..00000000 --- a/zsh/functions/cache +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env zsh - -[[ -z "$ZSH_CACHE_DIR" ]] && exit 1 - -[[ ! -d "$ZSH_CACHE_DIR" ]] && mkdir -p "$ZSH_CACHE_DIR" - -is-callable "$1" || return 1 -local cache="${ZSH_CACHE_DIR}/$1-cache" -if [[ ! -s "$cache" ]]; then - echo "Caching $1" - $@ >| "$cache" 2> /dev/null -fi -source $cache diff --git a/zsh/keybinds.zsh b/zsh/keybinds similarity index 65% rename from zsh/keybinds.zsh rename to zsh/keybinds index 00510dc8..f83385ef 100644 --- a/zsh/keybinds.zsh +++ b/zsh/keybinds @@ -1,18 +1,44 @@ bindkey -v +## vi-mode ############### +bindkey -M viins 'jk' vi-cmd-mode +# bindkey -M viins '^I' expand-or-complete-prefix + +# surround +autoload -Uz surround +zle -N delete-surround surround +zle -N add-surround surround +zle -N change-surround surround +bindkey -a cs change-surround +bindkey -a ds delete-surround +bindkey -a ys add-surround +bindkey -M visual S add-surround + +# text-objects +autoload -U select-quoted; zle -N select-quoted +for m in visual viopp; do + for c in {a,i}{\',\",\`}; do + bindkey -M $m $c select-quoted + done +done +autoload -U select-bracketed; zle -N select-bracketed +for m in visual viopp; do + for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do + bindkey -M $m $c select-bracketed + done +done + # Allow command line editing in an external editor. -autoload -Uz edit-command-line -zle -N edit-command-line +autoload -Uz edit-command-line; zle -N edit-command-line bindkey '^ ' edit-command-line bindkey -M viins '^n' history-substring-search-down bindkey -M viins '^p' history-substring-search-up bindkey -M viins '^s' history-incremental-pattern-search-backward bindkey -M viins '^u' backward-kill-line -bindkey -M viins '^r' redo bindkey -M viins '^w' backward-kill-word bindkey -M viins '^b' backward-word -bindkey -M viins '^q' push-line-or-edit +bindkey -M viins '^g' push-line-or-edit bindkey -M viins '^a' beginning-of-line bindkey -M viins '^e' end-of-line @@ -20,22 +46,17 @@ bindkey -M viins '^e' end-of-line bindkey -M viins '^[[Z' reverse-menu-complete bindkey -M viins ' ' magic-space -bindkey -M viins 'jk' vi-cmd-mode # Vim keymaps bindkey -M vicmd 'ga' what-cursor-position -bindkey -M vicmd 'gg' beginning-of-history -bindkey -M vicmd 'G ' end-of-history bindkey -M vicmd '^k' kill-line bindkey -M vicmd '?' history-incremental-pattern-search-forward bindkey -M vicmd '/' history-incremental-pattern-search-backward bindkey -M vicmd ':' execute-named-cmd # Page up / Page down bindkey -M vicmd 'H' run-help -bindkey -M vicmd 'u' undo -bindkey -M vicmd 'U' redo -bindkey -M vicmd 'yy' vi-yank-whole-line -bindkey -M vicmd 'Y' vi-yank-eol + +bindkey -s -M vicmd ',o' "tmux resize-pane -Z\n" # bind UP and DOWN arrow keys bindkey '^[[A' history-substring-search-up @@ -54,7 +75,7 @@ fancy-ctrl-z () { zle -N fancy-ctrl-z bindkey '^Z' fancy-ctrl-z -# Completion +# Omni-Completion bindkey -M viins '^x^f' fasd-complete-f # C-x C-f to do fasd-complete-f (only files) bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories) # Completing words in buffer in tmux @@ -101,3 +122,19 @@ bindkey -rM viins '^X' bindkey -M viins '^X,' _history-complete-newer \ '^X/' _history-complete-older \ '^X`' _bash_complete-word + +# In-place search insertion +autoload -Uz narrow-to-region +function _history-incremental-preserving-pattern-search-backward +{ + local state + MARK=CURSOR # magick, else multiple ^R don't work + narrow-to-region -p "$LBUFFER${BUFFER:+>>}" -P "${BUFFER:+<<}$RBUFFER" -S state + zle end-of-history + zle history-incremental-pattern-search-backward + narrow-to-region -R state +} +zle -N _history-incremental-preserving-pattern-search-backward +bindkey "^R" _history-incremental-preserving-pattern-search-backward +bindkey -M isearch "^R" history-incremental-pattern-search-backward +bindkey "^S" history-incremental-pattern-search-forward diff --git a/zsh/prompt b/zsh/prompt new file mode 100644 index 00000000..479d1ba1 --- /dev/null +++ b/zsh/prompt @@ -0,0 +1,102 @@ +# Based off Pure + +_strlen() { echo ${#${(S%%)1//$~%([BSUbfksu]|([FB]|){*})/}}; } + +# fastest possible way to check if repo is dirty +prompt_git_dirty() { + # disable auth prompting on git 2.3+ + GIT_TERMINAL_PROMPT=0 + + # check if we're in a git repo + [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || return + # check if it's dirty + command test -n "$(git status --porcelain --ignore-submodules -unormal)" || return + + echo -n "%F{red}[+]" + local r=$(command git rev-list --right-only --count HEAD...@'{u}' 2>/dev/null) + local l=$(command git rev-list --left-only --count HEAD...@'{u}' 2>/dev/null) + + (( ${r:-0} > 0 )) && echo -n " %F{green}${r}⇣" + (( ${l:-0} > 0 )) && echo -n " %F{yellow}${l}⇡" + echo -n '%f' +} + +# displays the exec time of the last command if set threshold was exceeded +prompt_cmd_exec_time() { + local stop=$EPOCHSECONDS + local start=${cmd_timestamp:-$stop} + integer elapsed=$stop-$start + (($elapsed > 2)) && $DOTFILES/bin/since -- $elapsed +} + +## Hooks ############################### +prompt_hook_preexec() { + cmd_timestamp=$EPOCHSECONDS +} + +prompt_hook_precmd() { + LAST=$EPOCHSECONDS + print -Pn '\e]0;%~\a' # full path in the title + vcs_info # get git info + # Newline before prompt, excpet on init + [[ -n "$_DONE" ]] && print ""; _DONE=1 +} + +## Initialization ###################### +prompt_init() { + zmodload zsh/datetime + + # prevent percentage showing up + # if output doesn't end with a newline + export PROMPT_EOL_MARK='' + + prompt_opts=(cr subst percent) + + setopt PROMPTSUBST + autoload -Uz add-zsh-hook + autoload -Uz vcs_info + + add-zsh-hook precmd prompt_hook_precmd + add-zsh-hook preexec prompt_hook_preexec + # Updates cursor shape and prompt symbol based on vim mode + zle-keymap-select() { + case $KEYMAP in + vicmd) print -n -- "\E]50;CursorShape=0\C-G"; + PROMPT_SYMBOL=$N_MODE; + ;; # block cursor + main|viins) print -n -- "\E]50;CursorShape=1\C-G"; + PROMPT_SYMBOL=$I_MODE; + ;; # line cursor + esac + zle reset-prompt + zle -R + } + zle-line-finish() { print -n -- "\E]50;CursorShape=0\C-G" } + zle -N zle-keymap-select + zle -N zle-line-finish + zle -A zle-keymap-select zle-line-init + + zstyle ':vcs_info:*' enable git + zstyle ':vcs_info:*' use-simple true + zstyle ':vcs_info:*' max-exports 2 + zstyle ':vcs_info:git*' formats ':%b' + zstyle ':vcs_info:git*' actionformats ':%b (%a)' + + # show username@host if logged in through SSH OR logged in as root + is-ssh || is-root && prompt_username='%F{white}%n%F{244}@%m ' + + ## Vim cursors + N_MODE="%F{blue}## " + I_MODE=">> " + + RPROMPT='$prompt_username' # PWD + RPROMPT+='%F{cyan}${vcs_info_msg_0_}$(prompt_git_dirty)' # Branch + dirty indicator + RPROMPT+='%F{yellow}$(prompt_cmd_exec_time)' # Exec time + RPROMPT+='%f' # end + + PROMPT='%F{blue}%~ %f' # username + PROMPT+='%(?.%F{green}.%F{red})${PROMPT_SYMBOL:->>> }' # Prompt (red if $? == 0) + PROMPT+='%f' #end +} + +prompt_init "$@" diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh deleted file mode 100644 index 37328317..00000000 --- a/zsh/prompt.zsh +++ /dev/null @@ -1,129 +0,0 @@ -# Based off Pure - -# turns seconds into human readable time -# 165392 => 1d 21h 56m 32s -_human_time() { - echo -n " " - local tmp=$1 - local days=$(( tmp / 60 / 60 / 24 )) - local hours=$(( tmp / 60 / 60 % 24 )) - local minutes=$(( tmp / 60 % 60 )) - local seconds=$(( tmp % 60 )) - (( $days > 0 )) && echo -n "${days}d " - (( $hours > 0 )) && echo -n "${hours}h " - (( $minutes > 0 )) && echo -n "${minutes}m " - echo "${seconds}s" -} - -_strlen () { - FOO=$1 - local zero='%([BSUbfksu]|([FB]|){*})' - LEN=${#${(S%%)FOO//$~zero/}} - echo $LEN -} - -# fastest possible way to check if repo is dirty -prompt_git_dirty() { - # disable auth prompting on git 2.3+ - GIT_TERMINAL_PROMPT=0 - - # check if we're in a git repo - [[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || return - # check if it's dirty - command test -n "$(git status --porcelain --ignore-submodules -unormal)" || return - - echo -n "%F{red}[+]" - local r=$(command git rev-list --right-only --count HEAD...@'{u}' 2>/dev/null) - local l=$(command git rev-list --left-only --count HEAD...@'{u}' 2>/dev/null) - - (( ${r:-0} > 0 )) && echo -n " %F{green}${r}⇣" - (( ${l:-0} > 0 )) && echo -n " %F{yellow}${l}⇡" - echo -n '%f' -} - -# displays the exec time of the last command if set threshold was exceeded -prompt_cmd_exec_time() { - local stop=$EPOCHSECONDS - local start=${cmd_timestamp:-$stop} - integer elapsed=$stop-$start - (($elapsed > 2)) && _human_time $elapsed -} - -## Hooks ############################### -prompt_hook_preexec() { - cmd_timestamp=$EPOCHSECONDS -} - -prompt_hook_precmd() { - last_time=$EPOCHSECONDS - # shows the full path in the title - print -Pn '\e]0;%~\a' - # git info - vcs_info - # newline before prompt (except on first prompt) - [[ -n "$_DONE" ]] && print "" - _DONE=1 -} - -# Updates cursor shape and prompt symbol based on vim mode -prompt_hook_update_vim_mode() { - case $KEYMAP in - vicmd) print -n -- "\E]50;CursorShape=0\C-G"; - PROMPT_SYMBOL=$N_MODE; - ;; # block cursor - main|viins) print -n -- "\E]50;CursorShape=1\C-G"; - PROMPT_SYMBOL=$I_MODE; - ;; # line cursor - esac - zle reset-prompt - zle -R -} -prompt_hook_restore_cursor() { - print -n -- "\E]50;CursorShape=0\C-G" # block cursor -} - -## Initialization ###################### -prompt_init() { - # prevent percentage showing up - # if output doesn't end with a newline - export PROMPT_EOL_MARK='' - - prompt_opts=(cr subst percent) - - setopt PROMPTSUBST - zmodload zsh/datetime - autoload -Uz add-zsh-hook - autoload -Uz vcs_info - - add-zsh-hook precmd prompt_hook_precmd - add-zsh-hook preexec prompt_hook_preexec - - # Show $N-MODE if in normal mode and Change cursor depending on vim mode - hooks-add-hook zle_keymap_select_hook prompt_hook_update_vim_mode - hooks-add-hook zle_line_init_hook prompt_hook_update_vim_mode - hooks-add-hook zle_line_finish_hook prompt_hook_restore_cursor - - zstyle ':vcs_info:*' enable git - zstyle ':vcs_info:*' use-simple true - zstyle ':vcs_info:*' max-exports 2 - zstyle ':vcs_info:git*' formats ':%b' - zstyle ':vcs_info:git*' actionformats ':%b (%a)' - - # show username@host if logged in through SSH OR logged in as root - [[ "$SSH_CONNECTION" != '' || "$UID" -eq 0 ]] && prompt_username='%F{white}%n%F{244}@%m ' - - ## Vim cursors - N_MODE="%F{blue}## " - I_MODE=">> " - - RPROMPT='%F{blue}%~' # PWD - RPROMPT+='%F{242}${vcs_info_msg_0_}$(prompt_git_dirty)' # Branch + dirty indicator - RPROMPT+='%F{yellow}$(prompt_cmd_exec_time)' # Exec time - RPROMPT+='%f' # end - - PROMPT='$prompt_username' # username - PROMPT+='%(?.%F{yellow}.%F{red})${PROMPT_SYMBOL}' # Prompt (red if $? == 0) - PROMPT+='%f' #end -} - -prompt_init "$@" diff --git a/zshenv b/zshenv index 801f799d..2b507217 100644 --- a/zshenv +++ b/zshenv @@ -1,7 +1,4 @@ -is-callable() { (( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] )); } -is-mac() { [[ "$OSTYPE" == "darwin"* ]]; } -is-deb() { [[ "$OSTYPE" == "linux-gnu" ]]; } -is-cygwin() { [[ "$OSTYPE" == "cygwin"* ]]; } +source $HOME/.dotfiles/.common.sh ## Paths # Ensure path arrays do not contain duplicates. @@ -9,7 +6,6 @@ typeset -gU cdpath fpath mailpath path ## export DOCKER_HOST=tcp://server:4243 - export RUST_SRC_PATH=$HOME/Dropbox/lib/rust/src export GOPATH=$HOME/Dropbox/work/go export ANDROID_HOME=/usr/local/opt/android-sdk @@ -17,7 +13,7 @@ export ANDROID_SDK=/usr/local/Cellar/android-sdk/24.2 # Set the list of directories that Zsh searches for programs. path=( - $HOME/.dotfiles/{bin,scripts} + $DOTFILES/{bin,scripts} $HOME/.{rb,py}env/bin $GOPATH/bin $ANDROID_HOME/platform-tools @@ -29,18 +25,13 @@ path=( $path ) -local FUNC_DIR="$HOME/.dotfiles/zsh/functions" +local FUNC_DIR="$DOTFILES/zsh/functions" fpath=( ~/.zsh/completion "$FUNC_DIR" $fpath ) -# Load all scripts from ./zsh/functions/* -for func in "$FUNC_DIR"/*(N-.x:t); do - autoload -Uz $func -done - # Browser export BROWSER='open' @@ -57,12 +48,7 @@ export CPLUS_INCLUDE_PATH="/usr/local/include" export LIBRARY_PATH="/usr/local/lib" # export LDFLAGS="-L/usr/local/lib" -# Set the default Less options. -# 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. -export LESS='-X -F -g -i -M -R -S -w -z-4' - -# Set the Less input preprocessor. +export LESS='-F -g -i -M -R -S -w -z-4' if (( $+commands[lesspipe] )); then export LESSOPEN='| /usr/bin/env lesspipe %s 2>&-' fi @@ -76,6 +62,6 @@ fi TMPPREFIX="${TMPDIR%/}/zsh" [[ ! -d "$TMPPREFIX" ]] && mkdir -p "$TMPPREFIX" -## Language [[ -z "$LANG" ]] && export LANG='en_US.UTF-8' +autoload -U colors && colors diff --git a/zshrc b/zshrc index 4e4ed636..6ccc9808 100644 --- a/zshrc +++ b/zshrc @@ -1,37 +1,43 @@ ### zshrc # By Henrik Lissner -# Uses zgen to manage plugins -DOTFILES=$HOME/.dotfiles +############################################ + +# Light mode are for remote shells or computers where I don't have much access, and +# therefore cannot install most of my zsh plugins (though can somehow get away with using +# zsh itself). + +LIGHTMODE= + +############################################ -ZSH_CACHE_DIR="$HOME/.zsh/cache/$(hostname)" ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) +ZSH_PLUGINS_ALIAS_TIPS_EXPAND=1 +ZGEN_AUTOLOAD_COMPINIT=true +[[ "${USER}" == "root" ]] && ZGEN_AUTOLOAD_COMPINIT=false -# if not running through emacs' shell-command -if [ ! $TERM = dumb ]; then - ZGEN_AUTOLOAD_COMPINIT=true - [[ "${USER}" == "root" ]] && ZGEN_AUTOLOAD_COMPINIT=false +load zsh/zgen/zgen.zsh +if ! zgen saved; then + echo "Creating zgen save" + [[ -d "$CACHE_DIR" ]] && rm -f "$CACHE_DIR/*" - source ~/.zsh/zgen/zgen.zsh - if ! zgen saved; then - echo "Creating zgen save" + zgen load StackExchange/blackbox + zgen load thewtex/tmux-mem-cpu-load + zgen load djui/alias-tips + zgen load joepvd/zsh-hints + zgen load unixorn/git-extra-commands - zgen load zsh-users/zsh-history-substring-search - zgen load willghatch/zsh-hooks - zgen load hlissner/zsh-autopair - zgen load StackExchange/blackbox - [[ "$SSH_CONNECTION" == '' ]] && zgen load zsh-users/zsh-syntax-highlighting + zgen load hlissner/zsh-autopair "autopair.zsh" + zgen load zsh-users/zsh-history-substring-search + is-ssh || zgen load zsh-users/zsh-syntax-highlighting + zgen load zsh-users/zsh-completions src - zgen load zsh-users/zsh-completions src - - zgen load "$DOTFILES/zsh/config.zsh" - zgen load "$DOTFILES/zsh/completion.zsh" - zgen load "$DOTFILES/zsh/keybinds.zsh" - zgen load "$DOTFILES/zsh/prompt.zsh" - - zgen save - fi + zgen save +fi +cache rbenv init - --no-rehash +cache pyenv init - --no-rehash +if is-interactive; then cache fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install export FZF_DEFAULT_COMMAND='ag -g ""' @@ -39,9 +45,10 @@ if [ ! $TERM = dumb ]; then [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh fi -source "$DOTFILES/zsh/aliases.zsh" - -cache rbenv init - --no-rehash -cache pyenv init - --no-rehash +load zsh/config +iload zsh/keybinds +iload zsh/prompt +load zsh/aliases +iload zsh/completion # Done!