changed folder layout
This commit is contained in:
parent
d8d0325842
commit
6a1f0cce72
24 changed files with 2 additions and 2162 deletions
|
@ -1,3 +0,0 @@
|
||||||
export ZSH="${DOTLIB}/ohmyzsh"
|
|
||||||
DISABLE_AUTO_UPDATE="true"
|
|
||||||
source ${ZSH}/oh-my-zsh.sh
|
|
|
@ -1,7 +0,0 @@
|
||||||
alias rm='rm -i'
|
|
||||||
alias cp='cp -i'
|
|
||||||
alias mv='mv -i'
|
|
||||||
alias la='ls -lAh'
|
|
||||||
clearall () { clear; printf '\033[3J' }
|
|
||||||
|
|
||||||
for file in ${DOTCFGD}/aliases/*.zsh; do source $file; done
|
|
|
@ -1 +0,0 @@
|
||||||
for file in ${DOTCFGD}/functions/*.zsh; do source $file; done
|
|
|
@ -1,275 +0,0 @@
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# 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}
|
|
||||||
|
|
||||||
# Invokes each highlighter that needs updating.
|
|
||||||
# This function is supposed to be called whenever the ZLE state changes.
|
|
||||||
_zsh_highlight()
|
|
||||||
{
|
|
||||||
# Store the previous command return code to restore it whatever happens.
|
|
||||||
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
|
|
||||||
region_highlight=()
|
|
||||||
return $ret
|
|
||||||
fi
|
|
||||||
|
|
||||||
setopt localoptions warncreateglobal noksharrays
|
|
||||||
local REPLY # don't leak $REPLY into global scope
|
|
||||||
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
|
|
||||||
|
|
||||||
# Do not highlight if there are pending inputs (copy/paste).
|
|
||||||
[[ $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
|
|
||||||
-fast-highlight-init
|
|
||||||
-fast-highlight-process && region_highlight=( $reply ) || region_highlight=()
|
|
||||||
fi
|
|
||||||
|
|
||||||
{
|
|
||||||
local cache_place
|
|
||||||
local -a region_highlight_copy
|
|
||||||
|
|
||||||
# Re-apply zle_highlight settings
|
|
||||||
|
|
||||||
# region
|
|
||||||
if (( REGION_ACTIVE == 1 )); then
|
|
||||||
_zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR"
|
|
||||||
elif (( REGION_ACTIVE == 2 )); then
|
|
||||||
() {
|
|
||||||
local needle=$'\n'
|
|
||||||
integer min max
|
|
||||||
if (( MARK > CURSOR )) ; then
|
|
||||||
min=$CURSOR max=$MARK
|
|
||||||
else
|
|
||||||
min=$MARK max=$CURSOR
|
|
||||||
fi
|
|
||||||
(( min = ${${BUFFER[1,$min]}[(I)$needle]} ))
|
|
||||||
(( max += ${${BUFFER:($max-1)}[(i)$needle]} - 1 ))
|
|
||||||
_zsh_highlight_apply_zle_highlight region standout "$min" "$max"
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# yank / paste (zsh-5.1.1 and newer)
|
|
||||||
(( $+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"
|
|
||||||
|
|
||||||
# suffix
|
|
||||||
(( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
|
|
||||||
|
|
||||||
return $ret
|
|
||||||
|
|
||||||
} always {
|
|
||||||
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER"
|
|
||||||
typeset -g _ZSH_HIGHLIGHT_PRIOR_RACTIVE="$REGION_ACTIVE"
|
|
||||||
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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() {
|
|
||||||
local entry="$1" default="$2"
|
|
||||||
integer first="$3" second="$4"
|
|
||||||
|
|
||||||
# read the relevant entry from zle_highlight
|
|
||||||
local region="${zle_highlight[(r)${entry}:*]}"
|
|
||||||
|
|
||||||
if [[ -z "$region" ]]; then
|
|
||||||
# entry not specified at all, use default value
|
|
||||||
region=$default
|
|
||||||
else
|
|
||||||
# strip prefix
|
|
||||||
region="${region#${entry}:}"
|
|
||||||
|
|
||||||
# no highlighting when set to the empty string or to 'none'
|
|
||||||
if [[ -z "$region" ]] || [[ "$region" == none ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
integer start end
|
|
||||||
if (( first < second )); then
|
|
||||||
start=$first end=$second
|
|
||||||
else
|
|
||||||
start=$second end=$first
|
|
||||||
fi
|
|
||||||
region_highlight+=("$start $end $region")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# 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_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()
|
|
||||||
{
|
|
||||||
[[ -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()
|
|
||||||
{
|
|
||||||
builtin zle "$@" && _zsh_highlight
|
|
||||||
}
|
|
||||||
|
|
||||||
# Rebind all ZLE widgets to make them invoke _zsh_highlights.
|
|
||||||
_zsh_highlight_bind_widgets()
|
|
||||||
{
|
|
||||||
setopt localoptions noksharrays
|
|
||||||
typeset -F SECONDS
|
|
||||||
local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once
|
|
||||||
|
|
||||||
# Load ZSH module zsh/zleparameter, needed to override user defined widgets.
|
|
||||||
zmodload zsh/zleparameter 2>/dev/null || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Override ZLE widgets to make them invoke _zsh_highlight.
|
|
||||||
local -U widgets_to_bind
|
|
||||||
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)
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
local cur_widget
|
|
||||||
for cur_widget in $widgets_to_bind; do
|
|
||||||
case $widgets[$cur_widget] in
|
|
||||||
|
|
||||||
# Already rebound event: do nothing.
|
|
||||||
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]#*:}
|
|
||||||
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;;
|
|
||||||
|
|
||||||
# Completion widget: override and rebind old one with prefix "orig-".
|
|
||||||
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} -- \"\$@\" }"
|
|
||||||
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} -- \"\$@\" }"
|
|
||||||
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
|
|
||||||
_zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight }
|
|
||||||
zle -N $cur_widget _zsh_highlight_widget_$cur_widget
|
|
||||||
else
|
|
||||||
# Default: unhandled case.
|
|
||||||
print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}"
|
|
||||||
fi
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
# Setup
|
|
||||||
# -------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Try binding widgets.
|
|
||||||
_zsh_highlight_bind_widgets || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Reset scratch variables when commandline is done.
|
|
||||||
_zsh_highlight_preexec_hook()
|
|
||||||
{
|
|
||||||
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
|
|
||||||
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=0
|
|
||||||
}
|
|
||||||
|
|
||||||
autoload -U add-zsh-hook
|
|
||||||
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
|
|
||||||
print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.'
|
|
||||||
}
|
|
||||||
|
|
||||||
ZSH_HIGHLIGHT_MAXLENGTH=10000
|
|
||||||
|
|
||||||
# Load zsh/parameter module if available
|
|
||||||
zmodload zsh/parameter 2>/dev/null
|
|
||||||
|
|
||||||
autoload -U is-at-least
|
|
||||||
source "${DOTLIB}/highlight"
|
|
||||||
|
|
||||||
[[ "${+termcap[Co]}" = 1 && "${termcap[Co]}" = "256" ]] && FAST_HIGHLIGHT_STYLES[variable]="fg=112"
|
|
||||||
|
|
||||||
-fast-highlight-fill-option-variables
|
|
|
@ -1,692 +0,0 @@
|
||||||
# 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
|
|
||||||
|
|
||||||
# Asynchronous suggestions are generated in a pty
|
|
||||||
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'
|
|
||||||
|
|
||||||
# Prefix to use when saving original versions of bound widgets
|
|
||||||
ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|
||||||
|
|
||||||
ZSH_AUTOSUGGEST_STRATEGY=default
|
|
||||||
|
|
||||||
# Widgets that clear the suggestion
|
|
||||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
|
||||||
history-search-forward
|
|
||||||
history-search-backward
|
|
||||||
history-beginning-search-forward
|
|
||||||
history-beginning-search-backward
|
|
||||||
history-substring-search-up
|
|
||||||
history-substring-search-down
|
|
||||||
up-line-or-history
|
|
||||||
down-line-or-history
|
|
||||||
accept-line
|
|
||||||
)
|
|
||||||
|
|
||||||
# Widgets that accept the entire suggestion
|
|
||||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
|
||||||
forward-char
|
|
||||||
end-of-line
|
|
||||||
vi-forward-char
|
|
||||||
vi-end-of-line
|
|
||||||
vi-add-eol
|
|
||||||
)
|
|
||||||
|
|
||||||
# Widgets that accept the entire suggestion and execute it
|
|
||||||
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
|
||||||
)
|
|
||||||
|
|
||||||
# Widgets that accept the suggestion as far as the cursor moves
|
|
||||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
|
||||||
forward-word
|
|
||||||
vi-forward-word
|
|
||||||
vi-forward-word-end
|
|
||||||
vi-forward-blank-word
|
|
||||||
vi-forward-blank-word-end
|
|
||||||
)
|
|
||||||
|
|
||||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
|
||||||
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
|
||||||
orig-\*
|
|
||||||
beep
|
|
||||||
run-help
|
|
||||||
set-local-history
|
|
||||||
which-command
|
|
||||||
yank
|
|
||||||
)
|
|
||||||
|
|
||||||
# Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
|
|
||||||
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=
|
|
||||||
|
|
||||||
# Pty name for calculating autosuggestions asynchronously
|
|
||||||
ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=zsh_autosuggest_pty
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Utility Functions #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_escape_command() {
|
|
||||||
setopt localoptions EXTENDED_GLOB
|
|
||||||
|
|
||||||
# Escape special chars in the string (requires EXTENDED_GLOB)
|
|
||||||
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Feature Detection #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_feature_detect_zpty_returns_fd() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD
|
|
||||||
typeset -h REPLY
|
|
||||||
|
|
||||||
zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }'
|
|
||||||
|
|
||||||
if (( REPLY )); then
|
|
||||||
_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1
|
|
||||||
else
|
|
||||||
_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
zpty -d zsh_autosuggest_feature_detect
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Widget Helpers #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
_zsh_autosuggest_incr_bind_count() {
|
|
||||||
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
|
|
||||||
((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++))
|
|
||||||
else
|
|
||||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_get_bind_count() {
|
|
||||||
if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
|
|
||||||
bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
|
|
||||||
else
|
|
||||||
bind_count=0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
|
||||||
_zsh_autosuggest_bind_widget() {
|
|
||||||
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
|
|
||||||
|
|
||||||
local widget=$1
|
|
||||||
local autosuggest_action=$2
|
|
||||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
|
||||||
|
|
||||||
local -i bind_count
|
|
||||||
|
|
||||||
# Save a reference to the original widget
|
|
||||||
case $widgets[$widget] in
|
|
||||||
# Already bound
|
|
||||||
user:_zsh_autosuggest_(bound|orig)_*);;
|
|
||||||
|
|
||||||
# User-defined widget
|
|
||||||
user:*)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:}
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Built-in widget
|
|
||||||
builtin)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
|
|
||||||
zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget
|
|
||||||
;;
|
|
||||||
|
|
||||||
# Completion widget
|
|
||||||
completion:*)
|
|
||||||
_zsh_autosuggest_incr_bind_count $widget
|
|
||||||
eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
_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}() {
|
|
||||||
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
|
|
||||||
}"
|
|
||||||
|
|
||||||
# Create the bound widget
|
|
||||||
zle -N $widget _zsh_autosuggest_bound_${bind_count}_$widget
|
|
||||||
}
|
|
||||||
|
|
||||||
# Map all configured widgets to the right autosuggest widgets
|
|
||||||
_zsh_autosuggest_bind_widgets() {
|
|
||||||
local widget
|
|
||||||
local ignore_widgets
|
|
||||||
|
|
||||||
ignore_widgets=(
|
|
||||||
.\*
|
|
||||||
_\*
|
|
||||||
zle-\*
|
|
||||||
autosuggest-\*
|
|
||||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
|
||||||
$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
|
|
||||||
if [ ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget clear
|
|
||||||
elif [ ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget accept
|
|
||||||
elif [ ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget execute
|
|
||||||
elif [ ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]; then
|
|
||||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
|
||||||
else
|
|
||||||
# Assume any unspecified widget might modify the buffer
|
|
||||||
_zsh_autosuggest_bind_widget $widget modify
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# Given the name of an original widget and args, invoke it, if it exists
|
|
||||||
_zsh_autosuggest_invoke_original_widget() {
|
|
||||||
# Do nothing unless called with at least one arg
|
|
||||||
[ $# -gt 0 ] || return
|
|
||||||
|
|
||||||
local original_widget_name="$1"
|
|
||||||
|
|
||||||
shift
|
|
||||||
|
|
||||||
if [ $widgets[$original_widget_name] ]; then
|
|
||||||
zle $original_widget_name -- $@
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Highlighting #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# If there was a highlight, remove it
|
|
||||||
_zsh_autosuggest_highlight_reset() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
|
|
||||||
if [ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]; then
|
|
||||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# If there's a suggestion, highlight it
|
|
||||||
_zsh_autosuggest_highlight_apply() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
|
|
||||||
if [ $#POSTDISPLAY -gt 0 ]; then
|
|
||||||
_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
|
||||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
|
||||||
else
|
|
||||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Autosuggest Widget Implementations #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Disable suggestions
|
|
||||||
_zsh_autosuggest_disable() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_DISABLED
|
|
||||||
_zsh_autosuggest_clear
|
|
||||||
}
|
|
||||||
|
|
||||||
# Enable suggestions
|
|
||||||
_zsh_autosuggest_enable() {
|
|
||||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
|
||||||
|
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
|
||||||
_zsh_autosuggest_fetch
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Toggle suggestions (enable/disable)
|
|
||||||
_zsh_autosuggest_toggle() {
|
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
|
||||||
_zsh_autosuggest_enable
|
|
||||||
else
|
|
||||||
_zsh_autosuggest_disable
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clear the suggestion
|
|
||||||
_zsh_autosuggest_clear() {
|
|
||||||
# Remove the suggestion
|
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
}
|
|
||||||
|
|
||||||
# Modify the buffer and get a new suggestion
|
|
||||||
_zsh_autosuggest_modify() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
# Only added to zsh very recently
|
|
||||||
local -i KEYS_QUEUED_COUNT
|
|
||||||
|
|
||||||
# Save the contents of the buffer/postdisplay
|
|
||||||
local orig_buffer="$BUFFER"
|
|
||||||
local orig_postdisplay="$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Clear suggestion while waiting for next one
|
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Original widget may modify the buffer
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
|
||||||
if [[ $PENDING > 0 ]] || [[ $KEYS_QUEUED_COUNT > 0 ]]; then
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Optimize if manually typing in the suggestion
|
|
||||||
if [ $#BUFFER -gt $#orig_buffer ]; then
|
|
||||||
local added=${BUFFER#$orig_buffer}
|
|
||||||
|
|
||||||
# If the string added matches the beginning of the postdisplay
|
|
||||||
if [ "$added" = "${orig_postdisplay:0:$#added}" ]; then
|
|
||||||
POSTDISPLAY="${orig_postdisplay:$#added}"
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Don't fetch a new suggestion if the buffer hasn't changed
|
|
||||||
if [ "$BUFFER" = "$orig_buffer" ]; then
|
|
||||||
POSTDISPLAY="$orig_postdisplay"
|
|
||||||
return $retval
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Bail out if suggestions are disabled
|
|
||||||
if [ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]; then
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get a new suggestion if the buffer is not empty after modification
|
|
||||||
if [ $#BUFFER -gt 0 ]; then
|
|
||||||
if [ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" -o $#BUFFER -le "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]; then
|
|
||||||
_zsh_autosuggest_fetch
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
# Fetch a new suggestion based on what's currently in the buffer
|
|
||||||
_zsh_autosuggest_fetch() {
|
|
||||||
if zpty -t "$ZSH_AUTOSUGGEST_ASYNC_PTY_NAME" &>/dev/null; then
|
|
||||||
_zsh_autosuggest_async_request "$BUFFER"
|
|
||||||
else
|
|
||||||
local suggestion
|
|
||||||
_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$BUFFER"
|
|
||||||
_zsh_autosuggest_suggest "$suggestion"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Offer a suggestion
|
|
||||||
_zsh_autosuggest_suggest() {
|
|
||||||
local suggestion="$1"
|
|
||||||
|
|
||||||
if [ -n "$suggestion" ] && [ $#BUFFER -gt 0 ]; then
|
|
||||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
|
||||||
else
|
|
||||||
unset POSTDISPLAY
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Accept the entire suggestion
|
|
||||||
_zsh_autosuggest_accept() {
|
|
||||||
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
|
|
||||||
max_cursor_pos=$((max_cursor_pos - 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Only accept if the cursor is at the end of the buffer
|
|
||||||
if [ $CURSOR -eq $max_cursor_pos ]; then
|
|
||||||
# Add the suggestion to the buffer
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Move the cursor to the end of the buffer
|
|
||||||
CURSOR=${#BUFFER}
|
|
||||||
fi
|
|
||||||
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
}
|
|
||||||
|
|
||||||
# Accept the entire suggestion and execute it
|
|
||||||
_zsh_autosuggest_execute() {
|
|
||||||
# Add the suggestion to the buffer
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Remove the suggestion
|
|
||||||
unset POSTDISPLAY
|
|
||||||
|
|
||||||
# Call the original `accept-line` to handle syntax highlighting or
|
|
||||||
# other potential custom behavior
|
|
||||||
_zsh_autosuggest_invoke_original_widget "accept-line"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Partially accept the suggestion
|
|
||||||
_zsh_autosuggest_partial_accept() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
# Save the contents of the buffer so we can restore later if needed
|
|
||||||
local original_buffer="$BUFFER"
|
|
||||||
|
|
||||||
# Temporarily accept the suggestion.
|
|
||||||
BUFFER="$BUFFER$POSTDISPLAY"
|
|
||||||
|
|
||||||
# Original widget moves the cursor
|
|
||||||
_zsh_autosuggest_invoke_original_widget $@
|
|
||||||
retval=$?
|
|
||||||
|
|
||||||
# If we've moved past the end of the original buffer
|
|
||||||
if [ $CURSOR -gt $#original_buffer ]; then
|
|
||||||
# Set POSTDISPLAY to text right of the cursor
|
|
||||||
POSTDISPLAY="$RBUFFER"
|
|
||||||
|
|
||||||
# Clip the buffer at the cursor
|
|
||||||
BUFFER="$LBUFFER"
|
|
||||||
else
|
|
||||||
# Restore the original buffer
|
|
||||||
BUFFER="$original_buffer"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return $retval
|
|
||||||
}
|
|
||||||
|
|
||||||
for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do
|
|
||||||
eval "_zsh_autosuggest_widget_$action() {
|
|
||||||
local -i retval
|
|
||||||
|
|
||||||
_zsh_autosuggest_highlight_reset
|
|
||||||
|
|
||||||
_zsh_autosuggest_$action \$@
|
|
||||||
retval=\$?
|
|
||||||
|
|
||||||
_zsh_autosuggest_highlight_apply
|
|
||||||
|
|
||||||
zle -R
|
|
||||||
|
|
||||||
return \$retval
|
|
||||||
}"
|
|
||||||
done
|
|
||||||
|
|
||||||
zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch
|
|
||||||
zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest
|
|
||||||
zle -N autosuggest-accept _zsh_autosuggest_widget_accept
|
|
||||||
zle -N autosuggest-clear _zsh_autosuggest_widget_clear
|
|
||||||
zle -N autosuggest-execute _zsh_autosuggest_widget_execute
|
|
||||||
zle -N autosuggest-enable _zsh_autosuggest_widget_enable
|
|
||||||
zle -N autosuggest-disable _zsh_autosuggest_widget_disable
|
|
||||||
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() {
|
|
||||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
# Enable globbing flags so that we can use (#m)
|
|
||||||
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}"
|
|
||||||
|
|
||||||
# Get the history items that match
|
|
||||||
# - (r) subscript flag makes the pattern match on values
|
|
||||||
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() {
|
|
||||||
local prefix="${1//(#m)[\\()\[\]|*?~]/\\$MATCH}"
|
|
||||||
|
|
||||||
# Get all history event numbers that correspond to history
|
|
||||||
# entries that match pattern $prefix*
|
|
||||||
local history_match_keys
|
|
||||||
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]}"
|
|
||||||
|
|
||||||
# Get the previously executed command
|
|
||||||
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
|
|
||||||
# Stop if we ran out of history
|
|
||||||
[[ $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
|
|
||||||
histkey="$key"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Give back the matched history entry
|
|
||||||
suggestion="$history[$histkey]"
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Async #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Zpty process is spawned running this function
|
|
||||||
_zsh_autosuggest_async_server() {
|
|
||||||
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() {
|
|
||||||
kill -KILL $$
|
|
||||||
sleep 1 # Block for long enough for the signal to come through
|
|
||||||
}
|
|
||||||
|
|
||||||
# Output only newlines (not carriage return + newline)
|
|
||||||
stty -onlcr
|
|
||||||
|
|
||||||
# Silence any error messages
|
|
||||||
exec 2>/dev/null
|
|
||||||
|
|
||||||
local strategy=$1
|
|
||||||
local last_pid
|
|
||||||
|
|
||||||
while IFS='' read -r -d $'\0' query; do
|
|
||||||
# Kill last bg process
|
|
||||||
kill -KILL $last_pid &>/dev/null
|
|
||||||
|
|
||||||
# Run suggestion search in the background
|
|
||||||
(
|
|
||||||
local suggestion
|
|
||||||
_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$query"
|
|
||||||
echo -n -E "$suggestion"$'\0'
|
|
||||||
) &
|
|
||||||
|
|
||||||
last_pid=$!
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
_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'
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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() {
|
|
||||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
|
||||||
|
|
||||||
local suggestion
|
|
||||||
|
|
||||||
zpty -rt $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME suggestion '*'$'\0' 2>/dev/null
|
|
||||||
zle autosuggest-suggest -- "${suggestion%%$'\0'##}"
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_create() {
|
|
||||||
# With newer versions of zsh, REPLY stores the fd to read from
|
|
||||||
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
|
|
||||||
integer -l zptyfd
|
|
||||||
exec {zptyfd}>&1 # Open a new file descriptor (above 10).
|
|
||||||
exec {zptyfd}>&- # Close it so it's free to be used by zpty.
|
|
||||||
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"
|
|
||||||
|
|
||||||
# Store the fd so we can remove the handler later
|
|
||||||
if (( REPLY )); then
|
|
||||||
_ZSH_AUTOSUGGEST_PTY_FD=$REPLY
|
|
||||||
else
|
|
||||||
_ZSH_AUTOSUGGEST_PTY_FD=$zptyfd
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set up input handler from the zpty
|
|
||||||
zle -F $_ZSH_AUTOSUGGEST_PTY_FD _zsh_autosuggest_async_response
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_destroy() {
|
|
||||||
if zpty -t $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null; then
|
|
||||||
# Remove the input handler
|
|
||||||
zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
|
|
||||||
|
|
||||||
# Destroy the zpty
|
|
||||||
zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_pty_recreate() {
|
|
||||||
_zsh_autosuggest_async_pty_destroy
|
|
||||||
_zsh_autosuggest_async_pty_create
|
|
||||||
}
|
|
||||||
|
|
||||||
_zsh_autosuggest_async_start() {
|
|
||||||
typeset -g _ZSH_AUTOSUGGEST_PTY_FD
|
|
||||||
|
|
||||||
_zsh_autosuggest_feature_detect_zpty_returns_fd
|
|
||||||
_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
|
|
||||||
}
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
# Start #
|
|
||||||
#--------------------------------------------------------------------#
|
|
||||||
|
|
||||||
# Start the autosuggestion widgets
|
|
||||||
_zsh_autosuggest_start() {
|
|
||||||
add-zsh-hook -d precmd _zsh_autosuggest_start
|
|
||||||
|
|
||||||
_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
|
|
||||||
|
|
||||||
if [ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]; then
|
|
||||||
_zsh_autosuggest_async_start
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Start the autosuggestion widgets on the next precmd
|
|
||||||
add-zsh-hook precmd _zsh_autosuggest_start
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
# Authors:
|
|
||||||
# https://github.com/tristola
|
|
||||||
#
|
|
||||||
# Docker-compose related zsh aliases
|
|
||||||
|
|
||||||
# Aliases ###################################################################
|
|
||||||
|
|
||||||
# Use dco as alias for docker-compose, since dc on *nix is 'dc - an arbitrary precision calculator'
|
|
||||||
# https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html
|
|
||||||
|
|
||||||
alias dco='docker-compose'
|
|
||||||
|
|
||||||
alias dcb='docker-compose build'
|
|
||||||
alias dce='docker-compose exec'
|
|
||||||
alias dcps='docker-compose ps'
|
|
||||||
alias dcrestart='docker-compose restart'
|
|
||||||
alias dcrm='docker-compose rm'
|
|
||||||
alias dcr='docker-compose run'
|
|
||||||
alias dcstop='docker-compose stop'
|
|
||||||
alias dcup='docker-compose up'
|
|
||||||
alias dcdn='docker-compose down'
|
|
||||||
alias dcl='docker-compose logs'
|
|
||||||
alias dclf='docker-compose logs -f'
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Aliases for OS
|
|
||||||
if type pacman &>/dev/null; then source ${DOTCFGD}/aliases/os/archlinux.zsh; fi
|
|
||||||
if type apt-get &>/dev/null; then source ${DOTCFGD}/aliases/os/debian.zsh; fi
|
|
|
@ -1,136 +0,0 @@
|
||||||
if (( $+commands[yaourt] )); then
|
|
||||||
alias yaconf='yaourt -C'
|
|
||||||
alias yaupg='yaourt -Syua'
|
|
||||||
alias yasu='yaourt -Syua --noconfirm'
|
|
||||||
alias yain='yaourt -S'
|
|
||||||
alias yains='yaourt -U'
|
|
||||||
alias yare='yaourt -R'
|
|
||||||
alias yarem='yaourt -Rns'
|
|
||||||
alias yarep='yaourt -Si'
|
|
||||||
alias yareps='yaourt -Ss'
|
|
||||||
alias yaloc='yaourt -Qi'
|
|
||||||
alias yalocs='yaourt -Qs'
|
|
||||||
alias yalst='yaourt -Qe'
|
|
||||||
alias yaorph='yaourt -Qtd'
|
|
||||||
alias yainsd='yaourt -S --asdeps'
|
|
||||||
alias yamir='yaourt -Syy'
|
|
||||||
|
|
||||||
if (( $+commands[abs] && $+commands[aur] )); then
|
|
||||||
alias yaupd='yaourt -Sy && sudo abs && sudo aur'
|
|
||||||
elif (( $+commands[abs] )); then
|
|
||||||
alias yaupd='yaourt -Sy && sudo abs'
|
|
||||||
elif (( $+commands[aur] )); then
|
|
||||||
alias yaupd='yaourt -Sy && sudo aur'
|
|
||||||
else
|
|
||||||
alias yaupd='yaourt -Sy'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( $+commands[pacaur] )); then
|
|
||||||
alias paupg='pacaur -Syua'
|
|
||||||
alias pasu='pacaur -Syua --noconfirm'
|
|
||||||
alias pain='pacaur -S'
|
|
||||||
alias pains='pacaur -U'
|
|
||||||
alias pare='pacaur -R'
|
|
||||||
alias parem='pacaur -Rns'
|
|
||||||
alias parep='pacaur -Si'
|
|
||||||
alias pareps='pacaur -Ss'
|
|
||||||
alias paloc='pacaur -Qi'
|
|
||||||
alias palocs='pacaur -Qs'
|
|
||||||
alias palst='pacaur -Qe'
|
|
||||||
alias paorph='pacaur -Qtd'
|
|
||||||
alias painsd='pacaur -S --asdeps'
|
|
||||||
alias pamir='pacaur -Syy'
|
|
||||||
|
|
||||||
if (( $+commands[abs] && $+commands[aur] )); then
|
|
||||||
alias paupd='pacaur -Sy && sudo abs && sudo aur'
|
|
||||||
elif (( $+commands[abs] )); then
|
|
||||||
alias paupd='pacaur -Sy && sudo abs'
|
|
||||||
elif (( $+commands[aur] )); then
|
|
||||||
alias paupd='pacaur -Sy && sudo aur'
|
|
||||||
else
|
|
||||||
alias paupd='pacaur -Sy'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( $+commands[pacaur] )); then
|
|
||||||
upgrade() {
|
|
||||||
pacaur -Syu
|
|
||||||
}
|
|
||||||
elif (( $+commands[yaourt] )); then
|
|
||||||
upgrade() {
|
|
||||||
yaourt -Syu
|
|
||||||
}
|
|
||||||
else
|
|
||||||
upgrade() {
|
|
||||||
sudo pacman -Syu
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Pacman - https://wiki.archlinux.org/index.php/Pacman_Tips
|
|
||||||
alias pacupg='sudo pacman -Syu'
|
|
||||||
alias pacin='sudo pacman -S'
|
|
||||||
alias pacins='sudo pacman -U'
|
|
||||||
alias pacre='sudo pacman -R'
|
|
||||||
alias pacrem='sudo pacman -Rns'
|
|
||||||
alias pacrep='pacman -Si'
|
|
||||||
alias pacreps='pacman -Ss'
|
|
||||||
alias pacloc='pacman -Qi'
|
|
||||||
alias paclocs='pacman -Qs'
|
|
||||||
alias pacinsd='sudo pacman -S --asdeps'
|
|
||||||
alias pacmir='sudo pacman -Syy'
|
|
||||||
alias paclsorphans='sudo pacman -Qdt'
|
|
||||||
alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)'
|
|
||||||
alias pacfileupg='sudo pacman -Fy'
|
|
||||||
alias pacfiles='pacman tFs'
|
|
||||||
|
|
||||||
if (( $+commands[abs] && $+commands[aur] )); then
|
|
||||||
alias pacupd='sudo pacman -Sy && sudo abs && sudo aur'
|
|
||||||
elif (( $+commands[abs] )); then
|
|
||||||
alias pacupd='sudo pacman -Sy && sudo abs'
|
|
||||||
elif (( $+commands[aur] )); then
|
|
||||||
alias pacupd='sudo pacman -Sy && sudo aur'
|
|
||||||
else
|
|
||||||
alias pacupd='sudo pacman -Sy'
|
|
||||||
fi
|
|
||||||
|
|
||||||
paclist() {
|
|
||||||
# Source: https://bbs.archlinux.org/viewtopic.php?id=93683
|
|
||||||
LC_ALL=C pacman -Qei $(pacman -Qu | cut -d " " -f 1) | \
|
|
||||||
awk 'BEGIN {FS=":"} /^Name/{printf("\033[1;36m%s\033[1;37m", $2)} /^Description/{print $2}'
|
|
||||||
}
|
|
||||||
|
|
||||||
pacdisowned() {
|
|
||||||
emulate -L zsh
|
|
||||||
|
|
||||||
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
|
|
||||||
db=$tmp/db
|
|
||||||
fs=$tmp/fs
|
|
||||||
|
|
||||||
mkdir "$tmp"
|
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
|
||||||
|
|
||||||
pacman -Qlq | sort -u > "$db"
|
|
||||||
|
|
||||||
find /bin /etc /lib /sbin /usr ! -name lost+found \
|
|
||||||
\( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
|
|
||||||
|
|
||||||
comm -23 "$fs" "$db"
|
|
||||||
}
|
|
||||||
|
|
||||||
pacmanallkeys() {
|
|
||||||
emulate -L zsh
|
|
||||||
curl -s https://www.archlinux.org/people/{developers,trustedusers}/ | \
|
|
||||||
awk -F\" '(/pgp.mit.edu/) { sub(/.*search=0x/,""); print $1}' | \
|
|
||||||
xargs sudo pacman-key --recv-keys
|
|
||||||
}
|
|
||||||
|
|
||||||
pacmansignkeys() {
|
|
||||||
emulate -L zsh
|
|
||||||
for key in $*; do
|
|
||||||
sudo pacman-key --recv-keys $key
|
|
||||||
sudo pacman-key --lsign-key $key
|
|
||||||
printf 'trust\n3\n' | sudo gpg --homedir /etc/pacman.d/gnupg \
|
|
||||||
--no-permission-warning --command-fd 0 --edit-key $key
|
|
||||||
done
|
|
||||||
}
|
|
|
@ -1,230 +0,0 @@
|
||||||
# Authors:
|
|
||||||
# https://github.com/AlexBio
|
|
||||||
# https://github.com/dbb
|
|
||||||
# https://github.com/Mappleconfusers
|
|
||||||
#
|
|
||||||
# Debian-related zsh aliases and functions for zsh
|
|
||||||
|
|
||||||
# Use aptitude if installed, or apt-get if not.
|
|
||||||
# You can just set apt_pref='apt-get' to override it.
|
|
||||||
if [[ -e $( which -p aptitude 2>&1 ) ]]; then
|
|
||||||
apt_pref='aptitude'
|
|
||||||
apt_upgr='safe-upgrade'
|
|
||||||
else
|
|
||||||
apt_pref='apt-get'
|
|
||||||
apt_upgr='upgrade'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use sudo by default if it's installed
|
|
||||||
if [[ -e $( which -p sudo 2>&1 ) ]]; then
|
|
||||||
use_sudo=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Aliases ###################################################################
|
|
||||||
# These are for more obscure uses of apt-get and aptitude that aren't covered
|
|
||||||
# below.
|
|
||||||
alias age='apt-get'
|
|
||||||
alias api='aptitude'
|
|
||||||
|
|
||||||
# Some self-explanatory aliases
|
|
||||||
alias acs="apt-cache search"
|
|
||||||
alias aps='aptitude search'
|
|
||||||
alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
|
|
||||||
--no-gui --disable-columns search" # search package
|
|
||||||
|
|
||||||
# apt-file
|
|
||||||
alias afs='apt-file search --regexp'
|
|
||||||
|
|
||||||
|
|
||||||
# These are apt-get only
|
|
||||||
alias asrc='apt-get source'
|
|
||||||
alias app='apt-cache policy'
|
|
||||||
|
|
||||||
# superuser operations ######################################################
|
|
||||||
if [[ $use_sudo -eq 1 ]]; then
|
|
||||||
# commands using sudo #######
|
|
||||||
alias aac='sudo $apt_pref autoclean'
|
|
||||||
alias abd='sudo $apt_pref build-dep'
|
|
||||||
alias ac='sudo $apt_pref clean'
|
|
||||||
alias ad='sudo $apt_pref update'
|
|
||||||
alias adg='sudo $apt_pref update && sudo $apt_pref $apt_upgr'
|
|
||||||
alias adu='sudo $apt_pref update && sudo $apt_pref dist-upgrade'
|
|
||||||
alias afu='sudo apt-file update'
|
|
||||||
alias ag='sudo $apt_pref $apt_upgr'
|
|
||||||
alias ai='sudo $apt_pref install'
|
|
||||||
# Install all packages given on the command line while using only the first word of each line:
|
|
||||||
# acs ... | ail
|
|
||||||
alias ail="sed -e 's/ */ /g' -e 's/ *//' | cut -s -d ' ' -f 1 | "' xargs sudo $apt_pref install'
|
|
||||||
alias ap='sudo $apt_pref purge'
|
|
||||||
alias ar='sudo $apt_pref remove'
|
|
||||||
|
|
||||||
# apt-get only
|
|
||||||
alias ads='sudo apt-get dselect-upgrade'
|
|
||||||
|
|
||||||
# Install all .deb files in the current directory.
|
|
||||||
# Warning: you will need to put the glob in single quotes if you use:
|
|
||||||
# glob_subst
|
|
||||||
alias dia='sudo dpkg -i ./*.deb'
|
|
||||||
alias di='sudo dpkg -i'
|
|
||||||
|
|
||||||
# Remove ALL kernel images and headers EXCEPT the one in use
|
|
||||||
alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
|
|
||||||
?not(~n`uname -r`))'
|
|
||||||
|
|
||||||
|
|
||||||
# commands using su #########
|
|
||||||
else
|
|
||||||
alias aac='su -ls \'$apt_pref autoclean\' root'
|
|
||||||
abd() {
|
|
||||||
cmd="su -lc '$apt_pref build-dep $@' root"
|
|
||||||
print "$cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
}
|
|
||||||
alias ac='su -ls \'$apt_pref clean\' root'
|
|
||||||
alias ad='su -lc \'$apt_pref update\' root'
|
|
||||||
alias adg='su -lc \'$apt_pref update && aptitude $apt_upgr\' root'
|
|
||||||
alias adu='su -lc \'$apt_pref update && aptitude dist-upgrade\' root'
|
|
||||||
alias afu='su -lc "apt-file update"'
|
|
||||||
alias ag='su -lc \'$apt_pref $apt_upgr\' root'
|
|
||||||
ai() {
|
|
||||||
cmd="su -lc 'aptitude -P install $@' root"
|
|
||||||
print "$cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
}
|
|
||||||
ap() {
|
|
||||||
cmd="su -lc '$apt_pref -P purge $@' root"
|
|
||||||
print "$cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
}
|
|
||||||
ar() {
|
|
||||||
cmd="su -lc '$apt_pref -P remove $@' root"
|
|
||||||
print "$cmd"
|
|
||||||
eval "$cmd"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install all .deb files in the current directory
|
|
||||||
# Assumes glob_subst is off
|
|
||||||
alias dia='su -lc "dpkg -i ./*.deb" root'
|
|
||||||
alias di='su -lc "dpkg -i" root'
|
|
||||||
|
|
||||||
# Remove ALL kernel images and headers EXCEPT the one in use
|
|
||||||
alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \
|
|
||||||
?not(~n`uname -r`))'\'' root'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Completion ################################################################
|
|
||||||
|
|
||||||
#
|
|
||||||
# Registers a compdef for $1 that calls $apt_pref with the commands $2
|
|
||||||
# To do that it creates a new completion function called _apt_pref_$2
|
|
||||||
#
|
|
||||||
apt_pref_compdef() {
|
|
||||||
local f fb
|
|
||||||
f="_apt_pref_${2}"
|
|
||||||
|
|
||||||
eval "function ${f}() {
|
|
||||||
shift words;
|
|
||||||
service=\"\$apt_pref\";
|
|
||||||
words=(\"\$apt_pref\" '$2' \$words);
|
|
||||||
((CURRENT++))
|
|
||||||
test \"\${apt_pref}\" = 'aptitude' && _aptitude || _apt
|
|
||||||
}"
|
|
||||||
|
|
||||||
compdef "$f" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
apt_pref_compdef aac "autoclean"
|
|
||||||
apt_pref_compdef abd "build-dep"
|
|
||||||
apt_pref_compdef ac "clean"
|
|
||||||
apt_pref_compdef ad "update"
|
|
||||||
apt_pref_compdef afu "update"
|
|
||||||
apt_pref_compdef ag "$apt_upgr"
|
|
||||||
apt_pref_compdef ai "install"
|
|
||||||
apt_pref_compdef ail "install"
|
|
||||||
apt_pref_compdef ap "purge"
|
|
||||||
apt_pref_compdef ar "remove"
|
|
||||||
apt_pref_compdef ads "dselect-upgrade"
|
|
||||||
|
|
||||||
# Misc. #####################################################################
|
|
||||||
# print all installed packages
|
|
||||||
alias allpkgs='aptitude search -F "%p" --disable-columns ~i'
|
|
||||||
|
|
||||||
# Create a basic .deb package
|
|
||||||
alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
|
|
||||||
|
|
||||||
|
|
||||||
# Functions #################################################################
|
|
||||||
# create a simple script that can be used to 'duplicate' a system
|
|
||||||
apt-copy() {
|
|
||||||
print '#!/bin/sh'"\n" > apt-copy.sh
|
|
||||||
|
|
||||||
cmd='$apt_pref install'
|
|
||||||
|
|
||||||
for p in ${(f)"$(aptitude search -F "%p" --disable-columns \~i)"}; {
|
|
||||||
cmd="${cmd} ${p}"
|
|
||||||
}
|
|
||||||
|
|
||||||
print $cmd "\n" >> apt-copy.sh
|
|
||||||
|
|
||||||
chmod +x apt-copy.sh
|
|
||||||
}
|
|
||||||
|
|
||||||
# Prints apt history
|
|
||||||
# Usage:
|
|
||||||
# apt-history install
|
|
||||||
# apt-history upgrade
|
|
||||||
# apt-history remove
|
|
||||||
# apt-history rollback
|
|
||||||
# apt-history list
|
|
||||||
# Based On: http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
|
|
||||||
apt-history () {
|
|
||||||
case "$1" in
|
|
||||||
install)
|
|
||||||
zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
|
|
||||||
;;
|
|
||||||
upgrade|remove)
|
|
||||||
zgrep --no-filename $1 $(ls -rt /var/log/dpkg*)
|
|
||||||
;;
|
|
||||||
rollback)
|
|
||||||
zgrep --no-filename upgrade $(ls -rt /var/log/dpkg*) | \
|
|
||||||
grep "$2" -A10000000 | \
|
|
||||||
grep "$3" -B10000000 | \
|
|
||||||
awk '{print $4"="$5}'
|
|
||||||
;;
|
|
||||||
list)
|
|
||||||
zgrep --no-filename '' $(ls -rt /var/log/dpkg*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Parameters:"
|
|
||||||
echo " install - Lists all packages that have been installed."
|
|
||||||
echo " upgrade - Lists all packages that have been upgraded."
|
|
||||||
echo " remove - Lists all packages that have been removed."
|
|
||||||
echo " rollback - Lists rollback information."
|
|
||||||
echo " list - Lists all contains of dpkg logs."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Kernel-package building shortcut
|
|
||||||
kerndeb () {
|
|
||||||
# temporarily unset MAKEFLAGS ( '-j3' will fail )
|
|
||||||
MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
|
|
||||||
print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
|
|
||||||
appendage='-custom' # this shows up in $ (uname -r )
|
|
||||||
revision=$(date +"%Y%m%d") # this shows up in the .deb file name
|
|
||||||
|
|
||||||
make-kpkg clean
|
|
||||||
|
|
||||||
time fakeroot make-kpkg --append-to-version "$appendage" --revision \
|
|
||||||
"$revision" kernel_image kernel_headers
|
|
||||||
}
|
|
||||||
|
|
||||||
# List packages by size
|
|
||||||
function apt-list-packages {
|
|
||||||
dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | \
|
|
||||||
grep -v deinstall | \
|
|
||||||
sort -n | \
|
|
||||||
awk '{print $1" "$2}'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
user_commands=(
|
|
||||||
list-units is-active status show help list-unit-files
|
|
||||||
is-enabled list-jobs show-environment cat list-timers)
|
|
||||||
|
|
||||||
sudo_commands=(
|
|
||||||
start stop reload restart try-restart isolate kill
|
|
||||||
reset-failed enable disable reenable preset mask unmask
|
|
||||||
link load cancel set-environment unset-environment
|
|
||||||
edit daemon-reload)
|
|
||||||
|
|
||||||
for c in $user_commands; do; alias sc-$c="systemctl $c"; done
|
|
||||||
for c in $sudo_commands; do; alias sc-$c="sudo systemctl $c"; done
|
|
||||||
|
|
||||||
alias sc-enable-now="sc-enable --now"
|
|
||||||
alias sc-disable-now="sc-disable --now"
|
|
||||||
alias sc-mask-now="sc-mask --now"
|
|
|
@ -1,24 +0,0 @@
|
||||||
# For Dotfiles
|
|
||||||
export DOTFLS="${HOME}/dotfiles"
|
|
||||||
export DOTLIB="${DOTFLS}/lib"
|
|
||||||
export DOTBIN="${DOTFLS}/bin"
|
|
||||||
export DOTCFG="${DOTFLS}/cfg"
|
|
||||||
export DOTCFGD="${DOTCFG}/zsh/cfg.d"
|
|
||||||
|
|
||||||
# Path
|
|
||||||
path+=(${DOTBIN})
|
|
||||||
path+=(/opt/android-sdk/build-tools/26.0.1)
|
|
||||||
path+=(${HOME}/.gem/ruby/2.4.0/bin)
|
|
||||||
path+=(${DOTLIB}/welder/bin)
|
|
||||||
path+=(${DOTLIB}/basher/bin)
|
|
||||||
export PATH
|
|
||||||
|
|
||||||
# Editor Setting
|
|
||||||
export EDITOR='vim'
|
|
||||||
|
|
||||||
# Completions Paths
|
|
||||||
fpath+=(${DOTLIB}/completions/src)
|
|
||||||
fpath+=(${DOTLIB}/local)
|
|
||||||
|
|
||||||
# Reload all Prompts
|
|
||||||
autoload -U promptinit && promptinit
|
|
|
@ -1,2 +0,0 @@
|
||||||
[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
|
|
||||||
[[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
|
|
|
@ -1 +0,0 @@
|
||||||
eval `dircolors ${DOTCFG}/dir/cfg`
|
|
|
@ -1,72 +0,0 @@
|
||||||
alias x=extract
|
|
||||||
|
|
||||||
extract() {
|
|
||||||
local remove_archive
|
|
||||||
local success
|
|
||||||
local extract_dir
|
|
||||||
|
|
||||||
if (( $# == 0 )); then
|
|
||||||
cat <<-'EOF' >&2
|
|
||||||
Usage: extract [-option] [file ...]
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-r, --remove Remove archive.
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
remove_archive=1
|
|
||||||
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
|
|
||||||
remove_archive=0
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
|
|
||||||
while (( $# > 0 )); do
|
|
||||||
if [[ ! -f "$1" ]]; then
|
|
||||||
echo "extract: '$1' is not a valid file" >&2
|
|
||||||
shift
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
success=0
|
|
||||||
extract_dir="${1:t:r}"
|
|
||||||
case "$1" in
|
|
||||||
(*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
|
|
||||||
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
|
|
||||||
(*.tar.xz|*.txz)
|
|
||||||
tar --xz --help &> /dev/null \
|
|
||||||
&& tar --xz -xvf "$1" \
|
|
||||||
|| xzcat "$1" | tar xvf - ;;
|
|
||||||
(*.tar.zma|*.tlz)
|
|
||||||
tar --lzma --help &> /dev/null \
|
|
||||||
&& tar --lzma -xvf "$1" \
|
|
||||||
|| lzcat "$1" | tar xvf - ;;
|
|
||||||
(*.tar) tar xvf "$1" ;;
|
|
||||||
(*.gz) (( $+commands[pigz] )) && pigz -d "$1" || gunzip "$1" ;;
|
|
||||||
(*.bz2) bunzip2 "$1" ;;
|
|
||||||
(*.xz) unxz "$1" ;;
|
|
||||||
(*.lzma) unlzma "$1" ;;
|
|
||||||
(*.Z) uncompress "$1" ;;
|
|
||||||
(*.zip|*.war|*.jar|*.sublime-package|*.ipsw|*.xpi|*.apk) unzip "$1" -d $extract_dir ;;
|
|
||||||
(*.rar) unrar x -ad "$1" ;;
|
|
||||||
(*.7z) 7za x "$1" ;;
|
|
||||||
(*.deb)
|
|
||||||
mkdir -p "$extract_dir/control"
|
|
||||||
mkdir -p "$extract_dir/data"
|
|
||||||
cd "$extract_dir"; ar vx "../${1}" > /dev/null
|
|
||||||
cd control; tar xzvf ../control.tar.gz
|
|
||||||
cd ../data; extract ../data.tar.*
|
|
||||||
cd ..; rm *.tar.* debian-binary
|
|
||||||
cd ..
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
echo "extract: '$1' cannot be extracted" >&2
|
|
||||||
success=1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
(( success = $success > 0 ? $success : $? ))
|
|
||||||
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Fix MobaXterm Home/End key with ZSH
|
|
||||||
bindkey '^[[H' beginning-of-line
|
|
||||||
bindkey '^[[F' end-of-line
|
|
|
@ -1,2 +0,0 @@
|
||||||
[[ $- == *i* ]] && source "/usr/share/fzf/completion.zsh" 2> /dev/null
|
|
||||||
source "/usr/share/fzf/key-bindings.zsh"
|
|
|
@ -1,242 +0,0 @@
|
||||||
# Query/use custom command for `git`.
|
|
||||||
zstyle -s ":vcs_info:git:*:-all-" "command" _omz_git_git_cmd
|
|
||||||
: ${_omz_git_git_cmd:=git}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Functions
|
|
||||||
#
|
|
||||||
|
|
||||||
# The name of the current branch
|
|
||||||
# Back-compatibility wrapper for when this function was defined here in
|
|
||||||
# the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
|
|
||||||
# to fix the core -> git plugin dependency.
|
|
||||||
function current_branch() {
|
|
||||||
git_current_branch
|
|
||||||
}
|
|
||||||
# The list of remotes
|
|
||||||
function current_repository() {
|
|
||||||
if ! $_omz_git_git_cmd rev-parse --is-inside-work-tree &> /dev/null; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
echo $($_omz_git_git_cmd remote -v | cut -d':' -f 2)
|
|
||||||
}
|
|
||||||
# Pretty log messages
|
|
||||||
function _git_log_prettily(){
|
|
||||||
if ! [ -z $1 ]; then
|
|
||||||
git log --pretty=$1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
# Warn if the current branch is a WIP
|
|
||||||
function work_in_progress() {
|
|
||||||
if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
|
|
||||||
echo "WIP!!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Aliases
|
|
||||||
# (sorted alphabetically)
|
|
||||||
#
|
|
||||||
|
|
||||||
alias g='git'
|
|
||||||
|
|
||||||
alias ga='git add'
|
|
||||||
alias gaa='git add --all'
|
|
||||||
alias gapa='git add --patch'
|
|
||||||
alias gau='git add --update'
|
|
||||||
|
|
||||||
alias gb='git branch'
|
|
||||||
alias gba='git branch -a'
|
|
||||||
alias gbd='git branch -d'
|
|
||||||
alias gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
|
|
||||||
alias gbl='git blame -b -w'
|
|
||||||
alias gbnm='git branch --no-merged'
|
|
||||||
alias gbr='git branch --remote'
|
|
||||||
alias gbs='git bisect'
|
|
||||||
alias gbsb='git bisect bad'
|
|
||||||
alias gbsg='git bisect good'
|
|
||||||
alias gbsr='git bisect reset'
|
|
||||||
alias gbss='git bisect start'
|
|
||||||
|
|
||||||
alias gc='git commit -v'
|
|
||||||
alias gc!='git commit -v --amend'
|
|
||||||
alias gcn!='git commit -v --no-edit --amend'
|
|
||||||
alias gca='git commit -v -a'
|
|
||||||
alias gca!='git commit -v -a --amend'
|
|
||||||
alias gcan!='git commit -v -a --no-edit --amend'
|
|
||||||
alias gcans!='git commit -v -a -s --no-edit --amend'
|
|
||||||
alias gcam='git commit -a -m'
|
|
||||||
alias gcsm='git commit -s -m'
|
|
||||||
alias gcb='git checkout -b'
|
|
||||||
alias gcf='git config --list'
|
|
||||||
alias gcl='git clone --recursive'
|
|
||||||
alias gclean='git clean -fd'
|
|
||||||
alias gpristine='git reset --hard && git clean -dfx'
|
|
||||||
alias gcm='git checkout master'
|
|
||||||
alias gcd='git checkout develop'
|
|
||||||
alias gcmsg='git commit -m'
|
|
||||||
alias gco='git checkout'
|
|
||||||
alias gcount='git shortlog -sn'
|
|
||||||
compdef _git gcount
|
|
||||||
alias gcp='git cherry-pick'
|
|
||||||
alias gcpa='git cherry-pick --abort'
|
|
||||||
alias gcpc='git cherry-pick --continue'
|
|
||||||
alias gcs='git commit -S'
|
|
||||||
|
|
||||||
alias gd='git diff'
|
|
||||||
alias gdca='git diff --cached'
|
|
||||||
alias gdct='git describe --tags `git rev-list --tags --max-count=1`'
|
|
||||||
alias gdt='git diff-tree --no-commit-id --name-only -r'
|
|
||||||
alias gdw='git diff --word-diff'
|
|
||||||
|
|
||||||
gdv() { git diff -w "$@" | view - }
|
|
||||||
compdef _git gdv=git-diff
|
|
||||||
|
|
||||||
alias gf='git fetch'
|
|
||||||
alias gfa='git fetch --all --prune'
|
|
||||||
alias gfo='git fetch origin'
|
|
||||||
|
|
||||||
function gfg() { git ls-files | grep $@ }
|
|
||||||
compdef _grep gfg
|
|
||||||
|
|
||||||
alias gg='git gui citool'
|
|
||||||
alias gga='git gui citool --amend'
|
|
||||||
|
|
||||||
ggf() {
|
|
||||||
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
|
|
||||||
git push --force origin "${b:=$1}"
|
|
||||||
}
|
|
||||||
compdef _git ggf=git-checkout
|
|
||||||
|
|
||||||
ggl() {
|
|
||||||
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
|
|
||||||
git pull origin "${*}"
|
|
||||||
else
|
|
||||||
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
|
|
||||||
git pull origin "${b:=$1}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
compdef _git ggl=git-checkout
|
|
||||||
|
|
||||||
ggp() {
|
|
||||||
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
|
|
||||||
git push origin "${*}"
|
|
||||||
else
|
|
||||||
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
|
|
||||||
git push origin "${b:=$1}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
compdef _git ggp=git-checkout
|
|
||||||
|
|
||||||
ggpnp() {
|
|
||||||
if [[ "$#" == 0 ]]; then
|
|
||||||
ggl && ggp
|
|
||||||
else
|
|
||||||
ggl "${*}" && ggp "${*}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
compdef _git ggpnp=git-checkout
|
|
||||||
|
|
||||||
ggu() {
|
|
||||||
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
|
|
||||||
git pull --rebase origin "${b:=$1}"
|
|
||||||
}
|
|
||||||
compdef _git ggu=git-checkout
|
|
||||||
|
|
||||||
alias ggpur='ggu'
|
|
||||||
compdef _git ggpur=git-checkout
|
|
||||||
|
|
||||||
alias ggpull='git pull origin $(git_current_branch)'
|
|
||||||
compdef _git ggpull=git-checkout
|
|
||||||
|
|
||||||
alias ggpush='git push origin $(git_current_branch)'
|
|
||||||
compdef _git ggpush=git-checkout
|
|
||||||
|
|
||||||
alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
|
|
||||||
alias gpsup='git push --set-upstream origin $(git_current_branch)'
|
|
||||||
|
|
||||||
alias ghh='git help'
|
|
||||||
|
|
||||||
alias gignore='git update-index --assume-unchanged'
|
|
||||||
alias gignored='git ls-files -v | grep "^[[:lower:]]"'
|
|
||||||
alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
|
|
||||||
compdef _git git-svn-dcommit-push=git
|
|
||||||
|
|
||||||
alias gk='\gitk --all --branches'
|
|
||||||
compdef _git gk='gitk'
|
|
||||||
alias gke='\gitk --all $(git log -g --pretty=%h)'
|
|
||||||
compdef _git gke='gitk'
|
|
||||||
|
|
||||||
alias gl='git pull'
|
|
||||||
alias glg='git log --stat'
|
|
||||||
alias glgp='git log --stat -p'
|
|
||||||
alias glgg='git log --graph'
|
|
||||||
alias glgga='git log --graph --decorate --all'
|
|
||||||
alias glgm='git log --graph --max-count=10'
|
|
||||||
alias glo='git log --oneline --decorate'
|
|
||||||
alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
|
||||||
alias glola="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
|
|
||||||
alias glog='git log --oneline --decorate --graph'
|
|
||||||
alias gloga='git log --oneline --decorate --graph --all'
|
|
||||||
alias glp="_git_log_prettily"
|
|
||||||
compdef _git glp=git-log
|
|
||||||
|
|
||||||
alias gm='git merge'
|
|
||||||
alias gmom='git merge origin/master'
|
|
||||||
alias gmt='git mergetool --no-prompt'
|
|
||||||
alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
|
|
||||||
alias gmum='git merge upstream/master'
|
|
||||||
|
|
||||||
alias gp='git push'
|
|
||||||
alias gpd='git push --dry-run'
|
|
||||||
alias gpoat='git push origin --all && git push origin --tags'
|
|
||||||
compdef _git gpoat=git-push
|
|
||||||
alias gpu='git push upstream'
|
|
||||||
alias gpv='git push -v'
|
|
||||||
|
|
||||||
alias gr='git remote'
|
|
||||||
alias gra='git remote add'
|
|
||||||
alias grb='git rebase'
|
|
||||||
alias grba='git rebase --abort'
|
|
||||||
alias grbc='git rebase --continue'
|
|
||||||
alias grbi='git rebase -i'
|
|
||||||
alias grbm='git rebase master'
|
|
||||||
alias grbs='git rebase --skip'
|
|
||||||
alias grh='git reset HEAD'
|
|
||||||
alias grhh='git reset HEAD --hard'
|
|
||||||
alias grmv='git remote rename'
|
|
||||||
alias grrm='git remote remove'
|
|
||||||
alias grset='git remote set-url'
|
|
||||||
alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
|
|
||||||
alias gru='git reset --'
|
|
||||||
alias grup='git remote update'
|
|
||||||
alias grv='git remote -v'
|
|
||||||
|
|
||||||
alias gsb='git status -sb'
|
|
||||||
alias gsd='git svn dcommit'
|
|
||||||
alias gsi='git submodule init'
|
|
||||||
alias gsps='git show --pretty=short --show-signature'
|
|
||||||
alias gsr='git svn rebase'
|
|
||||||
alias gss='git status -s'
|
|
||||||
alias gst='git status'
|
|
||||||
alias gsta='git stash save'
|
|
||||||
alias gstaa='git stash apply'
|
|
||||||
alias gstc='git stash clear'
|
|
||||||
alias gstd='git stash drop'
|
|
||||||
alias gstl='git stash list'
|
|
||||||
alias gstp='git stash pop'
|
|
||||||
alias gsts='git stash show --text'
|
|
||||||
alias gsu='git submodule update'
|
|
||||||
|
|
||||||
alias gts='git tag -s'
|
|
||||||
alias gtv='git tag | sort -V'
|
|
||||||
|
|
||||||
alias gunignore='git update-index --no-assume-unchanged'
|
|
||||||
alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
|
|
||||||
alias gup='git pull --rebase'
|
|
||||||
alias gupv='git pull --rebase -v'
|
|
||||||
alias glum='git pull upstream master'
|
|
||||||
|
|
||||||
alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
|
|
||||||
alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "--wip-- [skip ci]"'
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
export ZSH_PLUGIN_GITIGNORE_PATH=$(dirname $0)
|
|
||||||
export ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS=${DOTLIB}/gitignore
|
|
||||||
|
|
||||||
function gie () {
|
|
||||||
${EDITOR} .gitignore
|
|
||||||
}
|
|
||||||
|
|
||||||
function gi() {
|
|
||||||
if [[ $# -eq 0 ]]; then
|
|
||||||
cat .gitignore
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
for t in $*; do
|
|
||||||
get_gitignore_template $t
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function gii() {
|
|
||||||
if [[ $# -eq 0 ]]; then
|
|
||||||
cat .gitignore
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# if NOCLOBBER option is setted
|
|
||||||
gi $* >>! .gitignore
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_gitignore_template() {
|
|
||||||
for tpath in ${(@s/:/)ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS}; do;
|
|
||||||
local file=$(find $tpath -iname "$1.gitignore")
|
|
||||||
if [[ ! -z $file ]]; then
|
|
||||||
comment=$(basename $file | sed -e 's/.gitignore$//')
|
|
||||||
echo
|
|
||||||
echo "### $comment"
|
|
||||||
cat $file
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done;
|
|
||||||
}
|
|
||||||
|
|
||||||
_gitignore_get_template_list() {
|
|
||||||
(for tpath in ${(@s/:/)ZSH_PLUGIN_GITIGNORE_TEMPLATE_PATHS}; do; find $tpath -type f -name "*.gitignore"; done) \
|
|
||||||
| xargs -n 1 basename \
|
|
||||||
| sed -e 's/.gitignore$//' -e 's/\(.*\)/\L\1/' \
|
|
||||||
| sort -u
|
|
||||||
}
|
|
||||||
|
|
||||||
_gitignore () {
|
|
||||||
compset -P '*,'
|
|
||||||
compadd -S '' `_gitignore_get_template_list`
|
|
||||||
}
|
|
||||||
|
|
||||||
compdef _gitignore gi
|
|
||||||
compdef _gitignore gii
|
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
#
|
|
||||||
# Aliases
|
|
||||||
#
|
|
||||||
|
|
||||||
alias ta='tmux attach -t'
|
|
||||||
alias tad='tmux attach -d -t'
|
|
||||||
alias ts='tmux new-session -s'
|
|
||||||
alias tl='tmux list-sessions'
|
|
||||||
alias tksv='tmux kill-server'
|
|
||||||
alias tkss='tmux kill-session -t'
|
|
||||||
|
|
||||||
# Only run if tmux is actually installed
|
|
||||||
if which tmux &> /dev/null
|
|
||||||
then
|
|
||||||
# Configuration variables
|
|
||||||
#
|
|
||||||
# Automatically start tmux
|
|
||||||
[[ -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
|
|
||||||
# Automatically connect to a previous session if it exists
|
|
||||||
[[ -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
|
|
||||||
# Set term to screen or screen-256color based on current terminal support
|
|
||||||
[[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true
|
|
||||||
# Set '-CC' option for iTerm2 tmux integration
|
|
||||||
[[ -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"
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
|
|
||||||
# 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" ]]
|
|
||||||
then
|
|
||||||
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR
|
|
||||||
else
|
|
||||||
export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set the correct local config file to use.
|
|
||||||
if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]]
|
|
||||||
then
|
|
||||||
#use this when they have a ~/.tmux.conf
|
|
||||||
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf"
|
|
||||||
else
|
|
||||||
#use this when they don't have a ~/.tmux.conf
|
|
||||||
export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Wrapper function for tmux.
|
|
||||||
function _zsh_tmux_plugin_run()
|
|
||||||
{
|
|
||||||
# We have other arguments, just run them
|
|
||||||
if [[ -n "$@" ]]
|
|
||||||
then
|
|
||||||
\tmux $@
|
|
||||||
# Try to connect to an existing session.
|
|
||||||
elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]]
|
|
||||||
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
|
|
||||||
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
|
|
||||||
# Just run tmux, fixing the TERM variable if requested.
|
|
||||||
else
|
|
||||||
\tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG`
|
|
||||||
[[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use the completions for tmux for our function
|
|
||||||
compdef _tmux _zsh_tmux_plugin_run
|
|
||||||
|
|
||||||
# Alias tmux to our wrapper function.
|
|
||||||
alias tmux=_zsh_tmux_plugin_run
|
|
||||||
|
|
||||||
# Autostart if not already in tmux and enabled.
|
|
||||||
if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]]
|
|
||||||
then
|
|
||||||
# Actually don't autostart if we already did and multiple autostarts are disabled.
|
|
||||||
if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]
|
|
||||||
then
|
|
||||||
export ZSH_TMUX_AUTOSTARTED=true
|
|
||||||
_zsh_tmux_plugin_run
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin."
|
|
||||||
fi
|
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
#
|
|
||||||
# Defines transfer alias and provides easy command line file and folder sharing.
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Remco Verhoef <remco@dutchcoders.io>
|
|
||||||
#
|
|
||||||
|
|
||||||
transfer() {
|
|
||||||
# check arguments
|
|
||||||
if [ $# -eq 0 ];
|
|
||||||
then
|
|
||||||
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# get temporarily filename, output is written to this file show progress can be showed
|
|
||||||
tmpfile=$( mktemp -t transferXXX )
|
|
||||||
|
|
||||||
# upload stdin or file
|
|
||||||
file=$1
|
|
||||||
|
|
||||||
if tty -s;
|
|
||||||
then
|
|
||||||
basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
|
||||||
|
|
||||||
if [ ! -e $file ];
|
|
||||||
then
|
|
||||||
echo "File $file doesn't exists."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d $file ];
|
|
||||||
then
|
|
||||||
# zip directory and transfer
|
|
||||||
zipfile=$( mktemp -t transferXXX.zip )
|
|
||||||
cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile
|
|
||||||
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile
|
|
||||||
rm -f $zipfile
|
|
||||||
else
|
|
||||||
# transfer file
|
|
||||||
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# transfer pipe
|
|
||||||
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
|
|
||||||
fi
|
|
||||||
|
|
||||||
# cat output link
|
|
||||||
cat $tmpfile
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
rm -f $tmpfile
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
__updir() {
|
|
||||||
if [[ "$1" == "/" || -z "$1" || -z "$2" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
local p="$(dirname $1)"
|
|
||||||
local a="$(basename $p)"
|
|
||||||
local b="$(basename $2)"
|
|
||||||
|
|
||||||
if [[ -z "$a" || -z "$b" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$a" == "$b"* ]]; then
|
|
||||||
echo "$p"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
__updir "$p" "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
__upnum() {
|
|
||||||
if [[ -z "$1" || -z "$2" || ! "$2" =~ ^[0-9]+$ ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
local p="$1"
|
|
||||||
local i="$2"
|
|
||||||
|
|
||||||
while (( i-- )); do
|
|
||||||
p="$(dirname $p)"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "$p"
|
|
||||||
}
|
|
||||||
|
|
||||||
_up() {
|
|
||||||
local p="$(dirname $PWD)"
|
|
||||||
local w="${COMP_WORDS[COMP_CWORD]}"
|
|
||||||
|
|
||||||
COMPREPLY=( $(IFS=';' compgen -S/ -W "${p//\//;}" -- "$w") )
|
|
||||||
}
|
|
||||||
|
|
||||||
up() {
|
|
||||||
# up one
|
|
||||||
if (( ! $# )); then
|
|
||||||
cd ..
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# up dir
|
|
||||||
local d="$(__updir "$PWD" "$1")"
|
|
||||||
|
|
||||||
if [[ -d "$d" ]]; then
|
|
||||||
cd "$d"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# up num
|
|
||||||
local n="$(__upnum "$PWD" "$1")"
|
|
||||||
|
|
||||||
if [[ -d "$n" ]]; then
|
|
||||||
cd "$n"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# fallback
|
|
||||||
if [[ $1 == - || -d $1 ]]; then
|
|
||||||
cd $1
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# usage
|
|
||||||
echo -e "usage: up [dir|num|-]\npwd: $PWD"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
autoload -U +X bashcompinit && bashcompinit
|
|
||||||
|
|
||||||
# tab-completion
|
|
||||||
complete -o nospace -F _up up
|
|
|
@ -1,137 +0,0 @@
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# FILE: zshmarks.plugin.zsh
|
|
||||||
# DESCRIPTION: oh-my-zsh plugin file.
|
|
||||||
# AUTHOR: Jocelyn Mallon
|
|
||||||
# VERSION: 1.7.0
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Set BOOKMARKS_FILE if it doesn't exist to the default.
|
|
||||||
# Allows for a user-configured BOOKMARKS_FILE.
|
|
||||||
if [[ -z $BOOKMARKS_FILE ]] ; then
|
|
||||||
export BOOKMARKS_FILE=${DOTLIB}/bookmarks
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if $BOOKMARKS_FILE is a symlink.
|
|
||||||
if [[ -L $BOOKMARKS_FILE ]]; then
|
|
||||||
BOOKMARKS_FILE=$(readlink $BOOKMARKS_FILE)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create bookmarks_file it if it doesn't exist
|
|
||||||
if [[ ! -f $BOOKMARKS_FILE ]]; then
|
|
||||||
touch $BOOKMARKS_FILE
|
|
||||||
fi
|
|
||||||
|
|
||||||
_zshmarks_move_to_trash(){
|
|
||||||
if [[ $(uname) == "Linux"* || $(uname) == "FreeBSD"* ]]; then
|
|
||||||
label=`date +%s`
|
|
||||||
mkdir -p ~/.local/share/Trash/info ~/.local/share/Trash/files
|
|
||||||
\mv "${BOOKMARKS_FILE}.bak" ~/.local/share/Trash/files/bookmarks-$label
|
|
||||||
echo "[Trash Info]
|
|
||||||
Path=/home/"$USER"/.bookmarks
|
|
||||||
DeletionDate="`date +"%Y-%m-%dT%H:%M:%S"`"
|
|
||||||
">~/.local/share/Trash/info/bookmarks-$label.trashinfo
|
|
||||||
elif [[ $(uname) = "Darwin" ]]; then
|
|
||||||
\mv "${BOOKMARKS_FILE}.bak" ~/.Trash/"bookmarks"$(date +%H-%M-%S)
|
|
||||||
else
|
|
||||||
\rm -f "${BOOKMARKS_FILE}.bak"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function bookmark() {
|
|
||||||
local bookmark_name=$1
|
|
||||||
if [[ -z $bookmark_name ]]; then
|
|
||||||
bookmark_name="${PWD##*/}"
|
|
||||||
fi
|
|
||||||
cur_dir="$(pwd)"
|
|
||||||
# Replace /home/uname with $HOME
|
|
||||||
if [[ "$cur_dir" =~ ^"$HOME"(/|$) ]]; then
|
|
||||||
cur_dir="\$HOME${cur_dir#$HOME}"
|
|
||||||
fi
|
|
||||||
# Store the bookmark as folder|name
|
|
||||||
bookmark="$cur_dir|$bookmark_name"
|
|
||||||
if [[ -z $(grep "$bookmark" $BOOKMARKS_FILE 2>/dev/null) ]]; then
|
|
||||||
echo $bookmark >> $BOOKMARKS_FILE
|
|
||||||
echo "Bookmark '$bookmark_name' saved"
|
|
||||||
else
|
|
||||||
echo "Bookmark already existed"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
__zshmarks_zgrep() {
|
|
||||||
local outvar="$1"; shift
|
|
||||||
local pattern="$1"
|
|
||||||
local filename="$2"
|
|
||||||
local file_contents="$(<"$filename")"
|
|
||||||
local file_lines; file_lines=(${(f)file_contents})
|
|
||||||
for line in "${file_lines[@]}"; do
|
|
||||||
if [[ "$line" =~ "$pattern" ]]; then
|
|
||||||
eval "$outvar=\"$line\""
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function jump() {
|
|
||||||
local bookmark_name=$1
|
|
||||||
local bookmark
|
|
||||||
if ! __zshmarks_zgrep bookmark "\\|$bookmark_name\$" "$BOOKMARKS_FILE"; then
|
|
||||||
echo "Invalid name, please provide a valid bookmark name. For example:"
|
|
||||||
echo " jump foo"
|
|
||||||
echo
|
|
||||||
echo "To bookmark a folder, go to the folder then do this (naming the bookmark 'foo'):"
|
|
||||||
echo " bookmark foo"
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
local dir="${bookmark%%|*}"
|
|
||||||
eval "cd \"${dir}\""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Show a list of the bookmarks
|
|
||||||
function showmarks() {
|
|
||||||
local bookmark_file="$(<"$BOOKMARKS_FILE")"
|
|
||||||
local bookmark_array; bookmark_array=(${(f)bookmark_file});
|
|
||||||
local bookmark_name bookmark_path bookmark_line
|
|
||||||
if [[ $# -eq 1 ]]; then
|
|
||||||
bookmark_name="*\|${1}"
|
|
||||||
bookmark_line=${bookmark_array[(r)$bookmark_name]}
|
|
||||||
bookmark_path="${bookmark_line%%|*}"
|
|
||||||
bookmark_path="${bookmark_path/\$HOME/~}"
|
|
||||||
printf "%s \n" $bookmark_path
|
|
||||||
else
|
|
||||||
for bookmark_line in $bookmark_array; do
|
|
||||||
bookmark_path="${bookmark_line%%|*}"
|
|
||||||
bookmark_path="${bookmark_path/\$HOME/~}"
|
|
||||||
bookmark_name="${bookmark_line#*|}"
|
|
||||||
printf "%s\t\t%s\n" "$bookmark_name" "$bookmark_path"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Delete a bookmark
|
|
||||||
function deletemark() {
|
|
||||||
local bookmark_name=$1
|
|
||||||
if [[ -z $bookmark_name ]]; then
|
|
||||||
printf "%s \n" "Please provide a name for your bookmark to delete. For example:"
|
|
||||||
printf "\t%s \n" "deletemark foo"
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
local bookmark_line bookmark_search
|
|
||||||
local bookmark_file="$(<"$BOOKMARKS_FILE")"
|
|
||||||
local bookmark_array; bookmark_array=(${(f)bookmark_file});
|
|
||||||
bookmark_search="*\|${bookmark_name}"
|
|
||||||
if [[ -z ${bookmark_array[(r)$bookmark_search]} ]]; then
|
|
||||||
eval "printf '%s\n' \"'${bookmark_name}' not found, skipping.\""
|
|
||||||
else
|
|
||||||
\cp "${BOOKMARKS_FILE}" "${BOOKMARKS_FILE}.bak"
|
|
||||||
bookmark_line=${bookmark_array[(r)$bookmark_search]}
|
|
||||||
bookmark_array=(${bookmark_array[@]/$bookmark_line})
|
|
||||||
eval "printf '%s\n' \"\${bookmark_array[@]}\"" >! $BOOKMARKS_FILE
|
|
||||||
_zshmarks_move_to_trash
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# Source all files
|
# Source all files
|
||||||
source ${HOME}/dotfiles/cfg/zsh/cfg.d/export
|
for file in ${HOME}/dotfiles/cfg/zsh/cfg.d/*.zsh; do source $file; done
|
||||||
for file in ${DOTCFGD}/*.zsh; do source $file; done
|
|
||||||
|
|
||||||
# Prompt
|
# Prompt
|
||||||
prompt z4rr3t
|
prompt z4rr3t
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 690a433b668348c33087d34fafe2155ebe8bb4cf
|
Subproject commit 2b7d841c01806236d26e81f512095717396ebcb8
|
Loading…
Add table
Reference in a new issue