Browse Source

Add zsh configs

master
Tovi Jaeschke-Rogers 4 years ago
parent
commit
ad3eb04b16
5 changed files with 3988 additions and 3 deletions
  1. +5
    -3
      .config/aliasrc
  2. +293
    -0
      .zsh/_git
  3. +1
    -0
      .zsh/fsh
  4. +3516
    -0
      .zsh/git-completion.bash
  5. +173
    -0
      .zshrc

+ 5
- 3
.config/aliasrc View File

@ -1,8 +1,9 @@
#!/bin/sh
alias q='exit' \
ls="ls -G" \
ll="ls -G -alh" \
dd='sudo dd status=progress' \
h="history | grep" \
h="history 1 | grep" \
back='cd -' \
b='cd -' \
py='python3' \
@ -23,8 +24,9 @@ alias q='exit' \
gco='git checkout' \
gbls='git --no-pager branch -a' \
vv='nvim ~/.config/nvim/init.vim' \
vb='nvim ~/.bash_profile && source ~/.bash_profile' \
va='nvim ~/.config/aliasrc && source ~/.bash_profile' \
vz='nvim ~/.zshrc && source ~/.zshrc' \
va='nvim ~/.config/aliasrc && source ~/.zshrc' \
sz='source ~/.zshrc' \
delorig='find . -name "*.orig" -exec rm {} \;' \
delbak='find . -name "*.bak" -exec rm {} \;' \
site-clone='wget --mirror --convert-links --adjust-extension --page-requisites --no-parent'

+ 293
- 0
.zsh/_git View File

