1
1
Fork 0

zshrc: Modernize and backport a bunch from fish

This commit is contained in:
Jonathan Schleifer 2020-02-14 01:40:46 +00:00
parent 3b305d4571
commit 69ff722e06

139
zshrc
View file

@ -5,7 +5,6 @@ LISTMAX=32768
WORDCHARS="*?[];!#~" WORDCHARS="*?[];!#~"
local grep="" local grep=""
local grep_color="auto" local grep_color="auto"
local fgrep=""
local ls="" local ls=""
local ls_color="auto" local ls_color="auto"
local ls_on_cd="yes" local ls_on_cd="yes"
@ -36,59 +35,37 @@ compinit -C
# Ignore case on completion # Ignore case on completion
zstyle ':completion:*' matcher-list 'm:{A-Z}={a-z} m:{a-z}={A-Z}' zstyle ':completion:*' matcher-list 'm:{A-Z}={a-z} m:{a-z}={A-Z}'
__find_command() {
which "$1" &>/dev/null && echo "$1" || echo "$2"
}
if [ -n "$grep" -o -n "$grep_color" ]; then if [ -n "$grep" -o -n "$grep_color" ]; then
if [ -z "$grep" ]; then : ${grep:=$(__find_command ggrep grep)}
if which ggrep &>/dev/null; then [ -n "$grep_color" -a "$grep_color[1]" != - ] &&
grep="ggrep"
else
grep="grep"
fi
fi
[ -n "$grep_color" -a "$grep_color[1]" != "-" ] && \
grep_color="--color=$grep_color" grep_color="--color=$grep_color"
alias grep="$grep $grep_color" alias grep="$grep $grep_color"
fi fi
alias fgrep="grep -F"
if [ -n "$fgrep" -o -n "$grep_color" ]; then
if [ -z "$fgrep" ]; then
if which ggrep &>/dev/null; then
fgrep="ggrep -F"
else
fgrep="fgrep"
fi
fi
[ -n "$grep_color" -a "$grep_color[1]" != "-" ] && \
grep_color="--color=$grep_color"
alias fgrep="$fgrep $grep_color"
fi
if [ -n "$ls" -o -n "$ls_color" ]; then if [ -n "$ls" -o -n "$ls_color" ]; then
if [ -z "$ls" ]; then : ${ls:=$(__find_command gls ls)}
if which gls &>/dev/null; then [ -n "$ls_color" -a "$ls_color[1]" != - ] &&
ls="gls"
else
ls="ls"
fi
fi
[ -n "$ls_color" -a "$ls_color[1]" != "-" ] && \
ls_color="--color=$ls_color" ls_color="--color=$ls_color"
alias ls="$ls $ls_color" alias ls="$ls $ls_color"
fi fi
[ "$ls_on_cd" = yes ] && chpwd() { ls }
[ "$ls_on_init" = yes ] && ls
if [ "$ls_on_cd" = "yes" ]; then case $TERM_PROGRAM in
chpwd() { Apple_Terminal)
ls __update_terminal_cwd() {
} printf '\e]7;%s\a' "file://$HOSTNAME${PWD// /%20}"
fi }
;;
if [ "$TERM_PROGRAM" = "Apple_Terminal" ]; then *)
update_terminal_cwd() { __update_terminal_cwd() {}
printf '\e]7;%s\a' "file://$HOSTNAME${PWD// /%20}" ;;
} esac
else
update_terminal_cwd() {
}
fi
set_prompt() { set_prompt() {
PS1="%m:%c$@%B%(!.#.$)%b " PS1="%m:%c$@%B%(!.#.$)%b "
@ -99,48 +76,39 @@ set_prompt() {
} }
set_prompt set_prompt
_precmd() { __precmd() {
update_terminal_cwd update_terminal_cwd
local branch_name local branch_name=$(git symbolic-ref HEAD 2>/dev/null)
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" branch_name=${branch_name##refs/heads/}
branch_name="${branch_name##refs/heads/}" if [ -n "$branch_name" -a "$branch_name" != master ]; then
if [ -n "$branch_name" -a "$branch_name" != "master" ]; then local branch="%{$(print "\e[1;30m")%}("
local branch
branch="%{$(print "\e[1;30m")%}("
branch+="%{$(print "\e[0;36m")%}$branch_name" branch+="%{$(print "\e[0;36m")%}$branch_name"
branch+="%{$(print "\e[1;30m")%})%{$(print "\e[0m")%}" branch+="%{$(print "\e[1;30m")%})%{$(print "\e[0m")%}"
set_prompt "$branch"
else
set_prompt
fi fi
set_prompt $branch
} }
case $TERM in case $TERM in
aterm|Eterm|rxvt*|uxterm*|xterm*) aterm|Eterm|rxvt*|uxterm*|xterm*)
# Use set_title if you want to change the term title # Use set_title if you want to change the term title
set_title() { set_title() {
# Without this, precmd would override it # Without this, precmd would override it
precmd() { precmd() { __precmd }
_precmd
}
print -Pn "\e]0;$@\a" print -Pn "\e]0;$@\a"
} }
unset_title() { unset_title() {
precmd() { precmd() {
print -Pn "\e]0;%m:%c\a" print -Pn "\e]0;%m:%c\a"
_precmd __precmd
} }
} }
unset_title unset_title
;; ;;
*) *)
precmd() { precmd() { __precmd }
_precmd
}
;; ;;
esac esac
@ -163,7 +131,7 @@ extr() {
ofarc -x $i ofarc -x $i
;; ;;
*.txz | *.tar.xz) *.txz | *.tar.xz)
xzcat $i | tar xfv - xzcat $i | ofarc -ttar -x -
;; ;;
*.rar) *.rar)
unrar x $i unrar x $i
@ -193,14 +161,49 @@ do
alias -s "$ext=extr" alias -s "$ext=extr"
done done
[ "$EDITOR" = "vim" ] && alias vi=vim [ "$EDITOR" = vim ] && alias vi=vim
which gpg2 &>/dev/null && alias gpg=gpg2 which gpg2 &>/dev/null && alias gpg=gpg2
[ "$ls_on_init" = "yes" ] && ls make() {
case "$PWD" in
function ixio() { # pkgsrc needs bmake and does not like MAKEFLAGS including -j.
curl -F 'f:1=<-' ix.io */pkgsrc | */pkgsrc/*)
MAKEFLAGS= =$(__find_command bmake make) $@
;;
*)
=make $@
;;
esac
} }
# pkgsrc does not like MAKEFLAGS including -j
which pkg_chk &>/dev/null && alias pkg_chk="MAKEFLAGS= pkg_chk"
which pkg_rolling-replace &>/dev/null &&
alias pkg_rolling-replace="MAKEFLAGS= pkg_rolling-replace"
which url2pkg &>/dev/null && alias url2pkg="MAKEFLAGS= url2pkg"
alias gpg-ssh="SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh ssh"
alias gpg-ssh-add="SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh ssh-add"
alias gpg-sftp="SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh sftp"
__pw() {
local clipboard
if which pbcopy &>/dev/null; then
clipboard=pbcopy
elif which xclip &>/dev/null; then
clipboard=xclip
else
echo "No clipboard handler found!"
return 1
fi
cryptopassphrase $@ | tr -d '\n' | $clipboard
}
alias pw="__pw -k ~/.cryptopassphrase.key"
alias pws="__pw -k ~/.cryptopassphrase-server.key"
ixio() { curl -F 'f:1=<-' ix.io }
0x0st() { curl -F'file=@-' https://0x0.st }
unset fgrep grep grep_color ls ls_color ls_on_cd ls_on_init unset fgrep grep grep_color ls ls_color ls_on_cd ls_on_init
unset HISTFILE unset HISTFILE