diff options
| author | Paul Iannetta <paul.iannetta@ens-lyon.fr> | 2022-04-21 23:55:52 +0200 |
|---|---|---|
| committer | Paul Iannetta <paul.iannetta@ens-lyon.fr> | 2022-04-22 08:24:15 +0200 |
| commit | c86932296809fb0b9dec4af024869a0648ac8ffd (patch) | |
| tree | c07914419e289b0f1488f2322e31e459ef4a3b7f | |
| parent | e83c4515e0179221e7315abb606452ab2f7b561d (diff) | |
update zsh conf
| -rwxr-xr-x | .config/zsh/.zprofile | 1 | ||||
| -rwxr-xr-x | .config/zsh/.zshrc | 5 | ||||
| -rwxr-xr-x | .config/zsh/functions/mkcd | 3 | ||||
| -rwxr-xr-x[-rw-r--r--] | .config/zsh/plugin/vi-mode.plugin | 3 | ||||
| -rwxr-xr-x | .config/zsh/rc/alias.rc | 23 | ||||
| -rwxr-xr-x | .config/zsh/rc/completion.rc | 2 | ||||
| -rwxr-xr-x | .config/zsh/rc/env.rc | 26 | ||||
| -rwxr-xr-x | .config/zsh/rc/fzf-complete.rc | 195 | ||||
| -rwxr-xr-x | .config/zsh/rc/fzf-keys.rc | 87 | ||||
| -rwxr-xr-x | .config/zsh/rc/fzf.rc | 4 | ||||
| -rwxr-xr-x | .config/zsh/rc/history.rc | 6 | ||||
| -rwxr-xr-x | .config/zsh/rc/ocaml.rc | 2 | ||||
| -rwxr-xr-x | .config/zsh/rc/opam.rc | 2 | ||||
| -rwxr-xr-x | .config/zsh/rc/options.rc | 2 | ||||
| -rwxr-xr-x | .config/zsh/rc/prompt.rc | 5 | ||||
| -rwxr-xr-x[-rw-r--r--] | .zshenv | 14 |
16 files changed, 359 insertions, 21 deletions
diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/.config/zsh/.zprofile @@ -0,0 +1 @@ + diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index efe5097..6991dfa 100755 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,8 +1,11 @@ -# # This file is based on the configuration written by # Bruno Bonfils, <asyd@debian-fr.org> # Written since summer 2001 +# fix ubuntu fpath… +FPATH=/usr/share/zsh/site-functions/:$FPATH +FPATH=$ZDOTDIR/functions/:$FPATH + # colors eval `dircolors $ZDOTDIR/colors` diff --git a/.config/zsh/functions/mkcd b/.config/zsh/functions/mkcd new file mode 100755 index 0000000..373ee13 --- /dev/null +++ b/.config/zsh/functions/mkcd @@ -0,0 +1,3 @@ +# vim: set ft=zsh + +mkdir $1 && cd $1 diff --git a/.config/zsh/plugin/vi-mode.plugin b/.config/zsh/plugin/vi-mode.plugin index 8747a7e..44c11a1 100644..100755 --- a/.config/zsh/plugin/vi-mode.plugin +++ b/.config/zsh/plugin/vi-mode.plugin @@ -1,4 +1,7 @@ +# vim: ft=zsh + # Updates editor information when the keymap changes. + function zle-keymap-select() { zle reset-prompt zle -R diff --git a/.config/zsh/rc/alias.rc b/.config/zsh/rc/alias.rc index 060dc02..9514f36 100755 --- a/.config/zsh/rc/alias.rc +++ b/.config/zsh/rc/alias.rc @@ -1,3 +1,5 @@ +# vim: ft=zsh + # Git aliases ############## @@ -132,17 +134,18 @@ alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commi # ls aliases ############# -alias lla="ls -lah" -alias ls="ls --color=auto" -alias la="ls -ail" -alias l="ls -il" +alias ls="ls --color=auto --group-directories-first" +alias la="ls -ahl" +alias l="ls -lh" # do a du -hs on each dir on current path alias lsdir="for dir in *;do;if [ -d \$dir ];then;du -hsL \$dir;fi;done" # Mutt ####### -alias mutt="neomutt -F ~/.mail_config/mutt/muttrc" +alias mutt="neomutt -F ~/.config/mutt/muttrc" +alias m="offlineimap -c .config/offlineimap/offlineimaprc && neomutt -F ~/.config/mutt/muttrc" +alias fetchmail="offlineimap -c .config/offlineimap/offlineimaprc" # Vim ####### @@ -150,7 +153,12 @@ alias mutt="neomutt -F ~/.mail_config/mutt/muttrc" alias v="nvim" alias vim="nvim" -alias zconf="nvim $ZDOTDIR/**/* $ZDOTDIR/.zshrc ~/.zshenv" +# Config +######### + +zconf () { + nvim $HOME/.zshenv $(find $ZDOTDIR -type f) +} # Miscellaneous @@ -162,9 +170,10 @@ alias .....="cd ../../../.." alias ......="cd ../../../../.." alias setjplayout="setxkbmap -layout 'jp(OADG109A)'" -alias mydf="df -hPT | column -t" +alias mydf="df -hPT | grep -v snap" alias cl="clear" alias open="xdg-open" alias reboot="shutdown -r now" +autoload -Uz mkcd alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME' diff --git a/.config/zsh/rc/completion.rc b/.config/zsh/rc/completion.rc index ee6cce7..db4e180 100755 --- a/.config/zsh/rc/completion.rc +++ b/.config/zsh/rc/completion.rc @@ -1,3 +1,5 @@ +# vim: ft=zsh + # case-insensitive (uppercase from lowercase) completion zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' diff --git a/.config/zsh/rc/env.rc b/.config/zsh/rc/env.rc index 1ed8141..94c40c7 100755 --- a/.config/zsh/rc/env.rc +++ b/.config/zsh/rc/env.rc @@ -1,10 +1,19 @@ -# vim: syntax=sh +# vim: ft=zsh #environement variables -export PATH=$PATH:~/.local/bin -export PATH=$PATH:~/.cabal/bin -export PATH=$PATH:~/.cargo/bin -export EDITOR=vim +export PATH=~/.local/bin:$PATH +export PATH=~/.cabal/bin:$PATH +export PATH=~/.cargo/bin:$PATH +export PATH=~/.gem/ruby/2.7.0/bin:$PATH + +# Set editor to nvim or vim or to nothing +if [ -x $(command -v nvim) ]; then + export EDITOR=nvim +elif [ -x $(command -v vim) ]; then + export EDITOR=vim +else + export EDITOR= +fi # gnupg export GNUPGHOME=$XDG_CONFIG_HOME/gnupg @@ -19,4 +28,11 @@ export LESSKEY=$XDG_CONFIG_HOME/less/keys # mplayer export MPLAYER_HOME=$XDG_CONFIG_HOME/mplayer +# unison export UNISON=$XDG_CONFIG_HOME/unison + +# papers +export PAPERS_BANK=/home/lys/Documents/Work/these/these-pi/papers + +# info +export INFOPATH=/usr/share/info:$INFOPATH diff --git a/.config/zsh/rc/fzf-complete.rc b/.config/zsh/rc/fzf-complete.rc new file mode 100755 index 0000000..13f9b01 --- /dev/null +++ b/.config/zsh/rc/fzf-complete.rc @@ -0,0 +1,195 @@ +# vim: ft=zsh +# ____ ____ +# / __/___ / __/ +# / /_/_ / / /_ +# / __/ / /_/ __/ +# /_/ /___/_/-completion.zsh +# +# - $FZF_TMUX (default: 0) +# - $FZF_TMUX_HEIGHT (default: '40%') +# - $FZF_COMPLETION_TRIGGER (default: '**') +# - $FZF_COMPLETION_OPTS (default: empty) + +# To use custom commands instead of find, override _fzf_compgen_{path,dir} +if ! declare -f _fzf_compgen_path > /dev/null; then + _fzf_compgen_path() { + echo "$1" + command find -L "$1" \ + -name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \ + -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' + } +fi + +if ! declare -f _fzf_compgen_dir > /dev/null; then + _fzf_compgen_dir() { + command find -L "$1" \ + -name .git -prune -o -name .svn -prune -o -type d \ + -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' + } +fi + +########################################################### + +__fzfcmd_complete() { + [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] && + echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" +} + +__fzf_generic_path_completion() { + local base lbuf compgen fzf_opts suffix tail fzf dir leftover matches + base=$1 + lbuf=$2 + compgen=$3 + fzf_opts=$4 + suffix=$5 + tail=$6 + fzf="$(__fzfcmd_complete)" + + setopt localoptions nonomatch + eval "base=$base" + [[ $base = *"/"* ]] && dir="$base" + while [ 1 ]; do + if [[ -z "$dir" || -d ${dir} ]]; then + leftover=${base/#"$dir"} + leftover=${leftover/#\/} + [ -z "$dir" ] && dir='.' + [ "$dir" != "/" ] && dir="${dir/%\//}" + matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "$leftover" | while read item; do + echo -n "${(q)item}$suffix " + done) + matches=${matches% } + if [ -n "$matches" ]; then + LBUFFER="$lbuf$matches$tail" + fi + zle reset-prompt + break + fi + dir=$(dirname "$dir") + dir=${dir%/}/ + done +} + +_fzf_path_completion() { + __fzf_generic_path_completion "$1" "$2" _fzf_compgen_path \ + "-m" "" " " +} + +_fzf_dir_completion() { + __fzf_generic_path_completion "$1" "$2" _fzf_compgen_dir \ + "" "/" "" +} + +_fzf_feed_fifo() ( + command rm -f "$1" + mkfifo "$1" + cat <&0 > "$1" & +) + +_fzf_complete() { + local fifo fzf_opts lbuf fzf matches post + fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$" + fzf_opts=$1 + lbuf=$2 + post="${funcstack[2]}_post" + type $post > /dev/null 2>&1 || post=cat + + fzf="$(__fzfcmd_complete)" + + _fzf_feed_fifo "$fifo" + matches=$(cat "$fifo" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ') + if [ -n "$matches" ]; then + LBUFFER="$lbuf$matches" + fi + zle reset-prompt + command rm -f "$fifo" +} + +_fzf_complete_telnet() { + _fzf_complete '+m' "$@" < <( + command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' | + awk '{if (length($2) > 0) {print $2}}' | sort -u + ) +} + +_fzf_complete_ssh() { + _fzf_complete '+m' "$@" < <( + command cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host ' | command grep -v '[*?]' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \ + <(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \ + <(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') | + awk '{if (length($2) > 0) {print $2}}' | sort -u + ) +} + +_fzf_complete_export() { + _fzf_complete '-m' "$@" < <( + declare -xp | sed 's/=.*//' | sed 's/.* //' + ) +} + +_fzf_complete_unset() { + _fzf_complete '-m' "$@" < <( + declare -xp | sed 's/=.*//' | sed 's/.* //' + ) +} + +_fzf_complete_unalias() { + _fzf_complete '+m' "$@" < <( + alias | sed 's/=.*//' + ) +} + +fzf-completion() { + local tokens cmd prefix trigger tail fzf matches lbuf d_cmds + setopt localoptions noshwordsplit noksh_arrays noposixbuiltins + + # http://zsh.sourceforge.net/FAQ/zshfaq03.html + # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags + tokens=(${(z)LBUFFER}) + if [ ${#tokens} -lt 1 ]; then + zle ${fzf_default_completion:-expand-or-complete} + return + fi + + cmd=${tokens[1]} + + # Explicitly allow for empty trigger. + trigger=${FZF_COMPLETION_TRIGGER-'**'} + [ -z "$trigger" -a ${LBUFFER[-1]} = ' ' ] && tokens+=("") + + tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))} + # Kill completion (do not require trigger sequence) + if [ $cmd = kill -a ${LBUFFER[-1]} = ' ' ]; then + fzf="$(__fzfcmd_complete)" + matches=$(command ps -ef | sed 1d | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-50%} --min-height 15 --reverse $FZF_DEFAULT_OPTS --preview 'echo {}' --preview-window down:3:wrap $FZF_COMPLETION_OPTS" ${=fzf} -m | awk '{print $2}' | tr '\n' ' ') + if [ -n "$matches" ]; then + LBUFFER="$LBUFFER$matches" + fi + zle reset-prompt + # Trigger sequence given + elif [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then + d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}) + + [ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}} + [ -z "${tokens[-1]}" ] && lbuf=$LBUFFER || lbuf=${LBUFFER:0:-${#tokens[-1]}} + + if eval "type _fzf_complete_${cmd} > /dev/null"; then + eval "prefix=\"$prefix\" _fzf_complete_${cmd} \"$lbuf\"" + elif [ ${d_cmds[(i)$cmd]} -le ${#d_cmds} ]; then + _fzf_dir_completion "$prefix" "$lbuf" + else + _fzf_path_completion "$prefix" "$lbuf" + fi + # Fall back to default completion + else + zle ${fzf_default_completion:-expand-or-complete} + fi +} + +[ -z "$fzf_default_completion" ] && { + binding=$(bindkey '^I') + [[ $binding =~ 'undefined-key' ]] || fzf_default_completion=$binding[(s: :w)2] + unset binding +} + +zle -N fzf-completion +bindkey '^I' fzf-completion diff --git a/.config/zsh/rc/fzf-keys.rc b/.config/zsh/rc/fzf-keys.rc new file mode 100755 index 0000000..de749f6 --- /dev/null +++ b/.config/zsh/rc/fzf-keys.rc @@ -0,0 +1,87 @@ +# vim: ft=zsh + +# Key bindings +# ------------ +if [[ $- == *i* ]]; then + +# CTRL-T - Paste the selected file path(s) into the command line +__fsel() { + local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ + -o -type f -print \ + -o -type d -print \ + -o -type l -print 2> /dev/null | cut -b3-"}" + setopt localoptions pipefail 2> /dev/null + eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do + echo -n "${(q)item} " + done + local ret=$? + echo + return $ret +} + +__fzf_use_tmux__() { + [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] +} + +__fzfcmd() { + __fzf_use_tmux__ && + echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf" +} + +fzf-file-widget() { + LBUFFER="${LBUFFER}$(__fsel)" + local ret=$? + zle reset-prompt + return $ret +} +zle -N fzf-file-widget +bindkey '^T' fzf-file-widget + +# Ensure precmds are run after cd +fzf-redraw-prompt() { + local precmd + for precmd in $precmd_functions; do + $precmd + done + zle reset-prompt +} +zle -N fzf-redraw-prompt + +# ALT-C - cd into the selected directory +fzf-cd-widget() { + local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ + -o -type d -print 2> /dev/null | cut -b3-"}" + setopt localoptions pipefail 2> /dev/null + local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)" + if [[ -z "$dir" ]]; then + zle redisplay + return 0 + fi + cd "$dir" + local ret=$? + zle fzf-redraw-prompt + return $ret +} +zle -N fzf-cd-widget +bindkey '\ec' fzf-cd-widget + +# CTRL-R - Paste the selected command from history into the command line +fzf-history-widget() { + local selected num + setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null + selected=( $(fc -rl 1 | + FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) ) + local ret=$? + if [ -n "$selected" ]; then + num=$selected[1] + if [ -n "$num" ]; then + zle vi-fetch-history -n $num + fi + fi + zle reset-prompt + return $ret +} +zle -N fzf-history-widget +bindkey '^R' fzf-history-widget + +fi diff --git a/.config/zsh/rc/fzf.rc b/.config/zsh/rc/fzf.rc new file mode 100755 index 0000000..75daaae --- /dev/null +++ b/.config/zsh/rc/fzf.rc @@ -0,0 +1,4 @@ +# vim: ft=zsh + +FZF_ALT_C_COMMAND=bfs +FZF_CTRL_T_COMMAND=bfs diff --git a/.config/zsh/rc/history.rc b/.config/zsh/rc/history.rc index cc1e892..1df2147 100755 --- a/.config/zsh/rc/history.rc +++ b/.config/zsh/rc/history.rc @@ -1,11 +1,11 @@ -# vim: syntax=sh +# vim: ft=zsh export HISTSIZE=1000 # nb of line in internal history export SAVEHIST=5000 # nb of line stored in $HISTFILE export HISTFILE=$XDG_CACHE_HOME/zsh/zsh_history setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format. -#setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. +# setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. setopt SHARE_HISTORY # Share history between all sessions. setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history. setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again. @@ -14,5 +14,5 @@ setopt HIST_FIND_NO_DUPS # Do not display a line previously found. setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space. setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file. setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry. -setopt HIST_VERIFY # Don't execute immediately upon history expansion. +# setopt HIST_VERIFY # Don't execute immediately upon history expansion. setopt HIST_BEEP # Beep when accessing nonexistent history. diff --git a/.config/zsh/rc/ocaml.rc b/.config/zsh/rc/ocaml.rc index e74e143..58230b3 100755 --- a/.config/zsh/rc/ocaml.rc +++ b/.config/zsh/rc/ocaml.rc @@ -1,2 +1,4 @@ +# vim: ft=zsh + # OPAM configuration . /home/paul/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true diff --git a/.config/zsh/rc/opam.rc b/.config/zsh/rc/opam.rc index b25377c..58230b3 100755 --- a/.config/zsh/rc/opam.rc +++ b/.config/zsh/rc/opam.rc @@ -1,4 +1,4 @@ - +# vim: ft=zsh # OPAM configuration . /home/paul/.opam/opam-init/init.zsh > /dev/null 2> /dev/null || true diff --git a/.config/zsh/rc/options.rc b/.config/zsh/rc/options.rc index bc91ccb..f6b0968 100755 --- a/.config/zsh/rc/options.rc +++ b/.config/zsh/rc/options.rc @@ -1,3 +1,5 @@ +# vim: ft=zsh + setopt CORRECT setopt ALWAYS_TO_END setopt NOTIFY diff --git a/.config/zsh/rc/prompt.rc b/.config/zsh/rc/prompt.rc index 9792215..ce0e39d 100755 --- a/.config/zsh/rc/prompt.rc +++ b/.config/zsh/rc/prompt.rc @@ -1,3 +1,5 @@ +# vim: ft=zsh + # for have colors autoload -U colors colors @@ -14,4 +16,5 @@ end="%{$fg[$cmd_color]%}%%%{$reset_color%} " #PS1=" $cpath $end" PS1=" $end" -#RPS1="$host" +RPS1="#%h" +#RPS1="$host#%h" @@ -1,3 +1,11 @@ -export XDG_CACHE_HOME=/home/paul/.cache -export XDG_CONFIG_HOME=/home/paul/.config -export ZDOTDIR=/home/paul/.config/zsh +export XDG_CACHE_HOME=/home/lys/.cache +export XDG_CONFIG_HOME=/home/lys/.config +export ZDOTDIR=/home/lys/.config/zsh +export TERM=screen +export PAPERS_BANK=/home/lys/Documents/Work/these/these-pi/papers +eval $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh,gpg) +eval $(/usr/bin/gnome-keyring-daemon --start --components=pkcs11,secrets,ssh,gpg) +export SSH_AUTH_SOCK +. "$HOME/.cargo/env" +. "$HOME/.profile" +. "$ZDOTDIR/rc/env.rc" |
