switch to chezmoi
This commit is contained in:
parent
3c5d00dbf3
commit
a8b0acd4db
76 changed files with 27 additions and 531 deletions
99
dot_config/zsh/functions.zsh
Normal file
99
dot_config/zsh/functions.zsh
Normal file
|
@ -0,0 +1,99 @@
|
|||
# Fuck default aliases
|
||||
unalias -a
|
||||
|
||||
function testbin { whence $@ > /dev/null }
|
||||
|
||||
function termcompat {
|
||||
typeset term=$TERM
|
||||
case $term in
|
||||
(alacritty*) ;&
|
||||
(kitty*) ;&
|
||||
(wezterm) ;&
|
||||
(xterm-*)
|
||||
term=xterm;;
|
||||
(rxvt-unicode*)
|
||||
term=rxvt-unicode;;
|
||||
(tmux*)
|
||||
term=screen.xterm-new;;
|
||||
esac
|
||||
TERM=$term command $@
|
||||
}
|
||||
|
||||
function addpath {
|
||||
typeset newpath=$1
|
||||
if [[ ! $PATH =~ $newpath ]]; then
|
||||
PATH+=:$newpath
|
||||
export PATH
|
||||
fi
|
||||
}
|
||||
|
||||
function fsf {
|
||||
typeset host prompt="SSH Remote > "
|
||||
host=$(cut -d\ -f1 $HOME/.ssh/known_hosts | sort -u | fzf --prompt=$prompt) || return 1
|
||||
|
||||
termcompat ssh $host $@
|
||||
}
|
||||
|
||||
function beep { printf $'\007' }
|
||||
function fixterm { printf $'\u001bc' }
|
||||
|
||||
function diff { command diff --color $@ }
|
||||
function tailf { command less +F $@ }
|
||||
function grep { command grep --color=auto $@ }
|
||||
function rgrep { grep --exclude-dir=.git -R $@ }
|
||||
function s { termcompat ssh $@ }
|
||||
|
||||
function tmux { command tmux -2 $@ }
|
||||
function atmux { tmux attach || tmux }
|
||||
|
||||
function ksw { command kubecm switch $@ }
|
||||
function k { command kubectl $@ }
|
||||
function kg { command kubectl get $@ }
|
||||
function kc { command kubectl config $@ }
|
||||
function kshell { command kubectl exec -n $1 --stdin --tty $2 -- /bin/sh }
|
||||
|
||||
function g { command lazygit $@ }
|
||||
function gci { command git commit $@ }
|
||||
function gsl { command git stash list $@ }
|
||||
function gss { command git status -sbu $@ }
|
||||
function gsw { command git switch $@ }
|
||||
function gup { command git pull $@ }
|
||||
function gwta { command git worktree add $@ }
|
||||
function gwtp { command git worktree prune -v }
|
||||
function groot { cd $(command git rev-parse --show-toplevel) || return 0 }
|
||||
function gdiff { command git diff --color $@ }
|
||||
function greset {
|
||||
echo "OK to reset and clean teh repo?"
|
||||
read -sq _
|
||||
(( $? )) && return 1
|
||||
command git clean -fd
|
||||
command git reset --hard
|
||||
}
|
||||
|
||||
if testbin diff-so-fancy; then
|
||||
function gdf { gdiff $@ | command diff-so-fancy | command less --tabs=4 -RSFX }
|
||||
else
|
||||
function gdf { gdiff $@ }
|
||||
fi
|
||||
|
||||
if testbin eza; then
|
||||
function ls { command eza --group-directories-first $@ }
|
||||
function ll { ls -alg $@ }
|
||||
function ld { ls -dlg $@ }
|
||||
else
|
||||
function ls { command ls --color=auto --group-directories-first $@ }
|
||||
function ll { ls -alh $@ }
|
||||
function ld { ls -dlh $@ }
|
||||
fi
|
||||
|
||||
# grc
|
||||
if testbin grc; then
|
||||
cmds=(\
|
||||
cc configure cvs df dig gcc gmake id ip last lsof make mount \
|
||||
mtr netstat ping ping6 ps tcpdump traceroute traceroute6 \
|
||||
)
|
||||
for cmd in $cmds; do
|
||||
eval "function $cmd { command grc -es --colour=auto $cmd \$@ }"
|
||||
done
|
||||
unset cmds cmd
|
||||
fi
|
183
dot_config/zsh/prompt.zsh
Normal file
183
dot_config/zsh/prompt.zsh
Normal file
|
@ -0,0 +1,183 @@
|
|||
prompt_fmtn='[ %%{\e[2;3m%%}%s%%{\e[0m%%} ] '
|
||||
printf -v PROMPT2 $prompt_fmtn '%_'
|
||||
printf -v PROMPT3 $prompt_fmtn '?#'
|
||||
printf -v PROMPT4 $prompt_fmtn '+%N:%i'
|
||||
|
||||
prompt_fifo=$HOME/.zsh_gitstatus_$$
|
||||
prompt_blimit=50
|
||||
kube_config=$HOME/.kube/config
|
||||
typeset -A prompt_symbols=(
|
||||
sep_a $'\ue0b0'
|
||||
ellipsis $'\u2026'
|
||||
git $'\ue0a0'
|
||||
git_unstaged '~'
|
||||
git_staged $'\u2713'
|
||||
git_untracked '!'
|
||||
git_unmerged '*'
|
||||
helm $'\u2388'
|
||||
bang $'\u276f'
|
||||
)
|
||||
|
||||
typeset -A prompt_colors=(
|
||||
# fg '15'
|
||||
root '1'
|
||||
ssh '15'
|
||||
cwd '4'
|
||||
git_branch ''
|
||||
git_unstaged '3'
|
||||
git_staged '6'
|
||||
git_untracked '1'
|
||||
git_unmerged '5'
|
||||
kube_context '2'
|
||||
brackets '8'
|
||||
bang '8'
|
||||
)
|
||||
|
||||
prompt.set_bang() {
|
||||
(( $# )) || return 1
|
||||
prompt_symbols[bang]=$1
|
||||
}
|
||||
|
||||
precmd.window_title() {
|
||||
typeset dir=$(pwd)
|
||||
printf '\033]0;%s:%s\007' ${HOST%%.*} ${dir##*/}
|
||||
}
|
||||
|
||||
precmd.has_kube() {
|
||||
[[ -r $kube_config ]]
|
||||
}
|
||||
|
||||
precmd.kube_context() {
|
||||
typeset kube_context=$(awk -F- '($1 == "current") {print $3}' $kube_config)
|
||||
precmd.prompt.add $prompt_symbols[helm]
|
||||
precmd.prompt.add $kube_context $prompt_colors[kube_context]
|
||||
}
|
||||
|
||||
precmd.is_git_repo() {
|
||||
typeset prompt_git_dir
|
||||
prompt_git_dir=$(git rev-parse --git-dir 2>/dev/null) || return 1
|
||||
[[ ! -e $prompt_git_dir/nozsh ]]
|
||||
}
|
||||
|
||||
precmd.prompt.add() {
|
||||
(( $# )) || return 1
|
||||
typeset data=$1 color=$2
|
||||
[[ -n $prompt_string ]] && prompt_string+=" "
|
||||
if [[ -n $color ]]; then
|
||||
prompt_string+="%F{$color}$data%f"
|
||||
else
|
||||
prompt_string+="$data"
|
||||
fi
|
||||
}
|
||||
|
||||
precmd.prompt.add_pl() {
|
||||
(( $# < 2 )) && return 1
|
||||
typeset data=$1 color=$2
|
||||
if [[ -z $prompt_string ]]; then
|
||||
prompt_string+="%K{$color}%F{$prompt_colors[fg]} $data "
|
||||
else
|
||||
prompt_string+="%F{$prev_color}%K{$color}$prompt_symbols[sep_a]%F{$prompt_colors[fg]} $data "
|
||||
fi
|
||||
prev_color=$color
|
||||
}
|
||||
|
||||
precmd.prompt.apply() {
|
||||
PROMPT=$prompt_string
|
||||
unset prompt_string
|
||||
}
|
||||
|
||||
precmd.prompt.pre_git() {
|
||||
precmd.prompt.add "$prompt_symbols[git] $prompt_symbols[ellipsis]" $prompt_colors[git_branch]
|
||||
}
|
||||
|
||||
precmd.prompt.git() {
|
||||
typeset raw_status IFS=
|
||||
raw_status=$(git status --porcelain -bu 2>/dev/null) || return 0
|
||||
|
||||
typeset -A count
|
||||
while read line; do
|
||||
case $line[1,2] in
|
||||
('##')
|
||||
typeset branch_status=${line[4,-1]%%...*}
|
||||
((${#branch_status}>prompt_blimit)) && \
|
||||
branch_status=$branch_status[1,$prompt_blimit]$prompt_symbols[ellipsis]
|
||||
[[ $line =~ behind ]] && branch_status+=?
|
||||
[[ $line =~ ahead ]] && branch_status+=!
|
||||
precmd.prompt.add "$prompt_symbols[git] $branch_status" $prompt_colors[git_branch]
|
||||
;;
|
||||
(?[MD]) (( ++count[git_unstaged] )) ;|
|
||||
([MDARC]?) (( ++count[git_staged] )) ;|
|
||||
('??') (( ++count[git_untracked] )) ;|
|
||||
([ADU][ADU]) (( ++count[git_unmerged] ))
|
||||
esac
|
||||
done <<< $raw_status
|
||||
|
||||
for i in git_untracked git_unmerged git_unstaged git_staged; do
|
||||
(( count[$i] )) && precmd.prompt.add "$count[$i]$prompt_symbols[$i]" $prompt_colors[$i]
|
||||
done
|
||||
}
|
||||
|
||||
precmd.prompt() {
|
||||
typeset -g prompt_string= prev_color=
|
||||
|
||||
precmd.prompt.add '[' $prompt_colors[brackets]
|
||||
(( UID )) \
|
||||
|| precmd.prompt.add '#' $prompt_colors[root]
|
||||
[[ -n $SSH_CONNECTION ]]\
|
||||
&& precmd.prompt.add %n@%m $prompt_colors[ssh]
|
||||
|
||||
precmd.prompt.add %~ $prompt_colors[cwd]
|
||||
|
||||
if precmd.has_kube; then
|
||||
precmd.kube_context
|
||||
fi
|
||||
|
||||
[[ $1 == pre_git ]]\
|
||||
&& precmd.prompt.pre_git
|
||||
[[ $1 == git ]]\
|
||||
&& precmd.prompt.git
|
||||
|
||||
precmd.prompt.add $']\n' $prompt_colors[brackets]
|
||||
prompt_string+="%F{$prompt_colors[bang]}$prompt_symbols[bang]%f "
|
||||
}
|
||||
|
||||
precmd.git_update() {
|
||||
precmd.prompt git
|
||||
[[ ! -p $prompt_fifo ]] && mkfifo -m 0600 $prompt_fifo
|
||||
echo -n $prompt_string > $prompt_fifo &!
|
||||
kill -s USR1 $$
|
||||
}
|
||||
|
||||
precmd.prompt.update() {
|
||||
typeset -g prompt_string=$(<$prompt_fifo)
|
||||
precmd.prompt.apply
|
||||
zle && zle reset-prompt
|
||||
}
|
||||
|
||||
precmd() {
|
||||
precmd.window_title
|
||||
if precmd.is_git_repo; then
|
||||
precmd.prompt pre_git
|
||||
precmd.git_update &!
|
||||
else
|
||||
precmd.prompt
|
||||
fi
|
||||
precmd.prompt.apply
|
||||
}
|
||||
|
||||
TRAPUSR1() {
|
||||
precmd.prompt.update
|
||||
}
|
||||
|
||||
TRAPEXIT() {
|
||||
[[ -p $prompt_fifo ]] && rm $prompt_fifo
|
||||
}
|
||||
|
||||
function zle-line-init zle-keymap-select {
|
||||
local seq=$'\e[2 q'
|
||||
[[ $KEYMAP == vicmd ]] && seq=$'\e[4 q'
|
||||
printf $seq
|
||||
}
|
||||
|
||||
zle -N zle-line-init
|
||||
zle -N zle-keymap-select
|
45
dot_config/zsh/settings.zsh
Normal file
45
dot_config/zsh/settings.zsh
Normal file
|
@ -0,0 +1,45 @@
|
|||
# disable the bloody ^S / ^Q
|
||||
stty -ixon
|
||||
setopt APPEND_HISTORY EXTENDED_HISTORY HIST_IGNORE_DUPS EXTENDED_GLOB AUTO_CD AUTO_PUSHD PRINT_EXIT_VALUE
|
||||
unsetopt BEEP NO_MATCH NOTIFY MENU_COMPLETE AUTO_MENU
|
||||
|
||||
SAVEHIST=1000
|
||||
HISTSIZE=1000
|
||||
HISTFILE=$HOME/.histfile.$UID
|
||||
|
||||
EDITOR=vim
|
||||
whence hx >/dev/null && EDITOR=hx
|
||||
|
||||
export EDITOR
|
||||
export LESS='i M R'
|
||||
export PAGER=less
|
||||
export TIME_STYLE=long-iso
|
||||
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
|
||||
|
||||
bindkey -e
|
||||
bindkey $terminfo[kdch1] delete-char
|
||||
bindkey $terminfo[khome] beginning-of-line
|
||||
bindkey $terminfo[kend] end-of-line
|
||||
bindkey '^[' vi-cmd-mode
|
||||
|
||||
# autocompletion
|
||||
autoload -Uz compinit
|
||||
|
||||
compinit
|
||||
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:]}' '+l:|=* r:|=*'
|
||||
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}
|
||||
|
||||
unalias ld ls ll &>/dev/null
|
Loading…
Add table
Add a link
Reference in a new issue