changed folder layout

This commit is contained in:
Nikolas Weger 2017-08-23 11:43:12 +02:00
parent fd30095cd0
commit b5f657b8a4
9 changed files with 37 additions and 397 deletions

View file

@ -1,25 +1,26 @@
# For Dotfiles # For Dotfiles
export DOTFLS="${HOME}/dotfiles" dotfls="${HOME}/dotfiles"
export DOTLIB="${DOTFLS}/lib" dotlib="${dotfls}/lib"
export DOTBIN="${DOTFLS}/bin" dotcfg="${dotfls}/cfg"
export DOTCFG="${DOTFLS}/cfg"
export DOTCFGD="${DOTCFG}/zsh/cfg.d"
# Path # Paths
path+=(${DOTBIN}) path+=(${dotfls}/bin)
path+=(/opt/android-sdk/build-tools/26.0.1)
path+=(${HOME}/.gem/ruby/2.4.0/bin) path+=(${HOME}/.gem/ruby/2.4.0/bin)
path+=(${DOTLIB}/welder/bin) path+=(${HOME}/basher/bin)
path+=(${DOTLIB}/basher/bin) path+=(/opt/android-sdk/build-tools/26.0.1)
path+=(/home/linuxbrew/.linuxbrew/bin) path+=(/home/linuxbrew/.linuxbrew/bin)
export PATH manpath+=(/home/linuxbrew/.linuxbrew/share/man)
infopath+=(/home/linuxbrew/.linuxbrew/share/info)
# Editor Setting # Editor Setting
export EDITOR='nano' EDITOR='nano'
# Completions Paths # Completions Paths
fpath+=(${DOTLIB}/completions/src) fpath+=(${dotlib}/completions/src)
fpath+=(${DOTLIB}/local) fpath+=(${dotlib}/local)
# Actually export
export dotlib dotcfg PATH MANPATH INFOPATH EDITOR
# Reload all Prompts # Reload all Prompts
autoload -U promptinit && promptinit autoload -U promptinit && promptinit

View file

@ -1,3 +1,3 @@
export ZSH="${DOTLIB}/ohmyzsh" export ZSH="${dotlib}/ohmyzsh"
DISABLE_AUTO_UPDATE="true" DISABLE_AUTO_UPDATE="true"
source ${ZSH}/oh-my-zsh.sh source ${ZSH}/oh-my-zsh.sh

View file

