config/zsh: improve shell startup

This commit is contained in:
xeruf 2021-12-14 19:46:28 +01:00
parent 5457718f21
commit 927a0b1f13
4 changed files with 28 additions and 25 deletions

View File

@ -80,7 +80,7 @@ pathadd() {
} }
# ZSH completion and stuff {{{1 # ZSH completion and stuff {{{1
alias rs="reset && source ~/.zprofile && exec $SHELL" alias rs="reset && exec $SHELL"
alias hist='print -z $(history | tac | fzf --tiebreak=index --bind='"'"'del:execute(sed "\;$(echo {4..})$d" -i.bak $HISTFILE)'"'"' | sed "s|^ \+||" | cut -d" " -f5-)' alias hist='print -z $(history | tac | fzf --tiebreak=index --bind='"'"'del:execute(sed "\;$(echo {4..})$d" -i.bak $HISTFILE)'"'"' | sed "s|^ \+||" | cut -d" " -f5-)'
# Edit shell config files # Edit shell config files
@ -90,7 +90,7 @@ edshell() {
case $1 in case $1 in
("") file="$CONFIG_SHELL_FUNCTIONS";; ("") file="$CONFIG_SHELL_FUNCTIONS";;
(zsh) file="$CONFIG_ZSH/.zshrc";; (zsh) file="$CONFIG_ZSH/.zshrc";;
(prof*) file="$HOME/.zprofile";; (env) file="$HOME/.zshenv";;
(-f) grepfile="$(grep --recursive "\(^$2()\|alias $2=\)" $CONFIG_SHELLS -n -m 1)" (-f) grepfile="$(grep --recursive "\(^$2()\|alias $2=\)" $CONFIG_SHELLS -n -m 1)"
file="$(echo "$grepfile" | cut -d':' -f1)" file="$(echo "$grepfile" | cut -d':' -f1)"
line="$(echo "$grepfile" | cut -d':' -f2)" line="$(echo "$grepfile" | cut -d':' -f2)"
@ -99,12 +99,10 @@ edshell() {
esac esac
test -f "$file" && checksum="$(md5sum "$file")" test -f "$file" && checksum="$(md5sum "$file")"
$EDITOR "$(test "$line" && echo "+normal! ${line}ggzx" || echo "--")" "${file%:*}" $EDITOR "$(test "$line" && echo "+normal! ${line}ggzx" || echo "--")" "${file%:*}"
#test -f "$file" || return 1 test -s "$file" || return 1
test "$checksum" != "$(md5sum $file)" && test "$checksum" != "$(md5sum $file)" && rs
source "$HOME/.zprofile" && exec $SHELL
} }
# Edit a file in the PATH # Edit a file in the PATH
edbin() { edbin() {
f="$(which $1 2>/dev/null)" && test -f "$f" && edit "$f" || f="$(which $1 2>/dev/null)" && test -f "$f" && edit "$f" ||
@ -187,8 +185,13 @@ alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
alias delta="sc restart openvpn-client@deltaPeak.service" alias delta="sc restart openvpn-client@deltaPeak.service"
sshl() { sshl() {
lemonade server -allow 127.0.0.1 & lemonade server -allow 127.0.0.1 &
ssh-copy-id -i "$(ssh -G "$1" | grep "^identityfile " | head -1 | cut -d " " -f2- | sed "s|^~|$HOME|")" "$1" file="/var/tmp/ssh-$1"
kitty +kitten ssh -R 2489:127.0.0.1:2489 "$@" if test ! -e "$file"; then
ssh-copy-id -i "$(ssh -G "$1" | grep "^identityfile " | head -1 | cut -d " " -f2- | sed "s|^~|$HOME|")" "$1" &&
kitty +kitten ssh -R 2489:127.0.0.1:2489 "$@" &&
touch "$file"
else ssh "$@"
fi
} }
# Listen to loopback of mic # Listen to loopback of mic
@ -298,6 +301,7 @@ which perl-rename >/dev/null &&
alias lowercase="perl-rename -iv '$lowercase_transliterate'" || alias lowercase="perl-rename -iv '$lowercase_transliterate'" ||
alias lowercase="rename -iv '$lowercase_transliterate'" alias lowercase="rename -iv '$lowercase_transliterate'"
# TODO replace cp by rsync, automatically use compression for remote transfers
# rsync directory properly - suffix both dirs with / to act on contents # rsync directory properly - suffix both dirs with / to act on contents
alias rcn='rsync -v --recursive --human-readable --links --dry-run' alias rcn='rsync -v --recursive --human-readable --links --dry-run'
rcd() { rcn --size-only "$@" | tail +2 | tree --fromfile . | less -F; } rcd() { rcn --size-only "$@" | tail +2 | tree --fromfile . | less -F; }

View File

@ -1,5 +1,5 @@
[alias] [alias]
cgit = !yadm cme "config/git:" $XDG_CONFIG_HOME/git $CONFIG_SHELLS/git $HOME/.local/bin/scripts/git-* cgit = !yadm cme "config/git:" $XDG_CONFIG_HOME/git $CONFIG_SHELLS/git $HOME/.local/bin/scripts/git-*
cshell = !yadm cme "config/shell:" $CONFIG_SHELLS $HOME/.zprofile cshell = !yadm cme "config/shell:" $CONFIG_SHELLS $HOME/.zshenv
cf = !yadm cme "bin:" $CONFIG_SHELLS/functions $HOME/.local/bin/scripts cf = !yadm cme "bin:" $CONFIG_SHELLS/functions $HOME/.local/bin/scripts
cbin = !yadm cme "bin:" $HOME/.local/bin/scripts cbin = !yadm cme "bin:" $HOME/.local/bin/scripts

View File

@ -144,6 +144,7 @@ export KEYTIMEOUT=1
# turn on spelling correction # turn on spelling correction
setopt correct setopt correct
CORRECT_IGNORE="[_|.]*"
# command history - https://unix.stackexchange.com/a/273863 # command history - https://unix.stackexchange.com/a/273863
HISTSIZE=100000 HISTSIZE=100000
SAVEHIST=$HISTSIZE SAVEHIST=$HISTSIZE
@ -176,28 +177,25 @@ done
# GENERATED SHIT # GENERATED SHIT
test -e /usr/share/zsh/manjaro-zsh-config && source_existing() {
source /usr/share/zsh/manjaro-zsh-config for arg
do test -s "$arg" && source "$arg"
done
}
export NVM_DIR="$HOME/.nvm" source_existing /usr/share/zsh/manjaro-zsh-config
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm source_existing $CONFIG_ZSH/.p10k.zsh # To customize prompt, run `p10k configure` or edit .p10k.zsh.
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion source_existing /usr/share/fzf/key-bindings.zsh /usr/share/fzf/completion.zsh
# To customize prompt, run `p10k configure` or edit .p10k.zsh. source_existing "$NVM_DIR/nvm.sh"
test -s $CONFIG_ZSH/.p10k.zsh && source_existing "$NVM_DIR/bash_completion"
source $CONFIG_ZSH/.p10k.zsh
test -d /usr/share/fzf && source_existing $XDG_CONFIG_HOME/broot/launcher/bash/br
source /usr/share/fzf/key-bindings.zsh && source /usr/share/fzf/completion.zsh
which zoxide >/dev/null && which zoxide >/dev/null &&
eval "$(zoxide init zsh)" eval "$(zoxide init zsh)"
test -f $XDG_CONFIG_HOME/broot/launcher/bash/br && source_existing /home/janek/.nix-profile/etc/profile.d/nix.sh
source $XDG_CONFIG_HOME/broot/launcher/bash/br
# Nix
test -e /home/janek/.nix-profile/etc/profile.d/nix.sh && source /home/janek/.nix-profile/etc/profile.d/nix.sh
which direnv >/dev/null && eval "$(direnv hook zsh)" which direnv >/dev/null && eval "$(direnv hook zsh)"
true true

View File

@ -30,6 +30,7 @@ export RLWRAP_HOME="$XDG_DATA_HOME"/rlwrap
export GOPATH="$XDG_STATE_HOME"/go export GOPATH="$XDG_STATE_HOME"/go
export CARGO_HOME="$XDG_DATA_HOME"/cargo export CARGO_HOME="$XDG_DATA_HOME"/cargo
export RUSTUP_HOME="$XDG_DATA_HOME"/rustup export RUSTUP_HOME="$XDG_DATA_HOME"/rustup
export NVM_DIR="$XDG_DATA_HOME"/nvm
export CABAL_CONFIG="$XDG_CONFIG_HOME"/cabal/config export CABAL_CONFIG="$XDG_CONFIG_HOME"/cabal/config
export CABAL_DIR="$XDG_CACHE_HOME"/cabal export CABAL_DIR="$XDG_CACHE_HOME"/cabal