parent
a282cf4d63
commit
8789a2a83e
33 changed files with 37 additions and 24 deletions
102
cli/.config/zsh/functions.zsh
Normal file
102
cli/.config/zsh/functions.zsh
Normal file
|
@ -0,0 +1,102 @@
|
|||
# Fuck default aliases
|
||||
unalias -a
|
||||
|
||||
testbin() { whence $@ > /dev/null }
|
||||
|
||||
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 $@
|
||||
}
|
||||
|
||||
addpath() {
|
||||
typeset newpath=$1
|
||||
if [[ ! $PATH =~ $newpath ]]; then
|
||||
PATH+=:$newpath
|
||||
export PATH
|
||||
fi
|
||||
}
|
||||
|
||||
fsf() {
|
||||
typeset host prompt="SSH Remote > "
|
||||
host=$(cut -d\ -f1 $HOME/.ssh/known_hosts | sort -u | fzf --prompt=$prompt) || return 1
|
||||
|
||||
termcompat ssh $host $@
|
||||
}
|
||||
|
||||
beep() { printf $'\007' }
|
||||
fixterm() { printf $'c' }
|
||||
|
||||
diff() { command diff --color $@ }
|
||||
tailf() { command less +F $@ }
|
||||
grep() { command grep --color=auto }
|
||||
rgrep() { grep --color=auto --exclude-dir=\.git -R $@ }
|
||||
fwcmd() { command firewall-cmd $@ }
|
||||
sush() { command sudo -Es }
|
||||
s() { termcompat ssh $@ }
|
||||
|
||||
if testbin nvim; then
|
||||
vi() { command nvim $@ }
|
||||
vim() { command nvim $@ }
|
||||
fi
|
||||
|
||||
tmux() { command tmux -2 $@ }
|
||||
atmux() { tmux attach || tmux }
|
||||
|
||||
g() { command lazygit $@ }
|
||||
tig() { termcompat tig $@ }
|
||||
gsi() { tig status }
|
||||
gci() { command git commit $@ }
|
||||
gsl() { command git stash list $@ }
|
||||
gss() { command git status -sbu $@ }
|
||||
gsw() { command git switch $@ }
|
||||
gup() { command git pull $@ }
|
||||
gwt() { command git worktree $@ }
|
||||
groot() { cd $(command git rev-parse --show-toplevel) || return 1 }
|
||||
ggrep() { command git grep $@ }
|
||||
gdiff() { command git diff --color $@; }
|
||||
greset() {
|
||||
echo "OK to reset and clean teh repo?"
|
||||
read -sq _
|
||||
(( $? )) && return 1
|
||||
/usr/bin/git clean -fd
|
||||
/usr/bin/git reset --hard
|
||||
}
|
||||
|
||||
if testbin diff-so-fancy; then
|
||||
gdf() { gdiff $@ | command diff-so-fancy | command less --tabs=4 -RSFX }
|
||||
else
|
||||
gdf() { gdiff $@ }
|
||||
fi
|
||||
|
||||
if testbin exa; then
|
||||
ls() { command exa --group-directories-first $@ }
|
||||
ll() { ls -alg $@ }
|
||||
ld() { ls -dlg $@ }
|
||||
else
|
||||
ls() { command ls --color=auto --group-directories-first $@ }
|
||||
ll() { ls -alh $@ }
|
||||
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
|
||||
alias $cmd="command grc -es --colour=auto $cmd"
|
||||
done
|
||||
unset cmds cmd
|
||||
fi
|
158
cli/.config/zsh/powerline.zsh
Normal file
158
cli/.config/zsh/powerline.zsh
Normal file
|
@ -0,0 +1,158 @@
|
|||
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_wt="$USERNAME@$HOST"
|
||||
prompt_fifo=~/.zsh_gitstatus_$$
|
||||
prompt_blimit=12
|
||||
typeset -A prompt_symbols=(
|
||||
sep_a $'\ue0b0'
|
||||
ellipsis $'\u2026'
|
||||
git $'\ue0a0'
|
||||
git_unstaged '~'
|
||||
git_staged $'\u2713'
|
||||
git_untracked '!'
|
||||
git_unmerged '*'
|
||||
bang $'\n %F{202}\u266a%f'
|
||||
)
|
||||
|
||||
typeset -A prompt_colors=(
|
||||
fg '15'
|
||||
root '1'
|
||||
ssh '0'
|
||||
cwd '4'
|
||||
git_branch '237'
|
||||
git_unstaged '3'
|
||||
git_staged '6'
|
||||
git_untracked '1'
|
||||
git_unmerged '5'
|
||||
)
|
||||
|
||||
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.init() {
|
||||
typeset -g prompt_string= prev_color=
|
||||
}
|
||||
|
||||
precmd.prompt.add() {
|
||||
(( $# < 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.bang() {
|
||||
prompt_string+="%F{$prev_color}%k$prompt_symbols[sep_a]%f$prompt_symbols[bang] "
|
||||
}
|
||||
|
||||
precmd.prompt.apply() {
|
||||
PROMPT=$prompt_string
|
||||
unset prompt_string
|
||||
}
|
||||
|
||||
precmd.prompt.user() {
|
||||
(( UID )) || precmd.prompt.add '#' $prompt_colors[root]
|
||||
}
|
||||
|
||||
precmd.prompt.cwd() {
|
||||
precmd.prompt.add %~ $prompt_colors[cwd]
|
||||
}
|
||||
|
||||
precmd.prompt.ssh() {
|
||||
[[ -n $SSH_CONNECTION ]] || return 0
|
||||
precmd.prompt.add %n@%m $prompt_colors[ssh]
|
||||
}
|
||||
|
||||
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() {
|
||||
precmd.prompt.init
|
||||
precmd.prompt.user
|
||||
precmd.prompt.ssh
|
||||
precmd.prompt.cwd
|
||||
}
|
||||
|
||||
precmd.git_update() {
|
||||
precmd.prompt
|
||||
precmd.prompt.git
|
||||
precmd.prompt.bang
|
||||
[[ ! -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.window_title() {
|
||||
printf '\033]0;%s\007' $prompt_wt
|
||||
}
|
||||
|
||||
precmd() {
|
||||
precmd.window_title
|
||||
precmd.prompt
|
||||
if precmd.is_git_repo; then
|
||||
precmd.prompt.pre_git
|
||||
precmd.git_update &!
|
||||
fi
|
||||
precmd.prompt.bang
|
||||
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
|
43
cli/.config/zsh/settings.zsh
Normal file
43
cli/.config/zsh/settings.zsh
Normal file
|
@ -0,0 +1,43 @@
|
|||
# disable the bloody ^S / ^Q, I use tmux all the time anyway
|
||||
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
|
||||
|
||||
export LESS='i M R'
|
||||
export PAGER=less
|
||||
export EDITOR=vim
|
||||
export TIME_STYLE=long-iso
|
||||
export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock"
|
||||
export ALTERNATE_EDITOR=
|
||||
|
||||
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:]}'
|
||||
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