@ -1,64 +1,22 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
# Copyright (c) 2017 Sebastian Gniazdowski (modifications)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# Set $ZERO to the expected value, regardless of functionargzero.
typeset -g ZERO=${(%):-%N} typeset -g ZERO=${(%):-%N}
# Invokes each highlighter that needs updating.
# This function is supposed to be called whenever the ZLE state changes.
_zsh_highlight() _zsh_highlight()
{ {
# Store the previous command return code to restore it whatever happens.
local ret=$? local ret=$?
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then
region_highlight=() region_highlight=()
return $ret return $ret
fi fi
setopt localoptions warncreateglobal noksharrays setopt localoptions warncreateglobal noksharrays
local REPLY # don't leak $REPLY into global scope local REPLY
local -a reply local -a reply
# Do not highlight if there are more than 300 chars in the buffer. It's most
# likely a pasted command or a huge list of files in that case..
[[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
# Do not highlight if there are pending inputs (copy/paste).
[[ $PENDING -gt 0 ]] && return $ret [[ $PENDING -gt 0 ]] && return $ret
# Reset region highlight to build it from scratch
# may need to remove path_prefix highlighting when the line ends
if [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified; then if [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified; then
-fast-highlight-init -fast-highlight-init
-fast-highlight-process && region_highlight=( $reply ) || region_highlight=() -fast-highlight-process && region_highlight=( $reply ) || region_highlight=()
@ -68,9 +26,6 @@ _zsh_highlight()
local cache_place local cache_place
local -a region_highlight_copy local -a region_highlight_copy
# Re-apply zle_highlight settings
# region
if (( REGION_ACTIVE == 1 )); then if (( REGION_ACTIVE == 1 )); then
_zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR" _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR"
elif (( REGION_ACTIVE == 2 )); then elif (( REGION_ACTIVE == 2 )); then
@ -88,13 +43,10 @@ _zsh_highlight()
} }
fi fi
# yank / paste (zsh-5.1.1 and newer)
(( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
# isearch
(( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END" (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
# suffix
(( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END" (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
return $ret return $ret
@ -106,28 +58,17 @@ _zsh_highlight()
} }
} }
# Apply highlighting based on entries in the zle_highlight array.
# This function takes four arguments:
# 1. The exact entry (no patterns) in the zle_highlight array:
# region, paste, isearch, or suffix
# 2. The default highlighting that should be applied if the entry is unset
# 3. and 4. Two integer values describing the beginning and end of the
# range. The order does not matter.
_zsh_highlight_apply_zle_highlight() { _zsh_highlight_apply_zle_highlight() {
local entry="$1" default="$2" local entry="$1" default="$2"
integer first="$3" second="$4" integer first="$3" second="$4"
# read the relevant entry from zle_highlight
local region="${zle_highlight[(r)${entry}:*]}" local region="${zle_highlight[(r)${entry}:*]}"
if [[ -z "$region" ]]; then if [[ -z "$region" ]]; then
# entry not specified at all, use default value
region=$default region=$default
else else
# strip prefix
region="${region#${entry}:}" region="${region#${entry}:}"
# no highlighting when set to the empty string or to 'none'
if [[ -z "$region" ]] || [[ "$region" == none ]]; then if [[ -z "$region" ]] || [[ "$region" == none ]]; then
return return
fi fi
@ -143,114 +84,72 @@ _zsh_highlight_apply_zle_highlight() {
} }
# -------------------------------------------------------------------------------------------------
# API/utility functions for highlighters
# -------------------------------------------------------------------------------------------------
# Whether the command line buffer has been modified or not.
#
# Returns 0 if the buffer has changed since _zsh_highlight was last called.
_zsh_highlight_buffer_modified() _zsh_highlight_buffer_modified()
{ {
[[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] } [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] }
} }
# Whether the cursor has moved or not.
#
# Returns 0 if the cursor has moved since _zsh_highlight was last called.
_zsh_highlight_cursor_moved() _zsh_highlight_cursor_moved()
{ {
[[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR)) [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR))
} }
# -------------------------------------------------------------------------------------------------
# Setup functions
# -------------------------------------------------------------------------------------------------
# Helper for _zsh_highlight_bind_widgets
# $1 is name of widget to call
_zsh_highlight_call_widget() _zsh_highlight_call_widget()
{ {
builtin zle "$@" && _zsh_highlight builtin zle "$@" && _zsh_highlight
} }
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
_zsh_highlight_bind_widgets() _zsh_highlight_bind_widgets()
{ {
setopt localoptions noksharrays setopt localoptions noksharrays
typeset -F SECONDS typeset -F SECONDS
local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once local prefix=orig-s$SECONDS-r$RANDOM
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
zmodload zsh/zleparameter 2>/dev/null || { zmodload zsh/zleparameter 2>/dev/null || {
print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.'
return 1 return 1
} }
# Override ZLE widgets to make them invoke _zsh_highlight.
local -U widgets_to_bind local -U widgets_to_bind
widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank)}) widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank)})
# Always wrap special zle-line-finish widget. This is needed to decide if the
# current line ends and special highlighting logic needs to be applied.
# E.g. remove cursor imprint, don't highlight partial paths, ...
widgets_to_bind+=(zle-line-finish) widgets_to_bind+=(zle-line-finish)
# Always wrap special zle-isearch-update widget to be notified of updates in isearch.
# This is needed because we need to disable highlighting in that case.
widgets_to_bind+=(zle-isearch-update) widgets_to_bind+=(zle-isearch-update)
local cur_widget local cur_widget
for cur_widget in $widgets_to_bind; do for cur_widget in $widgets_to_bind; do
case $widgets[$cur_widget] in case $widgets[$cur_widget] in
# Already rebound event: do nothing.
user:_zsh_highlight_widget_*);; user:_zsh_highlight_widget_*);;
# The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function
# definition time is used.
#
# We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with
# NO_function_argzero, regardless of the option's setting here.
# User defined widget: override and rebind old one with prefix "orig-".
user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:}
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Completion widget: override and rebind old one with prefix "orig-".
completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]}
eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Builtin widget: override and make it call the builtin ".widget".
builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }"
zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
# Incomplete or nonexistent widget: Bind to z-sy-h directly.
*) *)
if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then
_zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight }
zle -N $cur_widget _zsh_highlight_widget_$cur_widget zle -N $cur_widget _zsh_highlight_widget_$cur_widget
else else
# Default: unhandled case.
print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}"
fi fi
esac esac
done done
} }
# -------------------------------------------------------------------------------------------------
# Setup
# -------------------------------------------------------------------------------------------------
# Try binding widgets.
_zsh_highlight_bind_widgets || { _zsh_highlight_bind_widgets || {
print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'
return 1 return 1
} }
# Reset scratch variables when commandline is done.
_zsh_highlight_preexec_hook() _zsh_highlight_preexec_hook()
{ {
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
@ -264,11 +163,10 @@ add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
ZSH_HIGHLIGHT_MAXLENGTH=10000 ZSH_HIGHLIGHT_MAXLENGTH=10000
# Load zsh/parameter module if available
zmodload zsh/parameter 2>/dev/null zmodload zsh/parameter 2>/dev/null
autoload -U is-at-least autoload -U is-at-least
source "${DOTLIB}/highlight" source "${dotlib}/highlight"
[[ "${+termcap[Co]}" = 1 && "${termcap[Co]}" = "256" ]] && FAST_HIGHLIGHT_STYLES[variable]="fg=112" [[ "${+termcap[Co]}" = 1 && "${termcap[Co]}" = "256" ]] && FAST_HIGHLIGHT_STYLES[variable]="fg=112"

View file

@ -1,55 +1,11 @@
# Fish-like fast/unobtrusive autosuggestions for zsh.
# https://github.com/zsh-users/zsh-autosuggestions
# v0.4.0
# Copyright (c) 2013 Thiago de Arruda
# Copyright (c) 2016-2017 Eric Freese
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#--------------------------------------------------------------------#
# Setup #
#--------------------------------------------------------------------#
# Precmd hooks for initializing the library and starting pty's
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
# Asynchronous suggestions are generated in a pty
zmodload zsh/zpty zmodload zsh/zpty
#--------------------------------------------------------------------#
# Global Configuration Variables #
#--------------------------------------------------------------------#
# Color to use when highlighting suggestion
# Uses format of `region_highlight`
# More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
# Prefix to use when saving original versions of bound widgets
ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
ZSH_AUTOSUGGEST_STRATEGY=default ZSH_AUTOSUGGEST_STRATEGY=default
# Widgets that clear the suggestion
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=( ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
history-search-forward history-search-forward
history-search-backward history-search-backward
@ -62,7 +18,6 @@ ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
accept-line accept-line
) )
# Widgets that accept the entire suggestion
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=( ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
forward-char forward-char
end-of-line end-of-line
@ -71,11 +26,9 @@ ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
vi-add-eol vi-add-eol
) )
# Widgets that accept the entire suggestion and execute it
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=( ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
) )
# Widgets that accept the suggestion as far as the cursor moves
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
forward-word forward-word
vi-forward-word vi-forward-word
@ -84,7 +37,6 @@ ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
vi-forward-blank-word-end vi-forward-blank-word-end
) )
# Widgets that should be ignored (globbing supported but must be escaped)
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=( ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
orig-\* orig-\*
beep beep
@ -94,27 +46,14 @@ ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
yank yank
) )
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE= ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=
# Pty name for calculating autosuggestions asynchronously
ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=zsh_autosuggest_pty ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=zsh_autosuggest_pty
#--------------------------------------------------------------------#
# Utility Functions #
#--------------------------------------------------------------------#
_zsh_autosuggest_escape_command() { _zsh_autosuggest_escape_command() {
setopt localoptions EXTENDED_GLOB setopt localoptions EXTENDED_GLOB
# Escape special chars in the string (requires EXTENDED_GLOB)
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}" echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
} }
#--------------------------------------------------------------------#
# Feature Detection #
#--------------------------------------------------------------------#
_zsh_autosuggest_feature_detect_zpty_returns_fd() { _zsh_autosuggest_feature_detect_zpty_returns_fd() {
typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD
typeset -h REPLY typeset -h REPLY
@ -130,10 +69,6 @@ _zsh_autosuggest_feature_detect_zpty_returns_fd() {
zpty -d zsh_autosuggest_feature_detect zpty -d zsh_autosuggest_feature_detect
} }
#--------------------------------------------------------------------#
# Widget Helpers #
#--------------------------------------------------------------------#
_zsh_autosuggest_incr_bind_count() { _zsh_autosuggest_incr_bind_count() {
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++)) ((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++))
@ -152,7 +87,6 @@ _zsh_autosuggest_get_bind_count() {
fi fi
} }
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
_zsh_autosuggest_bind_widget() { _zsh_autosuggest_bind_widget() {
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
@ -162,25 +96,21 @@ _zsh_autosuggest_bind_widget() {
local -i bind_count local -i bind_count
# Save a reference to the original widget
case $widgets[$widget] in case $widgets[$widget] in
# Already bound # Already bound
user:_zsh_autosuggest_(bound|orig)_*);; user:_zsh_autosuggest_(bound|orig)_*);;
# User-defined widget
user:*) user:*)
_zsh_autosuggest_incr_bind_count $widget _zsh_autosuggest_incr_bind_count $widget
zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:} zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:}
;; ;;
# Built-in widget
builtin) builtin)
_zsh_autosuggest_incr_bind_count $widget _zsh_autosuggest_incr_bind_count $widget
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget
;; ;;
# Completion widget
completion:*) completion:*)
_zsh_autosuggest_incr_bind_count $widget _zsh_autosuggest_incr_bind_count $widget
eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
@ -189,21 +119,13 @@ _zsh_autosuggest_bind_widget() {
_zsh_autosuggest_get_bind_count $widget _zsh_autosuggest_get_bind_count $widget
# Pass the original widget's name explicitly into the autosuggest
# function. Use this passed in widget name to call the original
# widget instead of relying on the $WIDGET variable being set
# correctly. $WIDGET cannot be trusted because other plugins call
# zle without the `-w` flag (e.g. `zle self-insert` instead of
# `zle self-insert -w`).
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() { eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
}" }"
# Create the bound widget
zle -N $widget _zsh_autosuggest_bound_${bind_count}_$widget zle -N $widget _zsh_autosuggest_bound_${bind_count}_$widget
} }
# Map all configured widgets to the right autosuggest widgets
_zsh_autosuggest_bind_widgets() { _zsh_autosuggest_bind_widgets() {
local widget local widget
local ignore_widgets local ignore_widgets
@ -217,7 +139,6 @@ _zsh_autosuggest_bind_widgets() {
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS $ZSH_AUTOSUGGEST_IGNORE_WIDGETS
) )
# Find every widget we might want to bind and bind it appropriately
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
_zsh_autosuggest_bind_widget $widget clear _zsh_autosuggest_bind_widget $widget clear
@ -228,15 +149,12 @@ _zsh_autosuggest_bind_widgets() {
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
_zsh_autosuggest_bind_widget $widget partial_accept _zsh_autosuggest_bind_widget $widget partial_accept
else else
# Assume any unspecified widget might modify the buffer
_zsh_autosuggest_bind_widget $widget modify _zsh_autosuggest_bind_widget $widget modify
fi fi
done done
} }
# Given the name of an original widget and args, invoke it, if it exists
_zsh_autosuggest_invoke_original_widget() { _zsh_autosuggest_invoke_original_widget() {
# Do nothing unless called with at least one arg
[ $# -gt 0 ] || return [ $# -gt 0 ] || return
local original_widget_name="$1" local original_widget_name="$1"
@ -248,11 +166,6 @@ _zsh_autosuggest_invoke_original_widget() {
fi fi
} }
#--------------------------------------------------------------------#
# Highlighting #
#--------------------------------------------------------------------#
# If there was a highlight, remove it
_zsh_autosuggest_highlight_reset() { _zsh_autosuggest_highlight_reset() {
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
@ -262,7 +175,6 @@ _zsh_autosuggest_highlight_reset() {
fi fi
} }
# If there's a suggestion, highlight it
_zsh_autosuggest_highlight_apply() { _zsh_autosuggest_highlight_apply() {
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
@ -274,17 +186,11 @@ _zsh_autosuggest_highlight_apply() {
fi fi
} }
#--------------------------------------------------------------------#
# Autosuggest Widget Implementations #
#--------------------------------------------------------------------#
# Disable suggestions
_zsh_autosuggest_disable() { _zsh_autosuggest_disable() {
typeset -g _ZSH_AUTOSUGGEST_DISABLED typeset -g _ZSH_AUTOSUGGEST_DISABLED
_zsh_autosuggest_clear _zsh_autosuggest_clear
} }
# Enable suggestions
_zsh_autosuggest_enable() { _zsh_autosuggest_enable() {
unset _ZSH_AUTOSUGGEST_DISABLED unset _ZSH_AUTOSUGGEST_DISABLED
@ -293,7 +199,6 @@ _zsh_autosuggest_enable() {
fi fi
} }
# Toggle suggestions (enable/disable)
_zsh_autosuggest_toggle() { _zsh_autosuggest_toggle() {
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
_zsh_autosuggest_enable _zsh_autosuggest_enable
@ -302,60 +207,47 @@ _zsh_autosuggest_toggle() {
fi fi
} }
# Clear the suggestion
_zsh_autosuggest_clear() { _zsh_autosuggest_clear() {
# Remove the suggestion
unset POSTDISPLAY unset POSTDISPLAY
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@
} }
# Modify the buffer and get a new suggestion
_zsh_autosuggest_modify() { _zsh_autosuggest_modify() {
local -i retval local -i retval
# Only added to zsh very recently
local -i KEYS_QUEUED_COUNT local -i KEYS_QUEUED_COUNT
# Save the contents of the buffer/postdisplay
local orig_buffer="$BUFFER" local orig_buffer="$BUFFER"
local orig_postdisplay="$POSTDISPLAY" local orig_postdisplay="$POSTDISPLAY"
# Clear suggestion while waiting for next one
unset POSTDISPLAY unset POSTDISPLAY
# Original widget may modify the buffer
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@
retval=$? retval=$?
# Don't fetch a new suggestion if there's more input to be read immediately
if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then
return $retval return $retval
fi fi
# Optimize if manually typing in the suggestion
if [ $#BUFFER -gt $#orig_buffer ]; then if [ $#BUFFER -gt $#orig_buffer ]; then
local added=${BUFFER#$orig_buffer} local added=${BUFFER#$orig_buffer}
# If the string added matches the beginning of the postdisplay
if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then
POSTDISPLAY="${orig_postdisplay:$#added}" POSTDISPLAY="${orig_postdisplay:$#added}"
return $retval return $retval
fi fi
fi fi
# Don't fetch a new suggestion if the buffer hasn't changed
if [ "$BUFFER" = "$orig_buffer" ]; then if [ "$BUFFER" = "$orig_buffer" ]; then
POSTDISPLAY="$orig_postdisplay" POSTDISPLAY="$orig_postdisplay"
return $retval return $retval
fi fi
# Bail out if suggestions are disabled
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
return $? return $?
fi fi
# Get a new suggestion if the buffer is not empty after modification
if [ $#BUFFER -gt 0 ]; then if [ $#BUFFER -gt 0 ]; then
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
_zsh_autosuggest_fetch _zsh_autosuggest_fetch
@ -365,7 +257,6 @@ _zsh_autosuggest_modify() {
return $retval return $retval
} }
# Fetch a new suggestion based on what's currently in the buffer
_zsh_autosuggest_fetch() { _zsh_autosuggest_fetch() {
if zpty -t "$ZSH_AUTOSUGGEST_ASYNC_PTY_NAME" &>/dev/null; then if zpty -t "$ZSH_AUTOSUGGEST_ASYNC_PTY_NAME" &>/dev/null; then
_zsh_autosuggest_async_request "$BUFFER" _zsh_autosuggest_async_request "$BUFFER"
@ -376,7 +267,6 @@ _zsh_autosuggest_fetch() {
fi fi
} }
# Offer a suggestion
_zsh_autosuggest_suggest() { _zsh_autosuggest_suggest() {
local suggestion="$1" local suggestion="$1"
@ -387,67 +277,39 @@ _zsh_autosuggest_suggest() {
fi fi
} }
# Accept the entire suggestion
_zsh_autosuggest_accept() { _zsh_autosuggest_accept() {
local -i max_cursor_pos=$#BUFFER local -i max_cursor_pos=$#BUFFER
# When vicmd keymap is active, the cursor can't move all the way
# to the end of the buffer
if [ "$KEYMAP" = "vicmd" ]; then if [ "$KEYMAP" = "vicmd" ]; then
max_cursor_pos=$((max_cursor_pos - 1)) max_cursor_pos=$((max_cursor_pos - 1))
fi fi
# Only accept if the cursor is at the end of the buffer
if [ $CURSOR -eq $max_cursor_pos ]; then if [ $CURSOR -eq $max_cursor_pos ]; then
# Add the suggestion to the buffer
BUFFER="$BUFFER$POSTDISPLAY" BUFFER="$BUFFER$POSTDISPLAY"
# Remove the suggestion
unset POSTDISPLAY unset POSTDISPLAY
# Move the cursor to the end of the buffer
CURSOR=${#BUFFER} CURSOR=${#BUFFER}
fi fi
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@
} }
# Accept the entire suggestion and execute it
_zsh_autosuggest_execute() { _zsh_autosuggest_execute() {
# Add the suggestion to the buffer
BUFFER="$BUFFER$POSTDISPLAY" BUFFER="$BUFFER$POSTDISPLAY"
# Remove the suggestion
unset POSTDISPLAY unset POSTDISPLAY
# Call the original `accept-line` to handle syntax highlighting or
# other potential custom behavior
_zsh_autosuggest_invoke_original_widget "accept-line" _zsh_autosuggest_invoke_original_widget "accept-line"
} }
# Partially accept the suggestion
_zsh_autosuggest_partial_accept() { _zsh_autosuggest_partial_accept() {
local -i retval local -i retval
# Save the contents of the buffer so we can restore later if needed
local original_buffer="$BUFFER" local original_buffer="$BUFFER"
# Temporarily accept the suggestion.
BUFFER="$BUFFER$POSTDISPLAY" BUFFER="$BUFFER$POSTDISPLAY"
# Original widget moves the cursor
_zsh_autosuggest_invoke_original_widget $@ _zsh_autosuggest_invoke_original_widget $@
retval=$? retval=$?
# If we've moved past the end of the original buffer
if [ $CURSOR -gt $#original_buffer ]; then if [ $CURSOR -gt $#original_buffer ]; then
# Set POSTDISPLAY to text right of the cursor
POSTDISPLAY="$RBUFFER" POSTDISPLAY="$RBUFFER"
# Clip the buffer at the cursor
BUFFER="$LBUFFER" BUFFER="$LBUFFER"
else else
# Restore the original buffer
BUFFER="$original_buffer" BUFFER="$original_buffer"
fi fi
@ -480,115 +342,50 @@ zle -N autosuggest-enable _zsh_autosuggest_widget_enable
zle -N autosuggest-disable _zsh_autosuggest_widget_disable zle -N autosuggest-disable _zsh_autosuggest_widget_disable
zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle
#--------------------------------------------------------------------#
# Default Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history item that matches the given
# prefix.
#
_zsh_autosuggest_strategy_default() { _zsh_autosuggest_strategy_default() {
# Reset options to defaults and enable LOCAL_OPTIONS
emulate -L zsh emulate -L zsh
# Enable globbing flags so that we can use (#m)
setopt EXTENDED_GLOB setopt EXTENDED_GLOB
# Escape backslashes and all of the glob operators so we can use
# this string as a pattern to search the $history associative array.
# - (#m) globbing flag enables setting references for match data
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
# Get the history items that match
# - (r) subscript flag makes the pattern match on values
suggestion="${history[(r)$prefix*]}" suggestion="${history[(r)$prefix*]}"
} }
#--------------------------------------------------------------------#
# Match Previous Command Suggestion Strategy #
#--------------------------------------------------------------------#
# Suggests the most recent history item that matches the given
# prefix and whose preceding history item also matches the most
# recently executed command.
#
# For example, suppose your history has the following entries:
# - pwd
# - ls foo
# - ls bar
# - pwd
#
# Given the history list above, when you type 'ls', the suggestion
# will be 'ls foo' rather than 'ls bar' because your most recently
# executed command (pwd) was previously followed by 'ls foo'.
#
# Note that this strategy won't work as expected with ZSH options that don't
# preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
# `HIST_EXPIRE_DUPS_FIRST`.
_zsh_autosuggest_strategy_match_prev_cmd() { _zsh_autosuggest_strategy_match_prev_cmd() {
local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}" local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}"
# Get all history event numbers that correspond to history
# entries that match pattern $prefix*
local history_match_keys local history_match_keys
history_match_keys=(${(k)history[(R)$prefix*]}) history_match_keys=(${(k)history[(R)$prefix*]})
# By default we use the first history number (most recent history entry)
local histkey="${history_match_keys[1]}" local histkey="${history_match_keys[1]}"
# Get the previously executed command
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
# Iterate up to the first 200 history event numbers that match $prefix
for key in "${(@)history_match_keys[1,200]}"; do for key in "${(@)history_match_keys[1,200]}"; do
# Stop if we ran out of history
[[ $key -gt 1 ]] || break [[ $key -gt 1 ]] || break
# See if the history entry preceding the suggestion matches the
# previous command, and use it if it does
if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
histkey="$key" histkey="$key"
break break
fi fi
done done
# Give back the matched history entry
suggestion="$history[$histkey]" suggestion="$history[$histkey]"
} }
#--------------------------------------------------------------------#
# Async #
#--------------------------------------------------------------------#
# Zpty process is spawned running this function
_zsh_autosuggest_async_server() { _zsh_autosuggest_async_server() {
emulate -R zsh emulate -R zsh
# There is a bug in zpty module (fixed in zsh/master) by which a
# zpty that exits will kill all zpty processes that were forked
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
# process immediately, before it has a chance to kill any other
# zpty processes.
zshexit() { zshexit() {
kill -KILL $$ kill -KILL $$
sleep 1 # Block for long enough for the signal to come through sleep 1
} }
# Output only newlines (not carriage return + newline)
stty -onlcr stty -onlcr
# Silence any error messages
exec 2>/dev/null exec 2>/dev/null
local strategy=$1 local strategy=$1
local last_pid local last_pid
while IFS='' read -r -d $'\0' query; do while IFS='' read -r -d $'\0' query; do
# Kill last bg process
kill -KILL $last_pid &>/dev/null kill -KILL $last_pid &>/dev/null
# Run suggestion search in the background
( (
local suggestion local suggestion
_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$query" _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$query"
@ -600,13 +397,9 @@ _zsh_autosuggest_async_server() {
} }
_zsh_autosuggest_async_request() { _zsh_autosuggest_async_request() {
# Write the query to the zpty process to fetch a suggestion
zpty -w -n $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "${1}"$'\0' zpty -w -n $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "${1}"$'\0'
} }
# Called when new data is ready to be read from the pty
# First arg will be fd ready for reading
# Second arg will be passed in case of error
_zsh_autosuggest_async_response() { _zsh_autosuggest_async_response() {
setopt LOCAL_OPTIONS EXTENDED_GLOB setopt LOCAL_OPTIONS EXTENDED_GLOB
@ -617,36 +410,29 @@ _zsh_autosuggest_async_response() {
} }
_zsh_autosuggest_async_pty_create() { _zsh_autosuggest_async_pty_create() {
# With newer versions of zsh, REPLY stores the fd to read from
typeset -h REPLY typeset -h REPLY
# If we won't get a fd back from zpty, try to guess it
if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then if [ $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD -eq 0 ]; then
integer -l zptyfd integer -l zptyfd
exec {zptyfd}>&1 # Open a new file descriptor (above 10). exec {zptyfd}>&1
exec {zptyfd}>&- # Close it so it's free to be used by zpty. exec {zptyfd}>&-
fi fi
# Fork a zpty process running the server function
zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY" zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "_zsh_autosuggest_async_server _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
# Store the fd so we can remove the handler later
if (( REPLY )); then if (( REPLY )); then
_ZSH_AUTOSUGGEST_PTY_FD=$REPLY _ZSH_AUTOSUGGEST_PTY_FD=$REPLY
else else
_ZSH_AUTOSUGGEST_PTY_FD=$zptyfd _ZSH_AUTOSUGGEST_PTY_FD=$zptyfd
fi fi
# Set up input handler from the zpty
zle -F $_ZSH_AUTOSUGGEST_PTY_FD _zsh_autosuggest_async_response zle -F $_ZSH_AUTOSUGGEST_PTY_FD _zsh_autosuggest_async_response
} }
_zsh_autosuggest_async_pty_destroy() { _zsh_autosuggest_async_pty_destroy() {
if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then
# Remove the input handler
zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
# Destroy the zpty
zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
fi fi
} }
@ -662,24 +448,14 @@ _zsh_autosuggest_async_start() {
_zsh_autosuggest_feature_detect_zpty_returns_fd _zsh_autosuggest_feature_detect_zpty_returns_fd
_zsh_autosuggest_async_pty_recreate _zsh_autosuggest_async_pty_recreate
# We recreate the pty to get a fresh list of history events
add-zsh-hook precmd _zsh_autosuggest_async_pty_recreate add-zsh-hook precmd _zsh_autosuggest_async_pty_recreate
} }
#--------------------------------------------------------------------#
# Start #
#--------------------------------------------------------------------#
# Start the autosuggestion widgets
_zsh_autosuggest_start() { _zsh_autosuggest_start() {
add-zsh-hook -d precmd _zsh_autosuggest_start add-zsh-hook -d precmd _zsh_autosuggest_start
_zsh_autosuggest_bind_widgets _zsh_autosuggest_bind_widgets
# Re-bind widgets on every precmd to ensure we wrap other wrappers.
# Specifically, highlighting breaks if our widgets are wrapped by
# zsh-syntax-highlighting widgets. This also allows modifications
# to the widget list variables to take effect on the next precmd.
add-zsh-hook precmd _zsh_autosuggest_bind_widgets add-zsh-hook precmd _zsh_autosuggest_bind_widgets
if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then
@ -687,6 +463,5 @@ _zsh_autosuggest_start() {
fi fi
} }
# Start the autosuggestion widgets on the next precmd
add-zsh-hook precmd _zsh_autosuggest_start add-zsh-hook precmd _zsh_autosuggest_start

View file

@ -1 +1 @@
eval `dircolors ${DOTCFG}/dir/cfg` eval `dircolors ${dotcfg}/dir/cfg`

View file

@ -1,5 +1,5 @@
export ZSH_PLUGIN_GITIGNORE_PATH=$(dirname $0) ZSH_PLUGIN_GITIGNORE_PATH=$(dirname $0)
export ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS=${DOTLIB}/gitignore ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS=${dotlib}/gitignore
function gie () { ${EDITOR} .gitignore } function gie () { ${EDITOR} .gitignore }

View file

@ -1,7 +1,3 @@
#
# Aliases
#
alias ta='tmux attach -t' alias ta='tmux attach -t'
alias tad='tmux attach -d -t' alias tad='tmux attach -d -t'
alias ts='tmux new-session -s' alias ts='tmux new-session -s'
@ -9,84 +5,52 @@ alias tl='tmux list-sessions'
alias tksv='tmux kill-server' alias tksv='tmux kill-server'
alias tkss='tmux kill-session -t' alias tkss='tmux kill-session -t'
# Only run if tmux is actually installed
if which tmux &> /dev/null if which tmux &> /dev/null
then then
# Configuration variables
#
# Automatically start tmux
[[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false
# Only autostart once. If set to false, tmux will attempt to
# autostart every time your zsh configs are reloaded.
[[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true [[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true
# Automatically connect to a previous session if it exists
[[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true
# Automatically close the terminal when tmux exits
[[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART
# Set term to screen or screen-256color based on current terminal support
[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
# Set '-CC' option for iTerm2 tmux integration
[[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false [[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false
# The TERM to use for non-256 color terminals.
# Tmux states this should be screen, but you may need to change it on
# systems without the proper terminfo
[[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen" [[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen"
# The TERM to use for 256 color terminals.
# Tmux states this should be screen-256color, but you may need to change it on
# systems without the proper terminfo
[[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color" [[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color"
local zsh_tmux_plugin_path=${dotcfg}/tmux
# Get the absolute path to the current directory
local zsh_tmux_plugin_path=${DOTCFG}/tmux
# Determine if the terminal supports 256 colors
if [[ `tput colors` == "256" ]] if [[ `tput colors` == "256" ]]
then then
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
else else
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
fi fi
# Set the correct local config file to use. if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
then then
#use this when they have a ~/.tmux.conf _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf"
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf"
else else
#use this when they don't have a ~/.tmux.conf _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
fi fi
# Wrapper function for tmux.
function _zsh_tmux_plugin_run() function _zsh_tmux_plugin_run()
{ {
# We have other arguments, just run them
if [[ -n "$@" ]] if [[ -n "$@" ]]
then then
\tmux $@ \tmux $@
# Try to connect to an existing session.
elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
then then
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
# Just run tmux, fixing the TERM variable if requested.
else else
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG`
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
fi fi
} }
# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run compdef _tmux _zsh_tmux_plugin_run
# Alias tmux to our wrapper function.
alias tmux=_zsh_tmux_plugin_run alias tmux=_zsh_tmux_plugin_run
# Autostart if not already in tmux and enabled.
if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]]
then then
# Actually don't autostart if we already did and multiple autostarts are disabled.
if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]
then then
export ZSH_TMUX_AUTOSTARTED=true export ZSH_TMUX_AUTOSTARTED=true

View file

@ -4,6 +4,6 @@ alias mv='mv -i'
alias la='ls -lAh' alias la='ls -lAh'
clearall () { clear; printf '\033[3J' } clearall () { clear; printf '\033[3J' }
for file in ${DOTCFGD}/source.d/*.zsh; do for file in ${dotcfg}/zsh/cfg.d/source.d/*.zsh; do
source $file source $file
done done

View file

@ -1,5 +1,7 @@
# Source all files # Source all files
for file in ${HOME}/dotfiles/cfg/zsh/cfg.d/*.zsh; do source $file; done for file in ${HOME}/dotfiles/cfg/zsh/cfg.d/*.zsh; do
source $file
done
# Prompt # Prompt
prompt z4rr3t prompt z4rr3t