dotfiles/.zshrc2

170 lines
5.3 KiB
Plaintext
Raw Normal View History

# env for shell
2022-05-07 16:19:39 +08:00
export TERM="xterm-256color"
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export PATH="$PATH:$DOTFILES/scripts"
export EDITOR='vim'
# env for apps
export PYTHONIOENCODING='UTF-8'
export GPG_TTY=$(tty)
export LESS_TERMCAP_md=$'\E[01;33m'
2022-05-07 16:19:39 +08:00
# antigen
if [[ -z "$DFS_NO_WALL" ]]; then
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
ANTIGEN_PLUGINS=( \
"https://gitee.com/dictxiong/zsh-syntax-highlighting" \
"https://gitee.com/dictxiong/zsh-completions" \
"https://gitee.com/dictxiong/zsh-autosuggestions" \
)
else
ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
ANTIGEN_PLUGINS=( \
"https://github.com/zsh-users/zsh-syntax-highlighting" \
"https://github.com/zsh-users/zsh-completions" \
"https://github.com/zsh-users/zsh-autosuggestions" \
)
fi
2022-05-07 16:19:39 +08:00
ANTIGEN="$HOME/antigen.zsh"
# Install antigen.zsh if not exist
if [ ! -f "$ANTIGEN" ]; then
echo "Installing antigen ..."
TMPFILE="/tmp/antigen.zsh"
if [ -x "$(which curl)" ]; then
curl -L "$ANTIGEN_URL" -o "$TMPFILE"
elif [ -x "$(which wget)" ]; then
wget "$ANTIGEN_URL" -O "$TMPFILE"
else
echo "ERROR: please install curl or wget before installation !!"
exit
fi
if [ ! $? -eq 0 ]; then
echo ""
echo "ERROR: downloading antigen.zsh ($ANTIGEN_URL) failed !!"
exit
fi;
echo "move $TMPFILE to $ANTIGEN"
mv "$TMPFILE" "$ANTIGEN"
2022-05-07 16:19:39 +08:00
fi
# config and enable antigen
source "$ANTIGEN"
# enable plugins
antigen use oh-my-zsh
ANTIGEN_PLUGINS+=( \
"command-not-found" \
"docker" \
"extract" \
"fzf" \
"git" \
"ripgrep" \
"tmux" \
"ufw" \
"z" \
)
for i in ${ANTIGEN_PLUGINS[*]}; do
if [[ -z $ANTIGEN_EXCLUDE || ! $i =~ $ANTIGEN_EXCLUDE ]]; then
antigen bundle $i
fi
done
2022-05-07 16:19:39 +08:00
# select theme
TMP_THEME=ys
if [[ -e /.dockerenv ]]; then
TMP_THEME=blinks
echo "==========================="
echo "This is in docker container"
echo "==========================="
fi
antigen theme ${ZSH_THEME:-$TMP_THEME}
2022-05-07 16:19:39 +08:00
# apply
antigen apply
# end of antigen config
# alias
alias "pls"='sudo $(fc -ln -1)'
alias "se"='sudo -sE'
alias "pbd"='ping baidu.com'
alias "p114"='ping 114.114.114.114'
alias "p666"='ping6 2001:da8::666'
alias "git-branches"='git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset)) %(authorname)"'
sibd() { ssh -p 12022 root@$1${1:+.}ibd.ink }
sob() { ssh -p 24022 root@$1${1:+.}ob.ac.cn }
snasp() { ssh -o ProxyJump="ssh@nasp.ob.ac.cn:36022" dictxiong@$1 }
case $(bash "$DOTFILES/tools/common.sh" get_os_type) in
macos ) alias l='ls -lAGh -D "%y-%m-%d %H:%M"' ;;
* ) alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"' ;;
esac
piv-agent()
{
eval $(ssh-agent -k)
# they are: ubuntu, macos, respectively
local SO_PATHS=( "/usr/lib64/opensc-pkcs11.so" "/usr/local/lib/opensc-pkcs11.so" )
for i in ${SO_PATHS[*]}; do
if [[ -f "$i" ]]; then
echo "using: $i"
eval $(ssh-agent -P "$i")
ssh-add -s "$i"
echo "now available keys:"
ssh-add -l
return 0
fi
done
echo "opensc-pkcs11.so not found"
return 1
}
# key bindings
bindkey "^b" beginning-of-line # ctrl+b
bindkey "\eOH" beginning-of-line
bindkey "\e[H" beginning-of-line # home; termius
bindkey "\e[1~" beginning-of-line
bindkey "^e" end-of-line # ctrl+e
bindkey "\eOF" end-of-line
bindkey "\e[F" end-of-line # end; termius
bindkey "\e[4~" end-of-line
bindkey "\ef" forward-word # alt+f
bindkey "\e[5C" forward-word
bindkey "\e\e[C" forward-word # alt+right_arrow; iterm2
bindkey "\e[1;5C" forward-word # alt+right_arrow; termius
bindkey "\eb" backward-word # alt+e
bindkey "\e[5D" backward-word
bindkey "\e\e[D" backward-word # alt+left_arrow; iterm2
bindkey "\e[1;5D" backward-word # alt+left_arrow; termius
bindkey "\ed" delete-char # alt+d
# dfs
dfs()
{
case $1 in
update ) "$DOTFILES/update.sh" ;;
force-update ) (
cd "$DOTFILES"
git fetch --all
ref=$(git symbolic-ref --short HEAD 2> /dev/null) || ref=$(git rev-parse --short HEAD 2> /dev/null) || return 0
for i in $(git for-each-ref refs/heads --format='%(refname)') ; do git checkout ${i#refs/heads/} ; git pull --ff-only ; done
git checkout -c advice.detachedHead=false $ref)
;;
version ) (cd "$DOTFILES" && git rev-parse HEAD) ;;
reset )
antigen reset 1> /dev/null
rm -rf $HOME/.antigen
"$DOTFILES/install.sh" -r
dfs update
"$DOTFILES/install.sh" -i
echo 'Done. Please open a new shell to see the changes.'
;;
cd ) cd "$DOTFILES" ;;
log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;;
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
esac
}
# clean
unset i