2022-11-06 14:00:25 +08:00
|
|
|
# env for shell
|
2022-05-07 16:19:39 +08:00
|
|
|
export TERM="xterm-256color"
|
2022-12-10 19:11:05 +08:00
|
|
|
if (command -v locale >/dev/null) && ( locale -a | grep -qxE "C.UTF-8|C.utf8" ); then
|
2022-12-03 20:37:20 +08:00
|
|
|
export LC_ALL=C.UTF-8
|
|
|
|
export LANG=C.UTF-8
|
|
|
|
else
|
|
|
|
export LC_ALL=en_US.UTF-8
|
|
|
|
export LANG=en_US.UTF-8
|
|
|
|
fi
|
2022-11-05 19:45:21 +08:00
|
|
|
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
|
|
|
export PATH="$PATH:$DOTFILES/scripts"
|
2022-11-06 14:00:25 +08:00
|
|
|
export EDITOR='vim'
|
|
|
|
# env for apps
|
|
|
|
export PYTHONIOENCODING='UTF-8'
|
|
|
|
export GPG_TTY=$(tty)
|
|
|
|
export LESS_TERMCAP_md=$'\E[01;33m'
|
2023-01-06 16:14:41 +08:00
|
|
|
# env for dfs
|
|
|
|
if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi
|
2022-05-07 16:19:39 +08:00
|
|
|
|
|
|
|
# antigen
|
2023-01-06 16:14:41 +08:00
|
|
|
if [[ "$DFS_NO_WALL" == "1" ]]; then
|
2022-11-05 19:45:21 +08:00
|
|
|
ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
|
|
|
|
ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
|
2022-11-24 20:51:35 +08:00
|
|
|
ANTIGEN_PLUGINS=(
|
2023-06-20 15:10:59 +08:00
|
|
|
"https://github.com/zdharma-continuum/fast-syntax-highlighting"
|
2022-11-24 20:51:35 +08:00
|
|
|
"https://github.com/zsh-users/zsh-completions"
|
|
|
|
"https://github.com/zsh-users/zsh-autosuggestions"
|
2022-11-05 19:45:21 +08:00
|
|
|
)
|
2023-01-06 16:14:41 +08:00
|
|
|
else
|
|
|
|
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
|
|
|
|
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
|
|
|
|
ANTIGEN_PLUGINS=(
|
2023-06-20 15:10:59 +08:00
|
|
|
"https://gitee.com/dictxiong/fast-syntax-highlighting"
|
2023-01-06 16:14:41 +08:00
|
|
|
"https://gitee.com/dictxiong/zsh-completions"
|
|
|
|
"https://gitee.com/dictxiong/zsh-autosuggestions"
|
|
|
|
)
|
2022-11-05 19:45:21 +08:00
|
|
|
fi
|
2022-05-07 16:19:39 +08:00
|
|
|
ANTIGEN="$HOME/antigen.zsh"
|
|
|
|
# Install antigen.zsh if not exist
|
|
|
|
if [ ! -f "$ANTIGEN" ]; then
|
2022-08-14 20:34:18 +08:00
|
|
|
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
|
2022-11-05 19:45:21 +08:00
|
|
|
antigen use oh-my-zsh
|
2022-11-24 20:51:35 +08:00
|
|
|
ANTIGEN_PLUGINS+=(
|
|
|
|
"command-not-found"
|
|
|
|
"docker"
|
|
|
|
"extract"
|
|
|
|
"fzf"
|
|
|
|
"git"
|
|
|
|
"ripgrep"
|
|
|
|
"tmux"
|
|
|
|
"ufw"
|
|
|
|
"z"
|
2022-05-22 00:53:55 +08:00
|
|
|
)
|
2022-11-15 01:28:38 +08:00
|
|
|
for i in ${ANTIGEN_PLUGINS[*]}; do
|
2022-05-22 00:53:55 +08:00
|
|
|
if [[ -z $ANTIGEN_EXCLUDE || ! $i =~ $ANTIGEN_EXCLUDE ]]; then
|
|
|
|
antigen bundle $i
|
|
|
|
fi
|
|
|
|
done
|
2022-05-07 16:19:39 +08:00
|
|
|
# select theme
|
2022-10-27 01:16:45 +08:00
|
|
|
TMP_THEME=ys
|
|
|
|
if [[ -e /.dockerenv ]]; then
|
2023-04-21 12:37:05 +08:00
|
|
|
TMP_THEME=robbyrussell
|
2022-10-27 01:16:45 +08:00
|
|
|
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
|
2022-05-14 20:26:25 +08:00
|
|
|
# end of antigen config
|
|
|
|
|
2022-12-03 20:37:20 +08:00
|
|
|
# beacon
|
2023-04-21 12:37:05 +08:00
|
|
|
if [[ -z "$DFS_INITED" && -z "$CI" ]]; then
|
|
|
|
if [[ "$EUID" == "0" ]]; then
|
|
|
|
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.root" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
|
|
|
|
else
|
|
|
|
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.user" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
|
|
|
|
fi
|
2022-12-03 20:37:20 +08:00
|
|
|
fi
|
|
|
|
|
2022-08-26 20:43:00 +08:00
|
|
|
# alias
|
|
|
|
alias "pls"='sudo $(fc -ln -1)'
|
|
|
|
alias "se"='sudo -sE'
|
2023-07-29 03:35:23 +08:00
|
|
|
alias "sl"='sudo zsh -l'
|
2022-08-26 20:43:00 +08:00
|
|
|
alias "pbd"='ping baidu.com'
|
|
|
|
alias "p114"='ping 114.114.114.114'
|
|
|
|
alias "p666"='ping6 2001:da8::666'
|
2023-04-21 12:37:05 +08:00
|
|
|
alias "cbd"='curl http://www.baidu.com'
|
|
|
|
alias "cbds"='curl https://www.baidu.com'
|
2023-01-06 16:14:41 +08:00
|
|
|
alias "gdebug"='git add -A; git commit --allow-empty -m "bug fix ($(date))"'
|
2023-07-29 15:59:53 +08:00
|
|
|
alias "l"='ls -lAGh --time-style="+%y-%m-%d %H:%M"'
|
2022-11-24 20:51:35 +08:00
|
|
|
if [[ -x $(command -v trash) ]]; then
|
|
|
|
alias "rm"="echo use the full path i.e. '/bin/rm'\; consider using trash"
|
|
|
|
fi
|
2022-11-17 20:02:35 +08:00
|
|
|
gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX }
|
2023-04-21 12:37:05 +08:00
|
|
|
sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" }
|
2022-08-25 00:23:29 +08:00
|
|
|
|
2022-08-26 20:43:00 +08:00
|
|
|
# key bindings
|
2022-11-15 01:28:38 +08:00
|
|
|
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
|
2022-08-25 00:23:29 +08:00
|
|
|
|
2023-07-03 16:52:06 +08:00
|
|
|
# mods
|
|
|
|
autoload zcalc
|
|
|
|
|
2022-08-26 20:43:00 +08:00
|
|
|
# dfs
|
2022-05-14 20:26:25 +08:00
|
|
|
dfs()
|
|
|
|
{
|
2022-12-03 20:37:20 +08:00
|
|
|
setopt local_options err_return pipe_fail
|
2022-08-14 20:34:18 +08:00
|
|
|
case $1 in
|
2022-11-24 20:51:35 +08:00
|
|
|
cd ) cd "$DOTFILES" ;;
|
2022-08-14 20:34:18 +08:00
|
|
|
update ) "$DOTFILES/update.sh" ;;
|
2022-11-24 20:51:35 +08:00
|
|
|
version ) (cd "$DOTFILES" && git rev-parse HEAD) ;;
|
|
|
|
vversion ) (cd "$DOTFILES" && git show) ;;
|
|
|
|
config )
|
|
|
|
mkdir -p ~/.config/dotfiles
|
|
|
|
$EDITOR ~/.config/dotfiles/env
|
|
|
|
;;
|
2022-08-14 20:34:18 +08:00
|
|
|
force-update ) (
|
2023-01-06 16:14:41 +08:00
|
|
|
cd "$DOTFILES"
|
2022-08-14 20:34:18 +08:00
|
|
|
git fetch --all
|
|
|
|
ref=$(git symbolic-ref --short HEAD 2> /dev/null) || ref=$(git rev-parse --short HEAD 2> /dev/null) || return 0
|
2022-11-15 01:28:38 +08:00
|
|
|
for i in $(git for-each-ref refs/heads --format='%(refname)') ; do git checkout ${i#refs/heads/} ; git pull --ff-only ; done
|
2022-08-14 20:34:18 +08:00
|
|
|
git checkout -c advice.detachedHead=false $ref)
|
|
|
|
;;
|
|
|
|
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.'
|
|
|
|
;;
|
2022-08-26 20:43:00 +08:00
|
|
|
log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;;
|
2023-04-21 12:37:05 +08:00
|
|
|
beacon ) "$DOTFILES/tools/common.sh" "post_beacon" "$2" "$3" ;;
|
2022-08-14 20:34:18 +08:00
|
|
|
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
|
|
|
|
esac
|
2022-05-14 20:26:25 +08:00
|
|
|
}
|
2022-11-15 01:28:38 +08:00
|
|
|
|
|
|
|
# clean
|
|
|
|
unset i
|
2023-04-21 12:37:05 +08:00
|
|
|
export DFS_INITED=1
|