From 46cd84d3a6417c744f84940a6bf61823235f74be Mon Sep 17 00:00:00 2001 From: David Chen Date: Wed, 4 Mar 2020 22:48:38 -0800 Subject: [PATCH] zsh+fzf=awesome --- zsh/aliases.zsh | 35 ++++++++++++ zsh/env.zsh | 25 +++++++++ zsh/fzf.zsh | 59 +++++++++++++++++++++ zsh/fzf/bcp | 11 ++++ zsh/fzf/bip | 12 +++++ zsh/fzf/bup | 12 +++++ zsh/fzf/cani | 10 ++++ zsh/fzf/ffind | 80 ++++++++++++++++++++++++++++ zsh/fzf/ffunctions | 5 ++ zsh/fzf/fhistory | 13 +++++ zsh/fzf/fp | 12 +++++ zsh/fzf/fps | 28 ++++++++++ zsh/fzf/fzf-find-widget | 42 +++++++++++++++ zsh/fzf/kp | 14 +++++ zsh/fzf/ks | 14 +++++ zsh/fzf/util | 42 +++++++++++++++ zsh/plugins.zsh | 6 +++ zsh/tmux.zsh | 15 ++++++ zsh/vi.zsh | 49 +++++++++++++++++ zsh/zimrc | 16 ++++++ zsh/zshrc | 115 +++------------------------------------- 21 files changed, 507 insertions(+), 108 deletions(-) create mode 100644 zsh/aliases.zsh create mode 100644 zsh/env.zsh create mode 100644 zsh/fzf.zsh create mode 100755 zsh/fzf/bcp create mode 100755 zsh/fzf/bip create mode 100755 zsh/fzf/bup create mode 100755 zsh/fzf/cani create mode 100755 zsh/fzf/ffind create mode 100755 zsh/fzf/ffunctions create mode 100755 zsh/fzf/fhistory create mode 100755 zsh/fzf/fp create mode 100755 zsh/fzf/fps create mode 100755 zsh/fzf/fzf-find-widget create mode 100755 zsh/fzf/kp create mode 100755 zsh/fzf/ks create mode 100755 zsh/fzf/util create mode 100644 zsh/plugins.zsh create mode 100644 zsh/tmux.zsh create mode 100644 zsh/vi.zsh create mode 100644 zsh/zimrc diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh new file mode 100644 index 0000000..7239712 --- /dev/null +++ b/zsh/aliases.zsh @@ -0,0 +1,35 @@ +alias av='source venv/bin/activate' +alias c='clear' +alias cdiff='colordiff' +alias cs='calcurse' +alias dv='deactivate' +alias gc='git config credential.helper store' +alias ipy='ipython' +alias l='ls -la' +alias lg='lazygit' +alias ms='mailsync' +alias mt='neomutt' +alias r='echo $RANGER_LEVEL' +alias pu='python3 -m pudb' +alias ra='ranger' +# ra() { + #if [ -z "$RANGER_LEVEL" ] + #then + #ranger + #else + #exit + #fi +#} +alias s='neofetch' +alias g='onefetch' +alias sra='sudo -E ranger' +alias sudo='sudo -E' +alias vim='nvim' +alias gs='git config credential.helper store' +alias bat='sudo tlp bat' +alias ac='sudo tlp ac' +alias gy='git-yolo' +alias nb='newsboat -r' +alias nt="sh -c 'cd $(pwd); st' > /dev/null 2>&1 &" +alias ta='tmux a' +alias t='tmux' diff --git a/zsh/env.zsh b/zsh/env.zsh new file mode 100644 index 0000000..c971d4f --- /dev/null +++ b/zsh/env.zsh @@ -0,0 +1,25 @@ +export GOPATH=$HOME/go +export PATH=$PATH:$HOME/.gem/ruby/2.6.0 +export PATH=$PATH:$HOME/go/bin +export PATH=$PATH:/home/linuxbrew/.linuxbrew/bin +export PATH=$PATH:$HOME/.local/bin +export PATH=$PATH:$HOME/.config/bin +export PATH=$PATH:/snap/bin +#export TERM=xterm-256color +export PATH=$PATH:/home/david/prog/flutter/bin +export TERM=xterm-256color +export TERM_ITALICS=true +export RANGER_LOAD_DEFAULT_RC="false" +#export TERM=screen-256color +export EDITOR=nvim +export XDG_CONFIG_HOME=/home/david/.config +export ZSH_AUTOSUGGEST_USE_ASYNC=1 +export ZSH_AUTOSUGGEST_MANUAL_REBIND=1 + +# fzf +export FZF_DEFAULT_OPTS='--bind ctrl-e:down,ctrl-u:up --preview "[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (ccat --color=always {} || highlight -O ansi -l {} || cat {}) 2> /dev/null | head -500"' +export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g ""' +export FZF_COMPLETION_TRIGGER='\' +export FZF_TMUX=1 +export FZF_TMUX_HEIGHT='80%' +export fzf_preview_cmd='[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (ccat --color=always {} || highlight -O ansi -l {} || cat {}) 2> /dev/null | head -500' diff --git a/zsh/fzf.zsh b/zsh/fzf.zsh new file mode 100644 index 0000000..2ea9989 --- /dev/null +++ b/zsh/fzf.zsh @@ -0,0 +1,59 @@ +export FZF_DEFAULT_OPTS='--bind=ctrl-t:top,change:top --bind ctrl-e:down,ctrl-u:up' + + +_fzf_fpath=${0:h}/fzf +fpath+=$_fzf_fpath +autoload -U $_fzf_fpath/*(.:t) +unset _fzf_fpath + +fzf-redraw-prompt() { + local precmd + for precmd in $precmd_functions; do + $precmd + done + zle reset-prompt +} +zle -N fzf-redraw-prompt + +zle -N fzf-find-widget +bindkey '^p' fzf-find-widget + +fzf-cd-widget() { + local tokens=(${(z)LBUFFER}) + if (( $#tokens <= 1 )); then + zle fzf-find-widget 'only_dir' + if [[ -d $LBUFFER ]]; then + cd $LBUFFER + local ret=$? + LBUFFER= + zle fzf-redraw-prompt + return $ret + fi + fi +} +zle -N fzf-cd-widget +bindkey '^t' fzf-cd-widget + +fzf-history-widget() { + local num=$(fhistory $LBUFFER) + local ret=$? + if [[ -n $num ]]; then + zle vi-fetch-history -n $num + fi + zle reset-prompt + return $ret +} +zle -N fzf-history-widget +bindkey '^R' fzf-history-widget + +fif() { + if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi + rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}" +} + +find-in-file() { + grep --line-buffered --color=never -r "" * | fzf +} +zle -N find-in-file +bindkey '^f' find-in-file + diff --git a/zsh/fzf/bcp b/zsh/fzf/bcp new file mode 100755 index 0000000..90a1c76 --- /dev/null +++ b/zsh/fzf/bcp @@ -0,0 +1,11 @@ +### BREW + FZF +# mnemonic [B]rew [I]nstall [P]lugin + +local uninst=$(brew leaves | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[brew:clean]'") + +if [[ $uninst ]]; then + for prog in $(echo $uninst) + do brew uninstall $prog + done +fi + diff --git a/zsh/fzf/bip b/zsh/fzf/bip new file mode 100755 index 0000000..103ad92 --- /dev/null +++ b/zsh/fzf/bip @@ -0,0 +1,12 @@ +### BREW + FZF +# update multiple packages at once +# mnemonic [B]rew [U]pdate [P]lugin + +local inst=$(brew search | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[brew:install]'") + +if [[ $inst ]]; then + for prog in $(echo $inst) + do brew install $prog + done +fi + diff --git a/zsh/fzf/bup b/zsh/fzf/bup new file mode 100755 index 0000000..74ab3b1 --- /dev/null +++ b/zsh/fzf/bup @@ -0,0 +1,12 @@ +### BREW + FZF +# uninstall multiple packages at once, async +# mnemonic [B]rew [C]lean [P]lugin (e.g. uninstall) + +local upd=$(brew leaves | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[brew:update]'") + +if [[ $upd ]]; then + for prog in $(echo $upd) + do brew upgrade $prog + done +fi + diff --git a/zsh/fzf/cani b/zsh/fzf/cani new file mode 100755 index 0000000..10ffe16 --- /dev/null +++ b/zsh/fzf/cani @@ -0,0 +1,10 @@ +### Caniuse + FZF +# caniuse for quick access to global support list +# also runs the `caniuse` command if installed + +local feat=$(ciu | sort -rn | eval "fzf ${FZF_DEFAULT_OPTS} --ansi --header='[caniuse:features]'" | sed -e 's/^.*%\ *//g' | sed -e 's/ .*//g') + +if which caniuse &> /dev/null; then + if [[ $feat ]] then; caniuse $feat; fi +fi + diff --git a/zsh/fzf/ffind b/zsh/fzf/ffind new file mode 100755 index 0000000..7fc2ed2 --- /dev/null +++ b/zsh/fzf/ffind @@ -0,0 +1,80 @@ +#!/usr/bin/env zsh + +setopt localoptions + +local s_path level +local only_dir +while getopts ':dl:s:' opt; do + case $opt in + d) + only_dir=1 + ;; + l) + level=$OPTARG + ;; + s) + s_path=$OPTARG + ;; + \?) + echo "Invalid option -$OPTARG." >&2 + ;; + esac +done + +local cmd="command find -L ${s_path:-.} -mindepth 1 ${level:+-maxdepth $level} \ +\\( -path '*/\\.git' \ +-o -path '*/venv' \ +-o -fstype 'sysfs' \ +-o -fstype 'devfs' \ +-o -fstype 'devtmpfs' \ +-o -fstype 'proc' \\) -prune \ +-o -type d -print" + +if [[ -z $only_dir ]]; then + cmd="$cmd -o -type f -print -o -type l -print" +fi + +cmd="$cmd 2>/dev/null" + +if [[ -z $s_path || $s_path == '.' ]]; then + cmd="$cmd | cut -b3-" +fi + +local fzf_opts="--height=50% --reverse -m --tiebreak=end \ +--preview-window=right:60%:wrap \ +--bind=ctrl-alt-u:preview-up,ctrl-alt-e:preview-down" + +local fzf_preview_cmd=' + t=${$(readlink {}):-{}} + if [[ $(file -i $t) =~ directory ]]; then + (exa --color=always -T -L 1 {} || + tree -C -L 1 {} || + echo {} is a directory.) 2>/dev/null + elif [[ $(file -i $t) =~ binary ]]; then + echo {} is a binary file. + else + ccat --color=always {} 2>/dev/null + fi +' + +local -a ret_array +local ret=0 + +eval $cmd | fzf ${(z)fzf_opts} --preview $fzf_preview_cmd ${(z)EXTRA_OPTS} | { + while read item; do + printf "${(q)item} " + done +} | sed -E '$s/ $//' + +ret_array=($pipestatus) +# ignore find command error code 1 such as loop detect or permission +if (( $ret_array[1] == 1 )); then + ret=0 +fi +local p_ret +for p_ret in $ret_array[2,-1]; do + if (( p_ret )); then + ret=$p_ret + fi +done +return $ret diff --git a/zsh/fzf/ffunctions b/zsh/fzf/ffunctions new file mode 100755 index 0000000..5529e14 --- /dev/null +++ b/zsh/fzf/ffunctions @@ -0,0 +1,5 @@ +#!/usr/bin/env zsh + +setopt localoptions pipefail + +print -l ${(k)functions} | fzf --height=50% diff --git a/zsh/fzf/fhistory b/zsh/fzf/fhistory new file mode 100755 index 0000000..67f1a5b --- /dev/null +++ b/zsh/fzf/fhistory @@ -0,0 +1,13 @@ +#!/usr/bin/env zsh + +setopt localoptions pipefail + +# TODO: sort is not stream command, bad performance # +local selected=( $(fc -rl 1 | sort -k 2 -u | sort -rn | + fzf --height 50% -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort --query=$1 +m) ) + +local ret=$? +if [[ -n $selected ]]; then + print $selected[1] +fi +return $ret diff --git a/zsh/fzf/fp b/zsh/fzf/fp new file mode 100755 index 0000000..36f6494 --- /dev/null +++ b/zsh/fzf/fp @@ -0,0 +1,12 @@ +### PATH +# mnemonic: [F]ind [P]ath +# list directories in $PATH, press [enter] on an entry to list the executables inside. +# press [escape] to go back to directory listing, [escape] twice to exit completely + +local loc=$(echo $PATH | sed -e $'s/:/\\\n/g' | eval "fzf ${FZF_DEFAULT_OPTS} --header='[find:path]'") + +if [[ -d $loc ]]; then + echo "$(rg --files $loc | rev | cut -d"/" -f1 | rev)" | eval "fzf ${FZF_DEFAULT_OPTS} --header='[find:exe] => ${loc}' >/dev/null" + fp +fi + diff --git a/zsh/fzf/fps b/zsh/fzf/fps new file mode 100755 index 0000000..169bf61 --- /dev/null +++ b/zsh/fzf/fps @@ -0,0 +1,28 @@ +#!/usr/bin/env zsh + +_fps() { + local render + if (( $+commands[grcat] )); then + render='grcat fps.grc' + else + render='cat' + fi + + ps -eo user,pid,ppid,pgid,stat,tname,cmd | awk ' + BEGIN { "ps -p $$ -o pgid --no-headers | tr -d \"[:blank:]\"" | getline pgid } { + if ($4 != pgid || $2 == pgid) + print + }' | ${(z)render} +} + +setopt localoptions pipefail + +local fzf_opts="--header-lines=1 -m \ +${commands[grcat]:+--ansi} --height=50% \ +--min-height=15 --tac --reverse \ +--preview-window=down:2" + +local fzf_preview_cmd="ps -o pcpu,pmem,vsz,rss,thcount,start_time,time -p {2}" + +_fps | fzf ${(z)fzf_opts} --preview=$fzf_preview_cmd | + awk -v sep=${FZF_MUL_DELIM:- } '{ printf "%s%c", $2, sep }' | sed -E "s/${FZF_MUL_DELIM:- }$//" diff --git a/zsh/fzf/fzf-find-widget b/zsh/fzf/fzf-find-widget new file mode 100755 index 0000000..45da309 --- /dev/null +++ b/zsh/fzf/fzf-find-widget @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh + +local ret=0 +local tokens=(${(z)LBUFFER}) +local -a cmd_opts=() +local -a extra_fzf_opts=() +if [[ $1 == 'only_dir' ]]; then + cmd_opts+='-d' + extra_fzf_opts+='+m' +fi +if (( $#tokens )) && [[ $LBUFFER[-1] != ' ' ]]; then + local is_wave=0 + local dir=${(e)tokens[-1]} + if [[ $dir[1] == ~* ]]; then + is_wave=1 + fi + dir=${dir/#'~'/$HOME} + local base + if [[ ! -d $dir ]]; then + base=$(basename $dir) + dir=$(dirname $dir) + fi + cmd_opts+="-s $dir" + extra_fzf_opts+=${base:+--query $base} + match=$(EXTRA_OPTS=${(z)extra_fzf_opts} ffind ${(z)cmd_opts}) + ret=$? + if (( ret == 0 || ret == 141 )); then + if (( is_wave )); then + match=$(sed "s| $HOME| ~|g" <<<$match) + fi + if (( $#tokens == 1 )); then + LBUFFER=$match + else + LBUFFER="$tokens[0,-2] $match" + fi + fi +else + LBUFFER=$LBUFFER$(EXTRA_OPTS=${(z)extra_fzf_opts} ffind ${(z)cmd_opts}) + ret=$? +fi +zle reset-prompt +return $ret diff --git a/zsh/fzf/kp b/zsh/fzf/kp new file mode 100755 index 0000000..c6c017c --- /dev/null +++ b/zsh/fzf/kp @@ -0,0 +1,14 @@ +### PROCESS +# mnemonic: [K]ill [P]rocess +# show output of "ps -ef", use [tab] to select one or multiple entries +# press [enter] to kill selected processes and go back to the process list. +# or press [escape] to go back to the process list. Press [escape] twice to exit completely. + +local pid=$(ps -ef | sed 1d | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[kill:process]'" | awk '{print $2}') + +if [ "x$pid" != "x" ] +then + echo $pid | xargs kill -${1:-9} + kp +fi + diff --git a/zsh/fzf/ks b/zsh/fzf/ks new file mode 100755 index 0000000..b7276ed --- /dev/null +++ b/zsh/fzf/ks @@ -0,0 +1,14 @@ +### SERVER +# mnemonic: [K]ill [S]erver +# show output of "lsof -Pwni tcp", use [tab] to select one or multiple entries +# press [enter] to kill selected processes and go back to the process list. +# or press [escape] to go back to the process list. Press [escape] twice to exit completely. + +local pid=$(lsof -Pwni tcp | sed 1d | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[kill:tcp]'" | awk '{print $2}') + +if [ "x$pid" != "x" ] +then + echo $pid | xargs kill -${1:-9} + ks +fi + diff --git a/zsh/fzf/util b/zsh/fzf/util new file mode 100755 index 0000000..a22378d --- /dev/null +++ b/zsh/fzf/util @@ -0,0 +1,42 @@ +### UTILS +# show utils commands and custom aliasses + +local helptxt="bcp [brew:clean] +bip [brew:install] +bup [brew:update] +cani [caniuse:features] +fp [find:path] +kp [kill:path] +ks [kill:tcp] +av [alias] source venv/bin/activate +c [alias] clear +cdiff [alias] colordiff +cs [alias] calcurse +dv [alias] deactivate +gc [alias] git config credential.helper store +ipy [alias] ipython +l [alias] ls -la +lg [alias] lazygit +ms [alias] mailsync +mt [alias] neomutt +r [alias] echo $RANGER_LEVEL +pu [alias] python3 -m pudb +ra [alias] ranger +s [alias] neofetch +g [alias] onefetch +sra [alias] sudo -E ranger +sudo [alias] sudo -E +vim [alias] nvim +gs [alias] git config credential.helper store +bat [alias] sudo tlp bat +ac [alias] sudo tlp ac +gy [alias] git-yolo +nb [alias] newsboat -r +nt [alias] sh -c 'cd $(pwd); st' > /dev/null 2>&1 &" + +local cmd=$(echo $helptxt | eval "fzf ${FZF_DEFAULT_OPTS} --header='[utils:show]'" | awk '{print $1}') + +if [[ -n $cmd ]]; then + eval ${cmd} +fi + diff --git a/zsh/plugins.zsh b/zsh/plugins.zsh new file mode 100644 index 0000000..6c56cdf --- /dev/null +++ b/zsh/plugins.zsh @@ -0,0 +1,6 @@ +export PLUG_DIR=$HOME/.zim +if [[ ! -d $PLUG_DIR ]]; then + curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh + rm ~/.zimrc + ln -s ~/.config/zsh/zimrc ~/.zimrc +fi diff --git a/zsh/tmux.zsh b/zsh/tmux.zsh new file mode 100644 index 0000000..43a1fbe --- /dev/null +++ b/zsh/tmux.zsh @@ -0,0 +1,15 @@ +tmux_preexec() { + local tmux_event=${TMUX%%,*}-event/client-attached-pane + if [[ -f $tmux_event-$TMUX_PANE ]]; then + eval $(tmux showenv -s) + command rm $tmux_event-$TMUX_PANE 2>/dev/null + fi +} + +if [[ -n $TMUX ]]; then + local tmux_event=${TMUX%%,*}-event/client-attached-pane + command rm $tmux_event-$TMUX_PANE 2>/dev/null + + autoload -U add-zsh-hook + add-zsh-hook preexec tmux_preexec +fi diff --git a/zsh/vi.zsh b/zsh/vi.zsh new file mode 100644 index 0000000..e69bea1 --- /dev/null +++ b/zsh/vi.zsh @@ -0,0 +1,49 @@ +bindkey '^v' edit-command-line +bindkey -v +bindkey -M vicmd "k" vi-insert +bindkey -M vicmd "K" vi-insert-bol +bindkey -M vicmd "n" vi-backward-char +bindkey -M vicmd "i" vi-forward-char +bindkey -M vicmd "N" vi-beginning-of-line +bindkey -M vicmd "I" vi-end-of-line +bindkey -M vicmd "e" down-line-or-history +bindkey -M vicmd "u" up-line-or-history +bindkey -M vicmd "l" undo +#bindkey -M vicmd "-" vi-rev-repeat-search +bindkey -M vicmd "=" vi-repeat-search +bindkey -M vicmd "h" vi-forward-word-end + +#function zle-line-init zle-keymap-select { + #RPS1="${${KEYMAP/vicmd/-- NOR --}/(main|viins)/-- INS --}" + #RPS2=$RPS1 + #zle reset-prompt +#} + +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 + +# Use beam shape cursor on startup. +echo -ne '\e[5 q' + +# Use beam shape cursor for each new prompt. +preexec() { + echo -ne '\e[5 q' +} + +_fix_cursor() { + echo -ne '\e[5 q' +} +precmd_functions+=(_fix_cursor) + + +zle -N zle-line-init +zle -N zle-keymap-select + +KEYTIMEOUT=1 + diff --git a/zsh/zimrc b/zsh/zimrc new file mode 100644 index 0000000..246b721 --- /dev/null +++ b/zsh/zimrc @@ -0,0 +1,16 @@ +zmodule environment +zmodule git +zmodule input +zmodule termtitle +zmodule utility +zmodule completion +zmodule git-info +zmodule magicmace +zmodule zsh-users/zsh-completions +zmodule zsh-users/zsh-autosuggestions +zmodule zsh-users/zsh-history-substring-search +zmodule zdharma/fast-syntax-highlighting +zmodule supercrabtree/k +zmodule mafredri/zsh-async +zmodule hlissner/zsh-autopair +#zmodule cusxio/delta-prompt diff --git a/zsh/zshrc b/zsh/zshrc index 4e3c7bc..0a9631c 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -1,115 +1,14 @@ -export GOPATH=$HOME/go -export PATH=$PATH:$HOME/.gem/ruby/2.6.0 -export PATH=$PATH:$HOME/go/bin -export PATH=$PATH:/home/linuxbrew/.linuxbrew/bin -export PATH=$PATH:$HOME/.local/bin -export PATH=$PATH:/snap/bin -#export TERM=xterm-256color -export PATH=$PATH:/home/david/prog/flutter/bin -export TERM=xterm-256color -export TERM_ITALICS=true -export RANGER_LOAD_DEFAULT_RC="false" -#export TERM=screen-256color -export EDITOR=nvim -export XDG_CONFIG_HOME=/home/david/.config - -#autoload edit-command-line; zle -N edit-command-line -#bindkey '^v' edit-command-line - -alias av='source venv/bin/activate' -alias c='clear' -alias cdiff='colordiff' -alias cs='calcurse' -alias dv='deactivate' -alias gc='git config credential.helper store' -alias ipy='ipython' -alias l='ls -la' -alias lg='lazygit' -alias ms='mailsync' -alias mt='neomutt' -alias r='echo $RANGER_LEVEL' -alias pu='python3 -m pudb' -alias ra='ranger' -# ra() { - #if [ -z "$RANGER_LEVEL" ] - #then - #ranger - #else - #exit - #fi -#} -alias s='neofetch' -alias g='onefetch' -alias sra='sudo -E ranger' -alias sudo='sudo -E' -alias vim='nvim' -alias gs='git config credential.helper store' -alias bat='sudo tlp bat' -alias ac='sudo tlp ac' -alias gy='git-yolo' -alias nb='newsboat -r' -alias nt="sh -c 'cd $(pwd); st' > /dev/null 2>&1 &" -alias ta='tmux a' -alias t='tmux' - -bindkey -v -bindkey -M vicmd "k" vi-insert -bindkey -M vicmd "K" vi-insert-bol -bindkey -M vicmd "n" vi-backward-char -bindkey -M vicmd "i" vi-forward-char -bindkey -M vicmd "N" vi-beginning-of-line -bindkey -M vicmd "I" vi-end-of-line -bindkey -M vicmd "e" down-line-or-history -bindkey -M vicmd "u" up-line-or-history -bindkey -M vicmd "l" undo -#bindkey -M vicmd "-" vi-rev-repeat-search -bindkey -M vicmd "=" vi-repeat-search -bindkey -M vicmd "h" vi-forward-word-end - -#function zle-line-init zle-keymap-select { - #RPS1="${${KEYMAP/vicmd/-- NOR --}/(main|viins)/-- INS --}" - #RPS2=$RPS1 - #zle reset-prompt -#} - -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 - -# Use beam shape cursor on startup. -echo -ne '\e[5 q' - -# Use beam shape cursor for each new prompt. -preexec() { - echo -ne '\e[5 q' -} - -_fix_cursor() { - echo -ne '\e[5 q' -} -precmd_functions+=(_fix_cursor) +source ~/.config/zsh/env.zsh +source ~/.config/zsh/aliases.zsh +source ~/.config/zsh/plugins.zsh +source ~/.config/zsh/vi.zsh +source ~/.config/zsh/fzf.zsh -zle -N zle-line-init -zle -N zle-keymap-select - -KEYTIMEOUT=1 - -# fzf -export FZF_DEFAULT_OPTS='--bind ctrl-e:down,ctrl-u:up --preview "[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (ccat --color=always {} || highlight -O ansi -l {} || cat {}) 2> /dev/null | head -500"' -export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g ""' -export FZF_COMPLETION_TRIGGER='\' -export FZF_TMUX_HEIGHT='80%' -export FZF_PREVIEW_COMMAND='[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (ccat --color=always {} || highlight -O ansi -l {} || cat {}) 2> /dev/null | head -500' -source ~/.config/zsh/key-bindings.zsh -source ~/.config/zsh/completion.zsh if [ -f ~/.sconfig/zsh/zshrc ]; then source ~/.sconfig/zsh/zshrc fi +autopair-init +