@ -0,0 +1,293 @@
#compdef git gitk
# zsh completion wrapper for git
#
# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
#
# The recommended way to install this script is to make a copy of it as a
# file named '_git' inside any directory in your fpath.
#
# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
# and then add the following to your ~/.zshrc file:
#
# fpath=(~/.zsh $fpath)
#
# You need git's bash completion script installed. By default bash-completion's
# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
#
# If your bash completion script is somewhere else, you can specify the
# location in your ~/.zshrc:
#
# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
#
zstyle -T ':completion:*:*:git:*' tag-order && \
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
zstyle -s ":completion:*:*:git:*" script script
if [ -z "$script" ]; then
local -a locations
local e bash_completion
bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) ||
bash_completion='/usr/share/bash-completion/completions/'
locations=(
"$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
"$HOME/.local/share/bash-completion/completions/git"
"$bash_completion/git"
'/etc/bash_completion.d/git' # old debian
)
for e in $locations; do
test -f $e && script="$e" && break
done
fi
local old_complete="$functions[complete]"
functions[complete]=:
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
functions[complete]="$old_complete"
__gitcomp ()
{
emulate -L zsh
local cur_="${3-$cur}"
case "$cur_" in
--*=)
;;
--no-*)
local c IFS=$' \t\n'
local -a array
for c in ${=1}; do
if [[ $c == "--" ]]; then
continue
fi
c="$c${4-}"
case $c in
--*=|*.) ;;
*) c="$c " ;;
esac
array+=("$c")
done
compset -P '*[=:]'
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
;;
*)
local c IFS=$' \t\n'
local -a array
for c in ${=1}; do
if [[ $c == "--" ]]; then
c="--no-...${4-}"
array+=("$c ")
break
fi
c="$c${4-}"
case $c in
--*=|*.) ;;
*) c="$c " ;;
esac
array+=("$c")
done
compset -P '*[=:]'
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
;;
esac
}
__gitcomp_direct ()
{
emulate -L zsh
compset -P '*[=:]'
compadd -Q -S '' -- ${(f)1} && _ret=0
}
__gitcomp_nl ()
{
emulate -L zsh
compset -P '*[=:]'
compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
}
__gitcomp_file ()
{
emulate -L zsh
compadd -f -p "${2-}" -- ${(f)1} && _ret=0
}
__gitcomp_direct_append ()
{
__gitcomp_direct "$@"
}
__gitcomp_nl_append ()
{
__gitcomp_nl "$@"
}
__gitcomp_file_direct ()
{
__gitcomp_file "$1" ""
}
_git_zsh ()
{
__gitcomp "v1.1"
}
__git_complete_command ()
{
emulate -L zsh
local command="$1"
local completion_func="_git_${command//-/_}"
if (( $+functions[$completion_func] )); then
emulate ksh -c $completion_func
return 0
else
return 1
fi
}
__git_zsh_bash_func ()
{
emulate -L ksh
local command=$1
__git_complete_command "$command" && return
local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then
words[1]=$expansion
__git_complete_command "$expansion"
fi
}
__git_zsh_cmd_common ()
{
local -a list
list=(
add:'add file contents to the index'
bisect:'find by binary search the change that introduced a bug'
branch:'list, create, or delete branches'
checkout:'checkout a branch or paths to the working tree'
clone:'clone a repository into a new directory'
commit:'record changes to the repository'
diff:'show changes between commits, commit and working tree, etc'
fetch:'download objects and refs from another repository'
grep:'print lines matching a pattern'
init:'create an empty Git repository or reinitialize an existing one'
log:'show commit logs'
merge:'join two or more development histories together'
mv:'move or rename a file, a directory, or a symlink'
pull:'fetch from and merge with another repository or a local branch'
push:'update remote refs along with associated objects'
rebase:'forward-port local commits to the updated upstream head'
reset:'reset current HEAD to the specified state'
restore:'restore working tree files'
rm:'remove files from the working tree and from the index'
show:'show various types of objects'
status:'show the working tree status'
switch:'switch branches'
tag:'create, list, delete or verify a tag object signed with GPG')
_describe -t common-commands 'common commands' list && _ret=0
}
__git_zsh_cmd_alias ()
{
local -a list
list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.})
list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"})
_describe -t alias-commands 'aliases' list && _ret=0
}
__git_zsh_cmd_all ()
{
local -a list
emulate ksh -c __git_compute_all_commands
list=( ${=__git_all_commands} )
_describe -t all-commands 'all commands' list && _ret=0
}
__git_zsh_main ()
{
local curcontext="$curcontext" state state_descr line
typeset -A opt_args
local -a orig_words
orig_words=( ${words[@]} )
_arguments -C \
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
'(-p --paginate)--no-pager[do not pipe git output into a pager]' \
'--git-dir=-[set the path to the repository]: :_directories' \
'--bare[treat the repository as a bare repository]' \
'(- :)--version[prints the git suite version]' \
'--exec-path=-[path to where your core git programs are installed]:: :_directories' \
'--html-path[print the path where git''s HTML documentation is installed]' \
'--info-path[print the path where the Info files are installed]' \
'--man-path[print the manpath (see `man(1)`) for the man pages]' \
'--work-tree=-[set the path to the working tree]: :_directories' \
'--namespace=-[set the git namespace]' \
'--no-replace-objects[do not use replacement refs to replace git objects]' \
'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
'(-): :->command' \
'(-)*:: :->arg' && return
case $state in
(command)
_tags common-commands alias-commands all-commands
while _tags; do
_requested common-commands && __git_zsh_cmd_common
_requested alias-commands && __git_zsh_cmd_alias
_requested all-commands && __git_zsh_cmd_all
let _ret || break
done
;;
(arg)
local command="${words[1]}" __git_dir
if (( $+opt_args[--bare] )); then
__git_dir='.'
else
__git_dir=${opt_args[--git-dir]}
fi
(( $+opt_args[--help] )) && command='help'
words=( ${orig_words[@]} )
__git_zsh_bash_func $command
;;
esac
}
_git ()
{
local _ret=1
local cur cword prev
cur=${words[CURRENT]}
prev=${words[CURRENT-1]}
let cword=CURRENT-1
if (( $+functions[__${service}_zsh_main] )); then
__${service}_zsh_main
elif (( $+functions[__${service}_main] )); then
emulate ksh -c __${service}_main
elif (( $+functions[_${service}] )); then
emulate ksh -c _${service}
elif (( $+functions[_${service//-/_}] )); then
emulate ksh -c _${service//-/_}
fi
let _ret && _default && _ret=0
return _ret
}
_git

+ 1
- 0
.zsh/fsh

@ -0,0 +1 @@
Subproject commit be2f385453670c18c40320a7384333f98fcd9f79

+ 3516
- 0
.zsh/git-completion.bash
File diff suppressed because it is too large
View File


+ 173
- 0
.zshrc View File

@ -0,0 +1,173 @@
#!/bin/zsh
# System-wide profile for interactive zsh(1) shells.
# Setup user specific overrides for this in ~/.zshrc. See zshbuiltins(1)
# and zshoptions(1) for more details.
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$PATH:$(du "$HOME/.local/bin/" | cut -f2 | tr '\n' ':')"
fi
# Correctly display UTF-8 with combining characters.
if [[ "$(locale LC_CTYPE)" == "UTF-8" ]]; then
setopt COMBINING_CHARS
fi
export HOMEBREW_NO_AUTO_UPDATE=1
export GIT_AUTHOR_NAME="Tovi Jaeschke-Rogers"
export GIT_AUTHOR_EMAIL="tovi.jaeschke-rogers@four.io"
export GIT_COMMITTER_NAME="Tovi Jaeschke-Rogers"
export GIT_COMMITTER_EMAIL="tovi.jaeschke-rogers@four.io"
export CASE_SENSITIVE="true"
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
export EDITOR=nvim
export GIT_EDITOR=nvim
# Disable the log builtin, so we don't conflict with /usr/bin/log
disable log
# Save command history
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
HISTSIZE=99999999
SAVEHIST=$HISTSIZE
# Beep on error
setopt BEEP
# Use keycodes (generated via zkbd) if present, otherwise fallback on
# values from terminfo
if [[ -r ${ZDOTDIR:-$HOME}/.zkbd/${TERM}-${VENDOR} ]] ; then
source ${ZDOTDIR:-$HOME}/.zkbd/${TERM}-${VENDOR}
else
typeset -g -A key
[[ -n "$terminfo[kf1]" ]] && key[F1]=$terminfo[kf1]
[[ -n "$terminfo[kf2]" ]] && key[F2]=$terminfo[kf2]
[[ -n "$terminfo[kf3]" ]] && key[F3]=$terminfo[kf3]
[[ -n "$terminfo[kf4]" ]] && key[F4]=$terminfo[kf4]
[[ -n "$terminfo[kf5]" ]] && key[F5]=$terminfo[kf5]
[[ -n "$terminfo[kf6]" ]] && key[F6]=$terminfo[kf6]
[[ -n "$terminfo[kf7]" ]] && key[F7]=$terminfo[kf7]
[[ -n "$terminfo[kf8]" ]] && key[F8]=$terminfo[kf8]
[[ -n "$terminfo[kf9]" ]] && key[F9]=$terminfo[kf9]
[[ -n "$terminfo[kf10]" ]] && key[F10]=$terminfo[kf10]
[[ -n "$terminfo[kf11]" ]] && key[F11]=$terminfo[kf11]
[[ -n "$terminfo[kf12]" ]] && key[F12]=$terminfo[kf12]
[[ -n "$terminfo[kf13]" ]] && key[F13]=$terminfo[kf13]
[[ -n "$terminfo[kf14]" ]] && key[F14]=$terminfo[kf14]
[[ -n "$terminfo[kf15]" ]] && key[F15]=$terminfo[kf15]
[[ -n "$terminfo[kf16]" ]] && key[F16]=$terminfo[kf16]
[[ -n "$terminfo[kf17]" ]] && key[F17]=$terminfo[kf17]
[[ -n "$terminfo[kf18]" ]] && key[F18]=$terminfo[kf18]
[[ -n "$terminfo[kf19]" ]] && key[F19]=$terminfo[kf19]
[[ -n "$terminfo[kf20]" ]] && key[F20]=$terminfo[kf20]
[[ -n "$terminfo[kbs]" ]] && key[Backspace]=$terminfo[kbs]
[[ -n "$terminfo[kich1]" ]] && key[Insert]=$terminfo[kich1]
[[ -n "$terminfo[kdch1]" ]] && key[Delete]=$terminfo[kdch1]
[[ -n "$terminfo[khome]" ]] && key[Home]=$terminfo[khome]
[[ -n "$terminfo[kend]" ]] && key[End]=$terminfo[kend]
[[ -n "$terminfo[kpp]" ]] && key[PageUp]=$terminfo[kpp]
[[ -n "$terminfo[knp]" ]] && key[PageDown]=$terminfo[knp]
[[ -n "$terminfo[kcuu1]" ]] && key[Up]=$terminfo[kcuu1]
[[ -n "$terminfo[kcub1]" ]] && key[Left]=$terminfo[kcub1]
[[ -n "$terminfo[kcud1]" ]] && key[Down]=$terminfo[kcud1]
[[ -n "$terminfo[kcuf1]" ]] && key[Right]=$terminfo[kcuf1]
fi
# Default key bindings
[[ -n ${key[Delete]} ]] && bindkey "${key[Delete]}" delete-char
[[ -n ${key[Home]} ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
[[ -n ${key[Up]} ]] && bindkey "${key[Up]}" up-line-or-search
[[ -n ${key[Down]} ]] && bindkey "${key[Down]}" down-line-or-search
# Default prompt
#PS1="%n@%m %1~ %# "
autoload -U colors && colors # Load colors
PROMPT="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
setopt autocd # Automatically cd into typed directory.
# Useful support for interacting with Terminal.app or other terminal programs
[ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"
# Load aliases
source ~/.config/aliasrc
# Load Git completion
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
autoload -Uz compinit && compinit
# Basic auto/tab complete:
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit
_comp_options+=(globdots) # Include hidden files.
# vi mode
bindkey -v
export KEYTIMEOUT=1
# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -v '^?' backward-delete-char
# Change cursor shape for different vi modes.
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then
echo -ne '\e[1 q'
elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} = '' ]] ||
[[ $1 = 'beam' ]]; then
echo -ne '\e[5 q'
fi
}
zle -N zle-keymap-select
zle-line-init() {
zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
echo -ne "\e[5 q"
}
zle -N zle-line-init
echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
bindkey -s '^f' 'cd "$(dirname "$(fzf)")"\n'
# Edit line in vim with ctrl-e:
autoload edit-command-line; zle -N edit-command-line
bindkey '^e' edit-command-line
# Load syntax highlighting; should be last.
source ~/.zsh/fsh/fast-syntax-highlighting.plugin.zsh 2>/dev/null
source ~/.iterm2_shell_integration.zsh
# Go up directory structures
up() {
cd $(printf "%0.0s../" $(seq 1 $1));
}
git-prune() {
if [[ $@ == "--apply" ]]; then
command git branch --merged develop | grep -vEw "develop$|master$" | xargs git branch -d
else
command git branch --merged develop | grep -vEw "develop$|master$"
fi
}
export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"

Loading…
Cancel
Save