123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- ####################################################
- # Customized configuration for ZSH based on prezto #
- ####################################################
- #
- # Exit if asked
- #
- if [[ "${DISABLE_DOTFILES_SYS}" = 1 ]]; then
- return
- fi
- #
- # HOMEDIR
- #
- export HOMEDIR="$(getent passwd "${USER}" | cut -d: -f6)"
- #
- # TMPDIR
- #
- export TMPDIR="${HOMEDIR}/tmp"
- if [[ ! -d "${TMPDIR}" ]]; then
- mkdir -p "${TMPDIR}"
- fi
- #
- # XDG (https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)
- #
- export XDG_CONFIG_HOME="${HOME}/.config"
- if [[ ! -d "${XDG_CONFIG_HOME}" ]]; then
- mkdir -p "${XDG_CONFIG_HOME}"
- fi
- export XDG_DATA_HOME="${HOME}/.local/share"
- if [[ ! -d "${XDG_DATA_HOME}" ]]; then
- mkdir -p "${XDG_DATA_HOME}"
- fi
- export XDG_CACHE_HOME="${HOME}/.cache"
- if [[ ! -d "${XDG_CACHE_HOME}" ]]; then
- mkdir -p "${XDG_CACHE_HOME}"
- fi
- export XDG_RUNTIME_DIR="${TMPDIR}"
- #
- # Using zpresto
- #
- export ZDOTDIR="$(dirname "$(readlink -f "${0}")")"
- if [[ -f "${ZDOTDIR}/prezto/init.zsh" ]]; then
- source "${ZDOTDIR}/prezto/init.zsh"
- zstyle ':completion::complete:*' cache-path "${TMPDIR}/.zcompcache"
- # Remove first '\n' in PS1
- export PS1="$(echo "${PS1}" | sed ':a;N;$!ba;s/\n//')"
- # Add jobs count at the end of the first line
- export PS1="$(echo "${PS1}" | sed ':a;N;$!ba;s/\n/%1(j. with %F{161}%j%f job(s).)\n/')"
- fi
- #
- # Load some colors
- #
- autoload colors zsh/terminfo
- if [[ "${terminfo[colors]}" -ge 8 ]]; then
- colors
- fi
- for color in RED GREEN YELLOW BLUE MAGENTA CYAN ORANGE WHITE; do
- eval COLOR_$color='$terminfo[bold]$fg[${(L)color}]'
- eval COLOR_LIGHT_$color='$fg[${(L)color}]'
- done
- COLOR_RESET="$terminfo[sgr0]"
- #
- # Pager
- #
- if (( $+commands[batcat] )); then
- export PAGER=batcat
- alias less="${PAGER}"
- alias more="${PAGER}"
- elif (( $+commands[vim] )) && [[ -f "${VIMPAGER}" ]]; then
- VIMPAGER="$(readlink -f "${ZDOTDIR}/../tools/vimpager/vimpager")"
- export PAGER="${VIMPAGER}"
- alias less="${PAGER}"
- alias more="${PAGER}"
- export VIMPAGER_RC="$(readlink -f "${ZDOTDIR}/../tools/vim/vimpagerrc")"
- if [[ ! -f "${VIMPAGER_RC}" ]]; then
- unset VIMPAGER_RC
- fi
- unset VIMPAGER
- elif (( $+commands[less] )); then
- export PAGER=less
- alias more="${PAGER}"
- elif (( $+commands[more] )); then
- export PAGER=more
- fi
- #
- # Vim
- #
- if (( $+commands[vim] )); then
- VIMRC="$(readlink -f "${ZDOTDIR}/../tools/vim/vimrc")"
- if [[ -f "${VIMRC}" ]]; then
- export VIMINIT="source ${VIMRC}"
- fi
- unset VIMRC
- export EDITOR="vim"
- alias v='vim'
- fi
- #
- # Git
- #
- if (( $+commands[delta] )); then
- export GIT_PAGER=delta
- fi
- GIT_OPTIONS=()
- if [[ -n "${LC_SSH_FULLNAME}" ]]; then
- GIT_OPTIONS+=(-c "user.name=${LC_SSH_FULLNAME}")
- export GIT_AUTHOR_NAME="${LC_SSH_FULLNAME}"
- export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}"
- fi
- if [[ -n "${LC_SSH_EMAIL}" ]]; then
- GIT_OPTIONS+=(-c "user.email=${LC_SSH_EMAIL}")
- export GIT_AUTHOR_EMAIL="${LC_SSH_EMAIL}"
- export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}"
- fi
- export GIT_OPTIONS
- git() {
- (
- export PAGER=less
- export GIT_FAKE_HOME="$(readlink -f "${ZDOTDIR}/../tools/git")"
- if [[ -f "${GIT_FAKE_HOME}/.gitconfig" ]]; then
- export HOME="${GIT_FAKE_HOME}"
- fi
- export LC_MESSAGES='en_US.UTF-8'
- =git ${GIT_OPTIONS} $@
- )
- }
- alias g='git'
- if (( $+commands[lazygit] )); then
- alias lg='lazygit'
- fi
- #
- # Tmux
- #
- TMUX_OPTS="-2"
- TMUX_CONF="$(readlink -f "${ZDOTDIR}/../tools/tmux/tmux.conf")"
- if [[ -f "${TMUX_CONF}" ]]; then
- TMUX_OPTS="${TMUX_OPTS} -f ${TMUX_CONF}"
- fi
- alias tmux="TMPDIR= tmux ${TMUX_OPTS}"
- unset TMUX_OPTS TMUX_CONF
- #
- # Common aliases / functions
- #
- alias ls='ls -h --color=auto'
- alias l='ls -lh --color=auto'
- alias rm='rm -i'
- alias mv='mv -i'
- alias cp='cp -i'
- alias mgrep="grep --color=auto -rnisH"
- alias rsu="sudo -E zsh"
- alias reloadsh="exec zsh"
- alias md="mkdir -p"
- mcd() { mkdir -p "$@" && cd "$@" }
- alias aug='sudo apt-get update && sudo apt-get upgrade'
- if (( $+commands[ccze] )) ; then
- alias alog='tail -n 300 -F /var/log/auth.log | ccze'
- alias mlog='tail -n 300 -F /var/log/mail.log | ccze'
- alias slog='tail -n 300 -F /var/log/syslog | ccze'
- else
- alias alog='tail -n 300 -F /var/log/auth.log'
- alias mlog='tail -n 300 -F /var/log/mail.log'
- alias slog='tail -n 300 -F /var/log/syslog'
- fi
- alias sscp_nosec='scp -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
- alias ssh_nosec='ssh -o '\''StrictHostKeyChecking=no'\'' -o '\''UserKnownHostsFile=/dev/null'\'
- #
- # History options
- #
- setopt extendedhistory # add a timestamp and the duration of each command
- setopt sharehistory # _all_ zsh sessions share the same history files
- setopt histignorealldups # ignores duplications
- export HISTSIZE=1000000
- export SAVEHIST=1000000
- export HISTFILE="${TMPDIR}/.zhistory"
- #
- # Zsh options
- #
- export LISTPROMPT # in order to scroll if completion list is too big
- setopt clobber # Allows > redirection to truncate existing files, and >> to create files
- setopt checkjobs # Report the status of background and suspended jobs before exiting a shell
- setopt auto_cd # a command like % /usr/local is equivalent to cd /usr/local
- setopt nohup # don't send HUP signal when closing term session
- setopt extended_glob # in order to use #, ~ and ^ for filename generation
- setopt always_to_end # move to cursor to the end after completion
- setopt notify # report the status of backgrounds jobs immediately
- setopt correct # try to correct the spelling if possible
- setopt noflowcontrol # disable xon/xoff
- setopt histnostore # don't store history command in history
- setopt nobanghist # don't care of '!' in commands
- setopt emacs # zle in emacs mode
- setopt pushdignoredups # ignore dups in pushd stack
- setopt auto_continue # send SIGCONT to jobs disowned
- setopt auto_list # list choice on ambiguous command
- setopt auto_pushd # cd = pushd
- setopt pushd_ignore_dups # ignore dups in pushd
- setopt pushd_silent # don't print stack after push/pop
- setopt bang_hist # yeah ! expansion (use bash !$ for example)
- setopt chase_links # cd to a symlink is in fact cd to the true dir
- setopt ksh_option_print # modify setopt output
- setopt long_list_jobs # list jobs in long format
- setopt no_rm_star_wait # dont't idle 10 seconds
- #
- # Zle config
- #
- # autoescape specials chars with urls
- autoload -U url-quote-magic
- zle -N self-insert url-quote-magic
- # insert sudo at beggining of current command
- insert-sudo-prefix () {
- local prefix
- prefix='sudo'
- if [ "${BUFFER:0:${#prefix}}" != "$prefix" ]; then
- BUFFER="$prefix $BUFFER"
- CURSOR=$(($CURSOR + $#prefix + 1))
- fi
- }
- zle -N insert-sudo-prefix
- bindkey "^b" insert-sudo-prefix
- # make home and end keys work with tmux
- bindkey "^[[H" beginning-of-line
- bindkey "^[[F" end-of-line
- #
- # MOTD
- #
- if [[ "${LC_SSH_VARS}" = 1 ]]; then
- if [[ -z "${TMUX}" ]] && [[ -z "${SUDO_UID}" ]]; then
- if [[ -z "${LC_SSH_EMAIL}" || -z "${LC_SSH_FULLNAME}" ]]; then
- printf "\n${COLOR_RED}You environment seems to not be properly configured: LC_SSH_EMAIL and LC_SSH_FULLNAME have to be set and forwarded through the ssh connection.${COLOR_RESET}\n"
- else
- printf "\n${COLOR_LIGHT_GREEN}You are logged in as ${COLOR_YELLOW}${LC_SSH_FULLNAME}${COLOR_RESET} <${COLOR_YELLOW}${LC_SSH_EMAIL}${COLOR_RESET}>\n"
- fi
- if [[ ! -e "${SSH_AUTH_SOCK}" ]]; then
- printf "${COLOR_LIGHT_YELLOW}Be warned that your ssh agent is not forwarded${COLOR_RESET}\n"
- fi
- fi
- fi
- #
- # NVM
- #
- export NVM_DIR="/usr/local/nvm"
- if [ -s "$NVM_DIR/nvm.sh" ]; then
- . "$NVM_DIR/nvm.sh"
- fi
- #
- # Node JS related tools
- #
- export NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/config"
- export NPM_CONFIG_CACHE="${XDG_CACHE_HOME}/npm"
- export NPM_CONFIG_TMP="${XDG_RUNTIME_DIR}/npm"
- # yarn is not yet able to use XDG-* directories, workaround:
- alias yarn="HOME=${TMPDIR} yarn"
- #
- # Additional entries in PATH
- #
- export PATH="${HOMEDIR}/.local/bin:${PATH}"
- # Sourcing ~/.zshrc
- ZSHRC="${HOMEDIR}/.zshrc"
- if [ -f "${ZSHRC}" ]; then
- . "${ZSHRC}"
- fi
- # Cleanup
- unset ZSHRC
- unset HOMEDIR
|