From d0382ac857db24d7b72bf60c77e347596e9c7e52 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 11 Feb 2021 00:57:36 +0300 Subject: [PATCH] I learn zsh --- bin/bin/pe | 2 +- bin/bin/zsnap.zsh | 70 ++++++++++++++++++++++----------------- vim/.vim/plugin/zshfe.zsh | 2 +- zsh/.zshenv | 46 ++++++++++++++----------- zsh/.zshrc | 20 +++++------ 5 files changed, 77 insertions(+), 63 deletions(-) diff --git a/bin/bin/pe b/bin/bin/pe index 48b7ede..bcd149b 100755 --- a/bin/bin/pe +++ b/bin/bin/pe @@ -6,4 +6,4 @@ path-extractor | while read fn ; do seen+=($fn 1) print $fn done | fzf -m | tr "\n" " " | read data -tmux set-buffer "${data:- }" +tmux set-buffer ${data:- } diff --git a/bin/bin/zsnap.zsh b/bin/bin/zsnap.zsh index a14979b..a75650c 100755 --- a/bin/bin/zsnap.zsh +++ b/bin/bin/zsnap.zsh @@ -1,65 +1,73 @@ -#!/bin/zsh -e +#!/usr/bin/env zsh + +set -e usage() { -cat < $dst/$latest.zfs.zst.gpg + dst=$3 + [[ -d $dst ]] || usage + setopt PIPE_FAIL + zfs send -Rv $latest | zstd | ${=enccmd} > \ + $dst/$latest_filename.zfs.zst.gpg sync - touch $dst/$latest.from + touch $dst/$latest_filename.from ;; sync) - dst="$3" - [ -d "$dst" ] || usage - latest_dst=$(find $dst -type f -name "*.from" | sort -rn | sed -n 1p) - [ -n "$latest_dst" ] - latest_dst=$(basename ${latest_dst%.from}) - [ "$latest_dst" != "$latest" ] - set PIPE_FAIL - zfs send -Rv -i $latest_dst $latest | zstd | ${=enccmd} > $dst/$latest.zfs.zst.gpg + dst=$3 + [[ -d $dst ]] || usage + latest_dst=($dst/*(.Onn[1])) + [[ $latest_dst ]] + latest_dst=${latest_dst[1]} + latest_dst=${${latest_dst##*/}%.from} + [[ $latest_dst != $latest_filename ]] + setopt PIPE_FAIL + zfs send -Rv -i ${latest_dst:gs#%#/} $latest | zstd | ${=enccmd} > \ + $dst/$latest_filename.zfs.zst.gpg sync - echo "$latest_dst" > $dst/$latest.from + print $latest_dst > $dst/$latest_filename.from ;; clean) - count="$3" - [ -n "$count" ] || usage + count=$3 + [[ -n $count ]] || usage count=$(( $count + 1 )) - for snap in $(echo $snaps) ; do + for snap in $snaps ; do count=$(( $count - 1 )) - [ $count -le 0 ] || continue + [[ $count -le 0 ]] || continue zfs destroy -Rv $snap done ;; diff --git a/vim/.vim/plugin/zshfe.zsh b/vim/.vim/plugin/zshfe.zsh index 0dfcd68..b0d8cd9 100755 --- a/vim/.vim/plugin/zshfe.zsh +++ b/vim/.vim/plugin/zshfe.zsh @@ -5,4 +5,4 @@ zmodload zsh/zpty zpty zshfe zsh zpty -w zshfe "print ZSHFE $*"$'\t EFHSZ\nexit\n' zpty -r zshfe zshfe "*exit" -echo "$zshfe" | sed -n "s/^ZSHFE \(.*\) EFHSZ/\1/p" +echo $zshfe | sed -n "s/^ZSHFE \(.*\) EFHSZ/\1/p" diff --git a/zsh/.zshenv b/zsh/.zshenv index 9bb0605..ff28109 100644 --- a/zsh/.zshenv +++ b/zsh/.zshenv @@ -8,7 +8,7 @@ SAVEHIST=10240 # Terminal {{{ export COLORFGBG="default;default;0" -export COLORTERM="xterm-256color" +export COLORTERM=xterm-256color [ "$TERM" = "screen-256color" ] || TERM=xterm-256color export TERM # }}} @@ -21,7 +21,7 @@ export LESS=RXij3 # ls options {{{ export CLICOLOR=1 -export LSCOLORS="BxGxcxdxCxegDxabagacad" +export LSCOLORS=BxGxcxdxCxegDxabagacad # }}} # Lynx options {{{ @@ -54,32 +54,38 @@ export XDG_RUNTIME_DIR=/tmp/stargrave-xdg # }}} # Paths {{{ -export CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" -export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin -export PATH=$HOME/local/bin:$HOME/bin:$PATH -export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH - -export MANPATH=/usr/local/share/man:/usr/local/man:/usr/share/man -export MANPATH=/usr/share/openssl/man:$MANPATH -export MANPATH=/usr/local/lib/perl5/site_perl/man:$MANPATH -export MANPATH=/usr/local/lib/perl5/5.26/perl/man:$MANPATH -export MANPATH=$HOME/local/share/man:$MANPATH - -export INFOPATH=/usr/local/share/info:/usr/local/info:$HOME/local/share/info - -export MANPATH=$HOME/src/suckless/tabbed:$MANPATH -export PATH=$HOME/src/suckless/tabbed:$PATH +path=(~/bin ~/local/bin /usr/local/bin /usr/local/sbin /usr/bin /usr/sbin /bin /sbin) +manpath=( + ~/local/share/man + /usr/local/lib/perl5/5.26/perl/man + /usr/local/lib/perl5/site_perl/man + /usr/share/openssl/man + /usr/local/share/man + /usr/local/man + /usr/share/man +) +export -TU INFOPATH infopath +infopath=(~/local/share/info /usr/local/share/info /usr/local/info) + +manpath=(~/src/suckless/tabbed $manpath) +path=(~/src/suckless/tabbed $path) + +path=(~/work/goredo $path) +# }}} -export PATH=$HOME/work/goredo:$PATH +# C related {{{ +export CFLAGS="-I/usr/local/include" +export LDFLAGS="-L/usr/local/lib" +export -TU LD_LIBRARY_PATH ld_library_path +ld_library_path=(~/local/lib) # }}} # Go related {{{ -export PATH=$HOME/work/go/bin:$PATH export GOCACHE=/tmp/go-cache export GOPROXY=direct export GOSUMDB=off export GOPATH=$HOME/work/gopath -export PATH=$GOPATH/bin:$PATH +path=($GOPATH/bin ~/work/go/bin $path) # }}} # Various {{{ diff --git a/zsh/.zshrc b/zsh/.zshrc index 387f852..c8591ba 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -41,7 +41,7 @@ bindkey "^[[A" history-beginning-search-backward-end bindkey "^[[B" history-beginning-search-forward-end beginning-history-incremental-pattern-search-backward() { - zle history-incremental-pattern-search-backward $(echo $BUFFER | sed "s/ /*/g") + zle history-incremental-pattern-search-backward ${BUFFER:gs/ /*/} } zle -N beginning-history-incremental-pattern-search-backward bindkey "^[[1;2A" beginning-history-incremental-pattern-search-backward @@ -51,14 +51,14 @@ bindkey -M isearch "^[[B" history-incremental-pattern-search-forward # Prompt {{{ function zle-line-init zle-keymap-select { - mode_vi="${${KEYMAP/vicmd/+}/(main|viins)/-}" - [ $timer ] && timer_show=$(( $SECONDS - $timer )) + mode_vi=${${KEYMAP/vicmd/+}/(main|viins)/-} + [[ $timer ]] && timer_show=$(( $SECONDS - $timer )) prompt="%2~|" prompt+="%U${timer_show}%u|" prompt+="%B%?%b" prompt+="${mode_vi}" prompt+="%B%F{magenta}%#%f%b " - PS1="$prompt" + PS1=$prompt zle reset-prompt } zle -N zle-line-init @@ -92,7 +92,7 @@ f() { } ssht() { - ssh -C -t "$1" tmux attach -t0 + ssh -C -t $1 tmux attach -t0 } alias sshnm="ssh -S none" # }}} @@ -174,11 +174,11 @@ bindkey -s "OP" " inc\n" # F1 zstyle ":completion:*:functions" ignored-patterns "_*" zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}' _mycomp () { - [ "$words[1]" != "man" ] || { _man && return 0 } - [ $CURRENT -eq 1 ] && _command_names || _files && return 0 + [[ ${words[1]} != man ]] || { _man && return 0 } + [[ $CURRENT -eq 1 ]] && _command_names || _files && return 0 # MAGIC_EQUAL_SUBST {{{ - [[ "$PREFIX" = *\=* ]] || return 1 - compstate[parameter]="${PREFIX%%\=*}" + [[ $PREFIX = *\=* ]] || return 1 + compstate[parameter]=${PREFIX%%\=*} compset -P 1 "*=" _value # }}} @@ -215,6 +215,6 @@ export FZF_DEFAULT_OPTS="--color=16 --info=inline" cf() { local dir=$(find ${1:-.} -path "*/\.git" -prune -o -type d -print | fzf --height 40% --reverse --preview="tree -CN {}") - [[ -z "$dir" ]] || cd "$dir" + [[ -z $dir ]] || cd $dir } # }}} -- 2.44.0