changed directories and addet fzf to zsh
This commit is contained in:
parent
0acd581d40
commit
cb928bb0b4
428 changed files with 20659 additions and 15 deletions
48
.zsh/plugins/custom/256color.zsh
Normal file
48
.zsh/plugins/custom/256color.zsh
Normal file
|
@ -0,0 +1,48 @@
|
|||
# Copyright (c) 2014-2019, Christian Ludwig
|
||||
#
|
||||
# Set 256color terminal mode if available.
|
||||
|
||||
_zsh_256color_debug() {
|
||||
[[ -n "${ZSH_256COLOR_DEBUG}" ]] && echo "zsh-256color: $@" >&2
|
||||
}
|
||||
|
||||
_zsh_terminal_set_256color() {
|
||||
if [[ "$TERM" =~ "-256color$" ]]; then
|
||||
_zsh_256color_debug "256 color terminal already set."
|
||||
return
|
||||
fi
|
||||
|
||||
local TERM256="${TERM}-256color"
|
||||
|
||||
# Use (n-)curses binaries, if installed.
|
||||
if [[ -x "$(which toe)" ]]; then
|
||||
if toe -a | grep -E "^$TERM256" >/dev/null; then
|
||||
_zsh_256color_debug "Found $TERM256 from (n-)curses binaries."
|
||||
export TERM="$TERM256"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Search through termcap descriptions, if binaries are not installed.
|
||||
for termcaps in $TERMCAP "$HOME/.termcap" "/etc/termcap" "/etc/termcap.small"; do
|
||||
if [[ -e "$termcaps" ]] && grep -E -q "(^$TERM256|\|$TERM256)\|" "$termcaps"; then
|
||||
_zsh_256color_debug "Found $TERM256 from $termcaps."
|
||||
export TERM="$TERM256"
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
# Search through terminfo descriptions, if binaries are not installed.
|
||||
for terminfos in $TERMINFO "$HOME/.terminfo" "/etc/terminfo" "/lib/terminfo" "/usr/share/terminfo"; do
|
||||
if [[ -e "$terminfos"/$TERM[1]/"$TERM256" ||
|
||||
-e "$terminfos"/"$TERM256" ]]; then
|
||||
_zsh_256color_debug "Found $TERM256 from $terminfos."
|
||||
export TERM="$TERM256"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
_zsh_terminal_set_256color
|
||||
unset -f _zsh_terminal_set_256color
|
||||
unset -f _zsh_256color_debug
|
50
.zsh/plugins/custom/agent.zsh
Normal file
50
.zsh/plugins/custom/agent.zsh
Normal file
|
@ -0,0 +1,50 @@
|
|||
export GPG_TTY=$TTY
|
||||
|
||||
# Fix for passphrase prompt on the correct tty
|
||||
# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport
|
||||
function _gpg-agent_update-tty_preexec {
|
||||
gpg-connect-agent updatestartuptty /bye &>/dev/null
|
||||
}
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook preexec _gpg-agent_update-tty_preexec
|
||||
|
||||
# If enable-ssh-support is set, fix ssh agent integration
|
||||
if [[ $(gpgconf --list-options gpg-agent 2>/dev/null | awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then
|
||||
unset SSH_AGENT_PID
|
||||
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
|
||||
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
|
||||
fi
|
||||
fi
|
||||
|
||||
(( $+commands[keychain] )) || return
|
||||
|
||||
# Define SHORT_HOST if not defined (%m = host name up to first .)
|
||||
SHORT_HOST=${SHORT_HOST:-${(%):-%m}}
|
||||
|
||||
function {
|
||||
local agents
|
||||
local -a identities
|
||||
local -a options
|
||||
local _keychain_env_sh
|
||||
local _keychain_env_sh_gpg
|
||||
|
||||
# load agents to start.
|
||||
zstyle -s :omz:plugins:keychain agents agents
|
||||
|
||||
# load identities to manage.
|
||||
zstyle -a :omz:plugins:keychain identities identities
|
||||
|
||||
# load additional options
|
||||
zstyle -a :omz:plugins:keychain options options
|
||||
|
||||
# start keychain...
|
||||
keychain ${^options:-} --agents ${agents:-gpg} ${^identities} --host $SHORT_HOST
|
||||
|
||||
# Get the filenames to store/lookup the environment from
|
||||
_keychain_env_sh="$HOME/.keychain/$SHORT_HOST-sh"
|
||||
_keychain_env_sh_gpg="$HOME/.keychain/$SHORT_HOST-sh-gpg"
|
||||
|
||||
# Source environment settings.
|
||||
[ -f "$_keychain_env_sh" ] && . "$_keychain_env_sh"
|
||||
[ -f "$_keychain_env_sh_gpg" ] && . "$_keychain_env_sh_gpg"
|
||||
}
|
70
.zsh/plugins/custom/command-not-found.plugin.zsh
Normal file
70
.zsh/plugins/custom/command-not-found.plugin.zsh
Normal file
|
@ -0,0 +1,70 @@
|
|||
## Platforms with a built-in command-not-found handler init file
|
||||
|
||||
for file (
|
||||
# Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found
|
||||
/usr/share/doc/pkgfile/command-not-found.zsh
|
||||
# Homebrew: https://github.com/Homebrew/homebrew-command-not-found
|
||||
/opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
|
||||
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
|
||||
/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
|
||||
); do
|
||||
if [[ -r "$file" ]]; then
|
||||
source "$file"
|
||||
unset file
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
unset file
|
||||
|
||||
|
||||
## Platforms with manual command_not_found_handler() setup
|
||||
|
||||
# Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found
|
||||
if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then
|
||||
command_not_found_handler() {
|
||||
if [[ -x /usr/lib/command-not-found ]]; then
|
||||
/usr/lib/command-not-found -- "$1"
|
||||
return $?
|
||||
elif [[ -x /usr/share/command-not-found/command-not-found ]]; then
|
||||
/usr/share/command-not-found/command-not-found -- "$1"
|
||||
return $?
|
||||
else
|
||||
printf "zsh: command not found: %s\n" "$1" >&2
|
||||
return 127
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound
|
||||
if [[ -x /usr/libexec/pk-command-not-found ]]; then
|
||||
command_not_found_handler() {
|
||||
if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then
|
||||
/usr/libexec/pk-command-not-found "$@"
|
||||
return $?
|
||||
fi
|
||||
|
||||
printf "zsh: command not found: %s\n" "$1" >&2
|
||||
return 127
|
||||
}
|
||||
fi
|
||||
|
||||
# NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found
|
||||
if [[ -x /run/current-system/sw/bin/command-not-found ]]; then
|
||||
command_not_found_handler() {
|
||||
/run/current-system/sw/bin/command-not-found "$@"
|
||||
}
|
||||
fi
|
||||
|
||||
# Termux: https://github.com/termux/command-not-found
|
||||
if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then
|
||||
command_not_found_handler() {
|
||||
/data/data/com.termux/files/usr/libexec/termux/command-not-found "$1"
|
||||
}
|
||||
fi
|
||||
|
||||
# SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/
|
||||
if [[ -x /usr/bin/command-not-found ]]; then
|
||||
command_not_found_handler() {
|
||||
/usr/bin/command-not-found "$1"
|
||||
}
|
||||
fi
|
180
.zsh/plugins/custom/zsh-interactive-cd.plugin.zsh
Normal file
180
.zsh/plugins/custom/zsh-interactive-cd.plugin.zsh
Normal file
|
@ -0,0 +1,180 @@
|
|||
#!/usr/bin/env zsh
|
||||
#
|
||||
# Copyright 2017-2018 Henry Chang
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
__zic_fzf_prog() {
|
||||
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] \
|
||||
&& echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
||||
}
|
||||
|
||||
__zic_matched_subdir_list() {
|
||||
local dir length seg starts_with_dir
|
||||
if [[ "$1" == */ ]]; then
|
||||
dir="$1"
|
||||
if [[ "$dir" != / ]]; then
|
||||
dir="${dir: : -1}"
|
||||
fi
|
||||
length=$(echo -n "$dir" | wc -c)
|
||||
if [ "$dir" = "/" ]; then
|
||||
length=0
|
||||
fi
|
||||
find -L "$dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null \
|
||||
| cut -b $(( ${length} + 2 ))- | command sed '/^$/d' | while read -r line; do
|
||||
if [[ "${line[1]}" == "." ]]; then
|
||||
continue
|
||||
fi
|
||||
echo "$line"
|
||||
done
|
||||
else
|
||||
dir=$(dirname -- "$1")
|
||||
length=$(echo -n "$dir" | wc -c)
|
||||
if [ "$dir" = "/" ]; then
|
||||
length=0
|
||||
fi
|
||||
seg=$(basename -- "$1")
|
||||
starts_with_dir=$( \
|
||||
find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
|
||||
2>/dev/null | cut -b $(( ${length} + 2 ))- | command sed '/^$/d' \
|
||||
| while read -r line; do
|
||||
if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
|
||||
continue
|
||||
fi
|
||||
if [ "$zic_case_insensitive" = "true" ]; then
|
||||
if [[ "$line:u" == "$seg:u"* ]]; then
|
||||
echo "$line"
|
||||
fi
|
||||
else
|
||||
if [[ "$line" == "$seg"* ]]; then
|
||||
echo "$line"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
)
|
||||
if [ -n "$starts_with_dir" ]; then
|
||||
echo "$starts_with_dir"
|
||||
else
|
||||
find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
|
||||
2>/dev/null | cut -b $(( ${length} + 2 ))- | command sed '/^$/d' \
|
||||
| while read -r line; do
|
||||
if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
|
||||
continue
|
||||
fi
|
||||
if [ "$zic_case_insensitive" = "true" ]; then
|
||||
if [[ "$line:u" == *"$seg:u"* ]]; then
|
||||
echo "$line"
|
||||
fi
|
||||
else
|
||||
if [[ "$line" == *"$seg"* ]]; then
|
||||
echo "$line"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
__zic_fzf_bindings() {
|
||||
autoload is-at-least
|
||||
fzf=$(__zic_fzf_prog)
|
||||
|
||||
if $(is-at-least '0.21.0' $(${=fzf} --version)); then
|
||||
echo 'shift-tab:up,tab:down,bspace:backward-delete-char/eof'
|
||||
else
|
||||
echo 'shift-tab:up,tab:down'
|
||||
fi
|
||||
}
|
||||
|
||||
_zic_list_generator() {
|
||||
__zic_matched_subdir_list "${(Q)@[-1]}" | sort
|
||||
}
|
||||
|
||||
_zic_complete() {
|
||||
setopt localoptions nonomatch
|
||||
local l matches fzf tokens base
|
||||
|
||||
l=$(_zic_list_generator $@)
|
||||
|
||||
if [ -z "$l" ]; then
|
||||
zle ${__zic_default_completion:-expand-or-complete}
|
||||
return
|
||||
fi
|
||||
|
||||
fzf=$(__zic_fzf_prog)
|
||||
fzf_bindings=$(__zic_fzf_bindings)
|
||||
|
||||
if [ $(echo $l | wc -l) -eq 1 ]; then
|
||||
matches=${(q)l}
|
||||
else
|
||||
matches=$(echo $l \
|
||||
| FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} \
|
||||
--reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS \
|
||||
--bind '${fzf_bindings}'" ${=fzf} \
|
||||
| while read -r item; do
|
||||
echo -n "${(q)item} "
|
||||
done)
|
||||
fi
|
||||
|
||||
matches=${matches% }
|
||||
if [ -n "$matches" ]; then
|
||||
tokens=(${(z)LBUFFER})
|
||||
base="${(Q)@[-1]}"
|
||||
if [[ "$base" != */ ]]; then
|
||||
if [[ "$base" == */* ]]; then
|
||||
base="$(dirname -- "$base")"
|
||||
if [[ ${base[-1]} != / ]]; then
|
||||
base="$base/"
|
||||
fi
|
||||
else
|
||||
base=""
|
||||
fi
|
||||
fi
|
||||
LBUFFER="${tokens[1]} "
|
||||
if [ -n "$base" ]; then
|
||||
base="${(q)base}"
|
||||
if [ "${tokens[2][1]}" = "~" ]; then
|
||||
base="${base/#$HOME/~}"
|
||||
fi
|
||||
LBUFFER="${LBUFFER}${base}"
|
||||
fi
|
||||
LBUFFER="${LBUFFER}${matches}/"
|
||||
fi
|
||||
zle redisplay
|
||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||
}
|
||||
|
||||
zic-completion() {
|
||||
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
|
||||
local tokens cmd
|
||||
|
||||
tokens=(${(z)LBUFFER})
|
||||
cmd=${tokens[1]}
|
||||
|
||||
if [[ "$LBUFFER" =~ "^\ *cd$" ]]; then
|
||||
zle ${__zic_default_completion:-expand-or-complete}
|
||||
elif [ "$cmd" = cd ]; then
|
||||
_zic_complete ${tokens[2,${#tokens}]/#\~/$HOME}
|
||||
else
|
||||
zle ${__zic_default_completion:-expand-or-complete}
|
||||
fi
|
||||
}
|
||||
|
||||
[ -z "$__zic_default_completion" ] && {
|
||||
binding=$(bindkey '^I')
|
||||
# $binding[(s: :w)2]
|
||||
# The command substitution and following word splitting to determine the
|
||||
# default zle widget for ^I formerly only works if the IFS parameter contains
|
||||
# a space via $binding[(w)2]. Now it specifically splits at spaces, regardless
|
||||
# of IFS.
|
||||
[[ $binding =~ 'undefined-key' ]] || __zic_default_completion=$binding[(s: :w)2]
|
||||
unset binding
|
||||
}
|
||||
|
||||
zle -N zic-completion
|
||||
if [ -z $zic_custom_binding ]; then
|
||||
zic_custom_binding='^I'
|
||||
fi
|
||||
bindkey "${zic_custom_binding}" zic-completion
|
Loading…
Add table
Add a link
Reference in a new issue