2017-11-08 18:24:25 +02:00
|
|
|
# If not running interactively, don't do anything
|
|
|
|
[[ $- != *i* ]] && return
|
|
|
|
|
|
|
|
# {{{ settings
|
2018-06-09 20:15:56 +03:00
|
|
|
# disable the bloody ^S / ^Q, I use tmux all the time anyway
|
|
|
|
stty -ixon
|
2017-11-09 18:34:19 +02:00
|
|
|
setopt APPEND_HISTORY EXTENDED_HISTORY HIST_IGNORE_DUPS EXTENDED_GLOB AUTO_CD AUTO_PUSHD PRINT_EXIT_VALUE
|
2017-11-08 18:24:25 +02:00
|
|
|
unsetopt BEEP NO_MATCH NOTIFY MENU_COMPLETE AUTO_MENU
|
|
|
|
|
|
|
|
SAVEHIST=1000
|
|
|
|
HISTSIZE=1000
|
2020-01-28 15:39:04 +02:00
|
|
|
HISTFILE=$HOME/.histfile.$UID
|
2017-11-08 18:24:25 +02:00
|
|
|
|
2022-07-06 18:53:00 +03:00
|
|
|
export LESS='i M R'
|
2021-04-08 21:06:34 +03:00
|
|
|
export PAGER=less
|
2020-01-28 15:39:04 +02:00
|
|
|
export EDITOR=vim
|
|
|
|
export TIME_STYLE=long-iso
|
2021-04-08 21:06:34 +03:00
|
|
|
export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock"
|
2017-11-09 18:15:06 +02:00
|
|
|
|
2019-01-29 12:18:16 +02:00
|
|
|
autoload -Uz compinit edit-command-line
|
|
|
|
zle -N edit-command-line
|
|
|
|
|
2017-11-08 18:24:25 +02:00
|
|
|
# completion
|
2019-01-29 12:18:16 +02:00
|
|
|
compinit
|
2017-11-08 18:24:25 +02:00
|
|
|
zstyle ':completion:*' completer _list _complete _ignored
|
|
|
|
zstyle ':completion:*' insert-unambiguous true
|
|
|
|
zstyle ':completion:*' file-sort name
|
|
|
|
zstyle ':completion:*' format 'Completing %d'
|
|
|
|
zstyle ':completion:*' group-name ''
|
|
|
|
zstyle ':completion:*' list-colors ''
|
|
|
|
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
|
|
|
|
zstyle ':completion:*' list-suffixes true
|
|
|
|
zstyle ':completion:*' original true
|
|
|
|
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
|
|
|
|
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}'
|
|
|
|
zstyle ':completion:*' rehash true
|
|
|
|
zstyle ':completion:*:kill:*:processes' command 'ps --forest -A -o pid,user,cmd'
|
|
|
|
zstyle ':completion:*:processes-names' command 'ps axho command'
|
|
|
|
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
|
2017-11-13 18:33:14 +02:00
|
|
|
# }}}
|
|
|
|
# {{{ key bindings
|
2017-11-08 18:24:25 +02:00
|
|
|
bindkey -e
|
|
|
|
# urxvt
|
2019-01-29 12:18:16 +02:00
|
|
|
bindkey '^[[7~' beginning-of-line # home
|
|
|
|
bindkey '^[[8~' end-of-line # end
|
|
|
|
bindkey '^[Oc' forward-word # ctrl + right
|
|
|
|
bindkey '^[Od' backward-word # ctrl + left
|
|
|
|
bindkey '^[[3^' delete-word # ctrl + del
|
2017-11-08 18:24:25 +02:00
|
|
|
# screen
|
2019-01-29 12:18:16 +02:00
|
|
|
bindkey '^[[1~' beginning-of-line # home
|
|
|
|
bindkey '^[[4~' end-of-line # end
|
2017-11-08 18:24:25 +02:00
|
|
|
# xterm
|
2019-01-29 12:18:16 +02:00
|
|
|
bindkey '^[[H' beginning-of-line # home
|
|
|
|
bindkey '^[[F' end-of-line # end
|
2018-06-20 14:53:12 +03:00
|
|
|
# st
|
2019-01-29 12:18:16 +02:00
|
|
|
bindkey '^[[P' delete-char # del
|
|
|
|
bindkey '^[[M' delete-word # ctrl + del
|
2017-11-08 18:24:25 +02:00
|
|
|
# most of them (but not urxvt)
|
2019-01-29 12:18:16 +02:00
|
|
|
bindkey '^[[1;5C' forward-word # ctrl + right
|
|
|
|
bindkey '^[[1;5D' backward-word # ctrl + left
|
|
|
|
bindkey '^[[3;5~' delete-word # ctrl + del
|
2017-11-08 18:24:25 +02:00
|
|
|
# all of them
|
2019-01-29 12:18:16 +02:00
|
|
|
bindkey '^[[5~' backward-word # page up
|
|
|
|
bindkey '^[[6~' forward-word # page down
|
|
|
|
bindkey '^[[3~' delete-char # del
|
|
|
|
bindkey '^[m' copy-prev-shell-word # alt + m
|
|
|
|
bindkey -s '^j' '^atime ^m' # ctrl + j
|
|
|
|
|
|
|
|
# command line editing
|
|
|
|
bindkey '^x^e' edit-command-line
|
2017-11-08 18:24:25 +02:00
|
|
|
# }}}
|
|
|
|
# {{{ prompt
|
2021-10-06 18:03:04 +03:00
|
|
|
prompt_fmt='%%k%%f[ %s %s:%s %s]\n> '
|
|
|
|
prompt_fmtn='%%k%%f[ %%{\e[2;3m%s\e[0m%%} ]> '
|
2021-02-10 20:52:02 +02:00
|
|
|
prompt_user='%F{%(!.red.blue)}%n%f'
|
|
|
|
prompt_host='%m'
|
|
|
|
prompt_cwd='%F{green}%d%f'
|
|
|
|
prompt_git_fmt='\ue0a0 %s %s%%f '
|
2022-07-29 19:02:33 +03:00
|
|
|
prompt_state_file=/tmp/zsh_gitstatus_$$.tmp
|
2021-08-19 20:40:23 +03:00
|
|
|
|
|
|
|
printf -v PROMPT $prompt_fmt $prompt_user $prompt_host $prompt_cwd ''
|
|
|
|
printf -v PROMPT2 $prompt_fmtn '%_'
|
|
|
|
printf -v PROMPT3 $prompt_fmtn '?#'
|
|
|
|
printf -v PROMPT4 $prompt_fmtn '+%N:%i'
|
2017-11-08 18:24:25 +02:00
|
|
|
precmd.title() {
|
2017-12-01 01:47:14 +02:00
|
|
|
case $TERM in
|
2021-03-02 23:10:38 +02:00
|
|
|
(screen*) printf '\033k%s\033\\' ${HOST%%.*};;
|
2018-07-10 03:01:14 +03:00
|
|
|
(*) printf '\033]2;%s\007' ${HOST%%.*};;
|
2017-11-08 18:24:25 +02:00
|
|
|
esac
|
|
|
|
}
|
2017-11-15 14:24:08 +02:00
|
|
|
precmd.is_git_repo() {
|
2021-08-19 20:40:23 +03:00
|
|
|
read -r git_dir < <(git rev-parse --git-dir 2>/dev/null)
|
|
|
|
if ! ((?)); then
|
|
|
|
[[ -e $git_dir/nozsh ]] && return 1
|
|
|
|
return 0
|
|
|
|
fi
|
2017-11-08 18:24:25 +02:00
|
|
|
return 1
|
|
|
|
}
|
2017-11-15 14:24:08 +02:00
|
|
|
precmd.git() {
|
2019-01-31 15:08:03 +02:00
|
|
|
typeset raw_status
|
2022-07-29 19:02:33 +03:00
|
|
|
raw_status=$(flock -n $prompt_state_file git --no-optional-locks status --porcelain -bu 2>/dev/null)
|
2019-01-31 15:08:03 +02:00
|
|
|
(($?)) && return 0
|
|
|
|
|
2020-01-17 18:32:31 +02:00
|
|
|
typeset branch_status git_status IFS=
|
2019-01-31 15:08:03 +02:00
|
|
|
typeset staged_count=0 unstaged_count=0 untracked_count=0 unmerged_count=0
|
2017-11-08 18:24:25 +02:00
|
|
|
|
|
|
|
while read line; do
|
2020-01-17 18:32:31 +02:00
|
|
|
if [[ $line[1,2] == '##' ]]; then
|
|
|
|
branch_status=${line[4,-1]%%...*}
|
2020-01-28 15:39:04 +02:00
|
|
|
[[ $line =~ behind ]] && branch_status+=?
|
|
|
|
[[ $line =~ ahead ]] && branch_status+=!
|
2020-01-17 18:32:31 +02:00
|
|
|
fi
|
2017-12-01 01:47:14 +02:00
|
|
|
[[ $line[1,2] == '??' ]] && (( untracked_count++ ))
|
|
|
|
[[ $line[1,2] =~ .[MD] ]] && (( unstaged_count++ ))
|
|
|
|
[[ $line[1,2] =~ [MDARC]. ]] && (( staged_count++ ))
|
|
|
|
[[ $line[1,2] =~ [ADU]{2} ]] && (( unmerged_count++ ))
|
|
|
|
done <<< $raw_status
|
2017-11-08 18:24:25 +02:00
|
|
|
|
2020-01-28 15:39:04 +02:00
|
|
|
(( unstaged_count )) && git_status+=%F{yellow}~$unstaged_count
|
|
|
|
(( staged_count )) && git_status+=%F{blue}+$staged_count
|
|
|
|
(( untracked_count )) && git_status+=%F{red}-$untracked_count
|
|
|
|
(( unmerged_count )) && git_status+=%F{cyan}*$unmerged_count
|
|
|
|
[[ -z $git_status ]] && git_status=%F{green}ok
|
2017-11-08 18:24:25 +02:00
|
|
|
|
2021-02-10 20:52:02 +02:00
|
|
|
printf $prompt_git_fmt $branch_status $git_status > $prompt_state_file
|
2017-11-08 18:24:25 +02:00
|
|
|
}
|
|
|
|
precmd.prompt() {
|
2021-02-10 20:52:02 +02:00
|
|
|
printf -v PROMPT $prompt_fmt $prompt_user $prompt_host $prompt_cwd $1
|
2017-11-08 18:24:25 +02:00
|
|
|
}
|
|
|
|
precmd.git_update() {
|
2019-02-01 13:52:49 +02:00
|
|
|
precmd.git
|
2017-11-08 18:24:25 +02:00
|
|
|
kill -s USR1 $$
|
|
|
|
}
|
|
|
|
precmd() {
|
|
|
|
precmd.title
|
2019-02-01 13:52:49 +02:00
|
|
|
if precmd.is_git_repo; then
|
2019-11-24 00:20:40 +02:00
|
|
|
precmd.prompt $'\ue0a0 ... '
|
2019-02-01 13:52:49 +02:00
|
|
|
precmd.git_update &!
|
|
|
|
else
|
2021-02-10 20:52:02 +02:00
|
|
|
precmd.prompt ''
|
2019-02-01 13:52:49 +02:00
|
|
|
fi
|
2017-11-08 18:24:25 +02:00
|
|
|
}
|
2017-11-15 14:24:08 +02:00
|
|
|
TRAPUSR1() {
|
2019-02-01 13:52:49 +02:00
|
|
|
precmd.prompt "$(<$prompt_state_file)"
|
2017-11-15 14:24:08 +02:00
|
|
|
zle && zle reset-prompt
|
|
|
|
}
|
2017-11-09 18:15:06 +02:00
|
|
|
TRAPEXIT() {
|
2019-02-01 13:52:49 +02:00
|
|
|
[[ -f $prompt_state_file ]] && rm $prompt_state_file
|
2017-11-09 18:15:06 +02:00
|
|
|
}
|
2017-11-08 18:24:25 +02:00
|
|
|
# }}}
|
2017-11-13 18:33:14 +02:00
|
|
|
# {{{ aliases
|
2020-01-28 15:39:04 +02:00
|
|
|
beep() { printf $'\007' }
|
|
|
|
fixterm() { printf $'c' }
|
|
|
|
|
|
|
|
diff() { command diff --color $@ }
|
2022-07-06 18:53:00 +03:00
|
|
|
tailf() { command less +F $@ }
|
2020-01-28 15:39:04 +02:00
|
|
|
rgrep() { command grep --exclude-dir=\.git -R $@ }
|
2018-06-21 17:51:48 +03:00
|
|
|
|
|
|
|
# ls
|
2021-04-08 21:06:34 +03:00
|
|
|
if [[ -x $(whence -p exa) ]]; then
|
2022-07-29 19:02:33 +03:00
|
|
|
ls() { command exa --group-directories-first $@ }
|
|
|
|
ll() { ls -lag $@ }
|
2021-04-08 21:06:34 +03:00
|
|
|
else
|
2022-07-29 19:02:33 +03:00
|
|
|
ls() { command ls --color=auto $@ }
|
|
|
|
ll() { ls -lha $@ }
|
2021-04-08 21:06:34 +03:00
|
|
|
fi
|
2018-06-21 17:51:48 +03:00
|
|
|
|
|
|
|
# git
|
2020-01-28 15:39:04 +02:00
|
|
|
gci() { command git commit $@ }
|
|
|
|
gsl() { command git stash list $@ }
|
|
|
|
gss() { command git status -sbu $@ }
|
|
|
|
gup() { command git pull $@ }
|
2021-08-20 17:13:49 +03:00
|
|
|
groot() { cd $(command git rev-parse --show-toplevel) || return 1 }
|
2020-01-28 15:39:04 +02:00
|
|
|
ggrep() { command git grep $@ }
|
|
|
|
gsi() { command tig status }
|
2018-06-21 17:51:48 +03:00
|
|
|
|
|
|
|
# tmux
|
2020-01-28 15:39:04 +02:00
|
|
|
tmux() { command tmux -2 $@ }
|
2020-03-23 09:00:08 +02:00
|
|
|
atmux() { tmux attach || tmux }
|
2018-06-21 17:51:48 +03:00
|
|
|
|
2021-04-08 21:06:34 +03:00
|
|
|
# sudo
|
|
|
|
sush() { command sudo -Es }
|
2018-11-15 11:44:56 +02:00
|
|
|
|
2020-02-10 18:37:26 +02:00
|
|
|
# vim
|
2021-03-02 23:10:38 +02:00
|
|
|
vi() { command vim $@ }
|
2017-11-13 18:33:14 +02:00
|
|
|
# }}}
|
2017-11-08 18:24:25 +02:00
|
|
|
# {{{ plugins
|
|
|
|
# grc
|
2020-09-28 17:23:28 +03:00
|
|
|
if [[ -x $(whence -p grc) ]]; then
|
2017-11-24 18:46:01 +02:00
|
|
|
cmds=(\
|
2018-06-09 20:15:56 +03:00
|
|
|
cc configure cvs df dig gcc gmake id ip last lsof make mount \
|
2017-11-24 18:46:01 +02:00
|
|
|
mtr netstat ping ping6 ps tcpdump traceroute traceroute6 \
|
|
|
|
)
|
|
|
|
for cmd in $cmds[@]; do
|
|
|
|
alias $cmd="command grc -es --colour=auto $cmd"
|
|
|
|
done
|
2018-07-06 03:12:05 +03:00
|
|
|
unset cmds cmd
|
2017-11-08 18:24:25 +02:00
|
|
|
fi
|
|
|
|
# some cool git stuff
|
2021-03-02 23:10:38 +02:00
|
|
|
gdiff() { command git diff --color $@; }
|
|
|
|
if [[ -x $(whence -p diff-so-fancy) ]]; then
|
|
|
|
gdf() { gdiff $@ | command diff-so-fancy | command less --tabs=4 -RSFX }
|
|
|
|
else
|
|
|
|
gdf() { gdiff $@ }
|
|
|
|
fi
|
2017-11-15 14:24:08 +02:00
|
|
|
greset() {
|
|
|
|
echo "OK to reset and clean teh repo?"
|
2017-12-18 12:59:59 +02:00
|
|
|
read -sq _
|
|
|
|
(( $? )) && return 1
|
2017-11-15 14:24:08 +02:00
|
|
|
/usr/bin/git clean -fd
|
|
|
|
/usr/bin/git reset --hard
|
|
|
|
}
|
2017-11-08 18:24:25 +02:00
|
|
|
# }}}
|