dotfiles

My dotfiles for Arch Linux
git clone git://git.janispagel.de/dotfiles.git
Log | Files | Refs | README

dot-zshrc (8438B)


      1 #################
      2 ### Functions ###
      3 #################
      4 
      5 # Source functions
      6 if [ -f $ZDOTDIR/.zsh_functions ]; then
      7   source $ZDOTDIR/.zsh_functions
      8 fi
      9 
     10 ########################
     11 #### Key bindings ######
     12 ########################
     13 
     14 bindkey '^[[P' delete-char # Delete
     15 bindkey '^[[5~' up-line-or-history # PageUp
     16 bindkey '^[[6~' down-line-or-history # PageDown
     17 
     18 ########################
     19 #### Autocomplete ######
     20 ########################
     21 
     22 # Perform some sanity checks on completion option
     23 autoload -Uz compinit
     24 compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION
     25 
     26 bindkey '^i' expand-or-complete-prefix # Complete inside of string
     27 zstyle ':completion:*' completer _complete _match _approximate # Enable fuzzy matching
     28 zstyle ':completion:*:match:*' original only
     29 zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )' # Tolerance of approximate increases by amount of characters typed so far
     30 zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes # Avoid getting the same file offered again with certain programs
     31 zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
     32 zstyle ':completion:*:descriptions' format "- %d -"
     33 zstyle ':completion:*:corrections' format "- %d - (errors %e})"
     34 zstyle ':completion:*:default' list-prompt '%S%M matches%s'
     35 zstyle ':completion:*' group-name ''
     36 zstyle ':completion:*:manuals' separate-sections true
     37 zstyle ':completion:*:manuals.(^1*)' insert-sections true
     38 zstyle ':completion:*:ssh:*' hosts off # Do not use /etc/hosts in ssh autocompletion
     39 zstyle ':completion:*:scp:*' hosts off # Do not use /etc/hosts in scp autocompletion
     40 zstyle ':completion:*' menu select
     41 zstyle ':completion:*' verbose yes
     42 zstyle ':completion:*' rehash true
     43 # Speed up completion by setting cache
     44 zstyle ':completion:*' use-cache on
     45 zstyle ':completion:*' cache-path $XDG_CACHE_HOME/zsh
     46 
     47 #######################
     48 ### Options ###########
     49 #######################
     50 
     51 setopt CORRECT # Make suggestions for correcting spelling mistakes
     52 setopt EXTENDED_GLOB # Inlude ~ in globbing
     53 setopt CASE_GLOB # Case sensitive globbing
     54 setopt GLOB_COMPLETE # Use pattern matching for wildcards and ~
     55 setopt NUMERIC_GLOB_SORT # Sort numerically if numbers are present in globbing
     56 setopt RC_EXPAND_PARAM # Expand globbing arrays to full names
     57 setopt NO_BEEP # Disable system beeps
     58 setopt MARK_DIRS # Always append trailing / to dirs
     59 setopt APPEND_HISTORY # Append to history file instead of overwriting
     60 setopt HIST_IGNORE_ALL_DUPS # Ignore all history dups
     61 setopt AUTO_CD # No need to type 'cd' if standard input is a valid path
     62 setopt PROMPT_SUBST # Enable command substitution in prompt
     63 
     64 ##########################
     65 ######## Basics ##########
     66 ##########################
     67 
     68 # Set history options
     69 HISTFILE="$XDG_DATA_HOME"/zsh/history
     70 HISTSIZE=1000000
     71 SAVEHIST=1000000
     72 
     73 # Source aliases
     74 if [ -f $ZDOTDIR/.zsh_aliases ]; then
     75     source $ZDOTDIR/.zsh_aliases
     76 fi
     77 
     78 # Use fish-like history substring search
     79 if [ -f /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh ]; then
     80     source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
     81     # bind UP and DOWN arrow keys to history substring search
     82     zmodload zsh/terminfo
     83     bindkey "$terminfo[kcuu1]" history-substring-search-up
     84     bindkey "$terminfo[kcud1]" history-substring-search-down
     85     bindkey '^[[A' history-substring-search-up
     86     bindkey '^[[B' history-substring-search-down
     87 fi
     88 # Use fish-like autosuggestion
     89 if [ -f /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then
     90 	source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
     91 	ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
     92 	ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=2'
     93 fi
     94 # Use fish-like syntax highlighting
     95 #if [ -f /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
     96 #	source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
     97 #fi
     98 # fzf commands (command history, changing directory, finding files
     99 if [ -f /usr/share/fzf/key-bindings.zsh ]; then
    100 	source /usr/share/fzf/key-bindings.zsh
    101 	fzf-file-widget-fd() {
    102 	  FZF_CTRL_T_COMMAND='fd --hidden --follow --exclude ".git" --exclude ".venv" --search-path . --search-path ~'
    103 	  fzf-file-widget
    104 	  unset FZF_CTRL_T_COMMAND
    105         }
    106 	fzf-cd-widget-fd() {
    107 	  FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude ".git" --exclude ".venv" --search-path . --search-path ~'
    108 	  fzf-cd-widget
    109 	  unset FZF_ALT_C_COMMAND
    110         }
    111 	# Bind fzf-fd functions
    112 	zle     -N   fzf-file-widget-fd
    113 	bindkey '^F' fzf-file-widget-fd
    114         zle     -N   fzf-cd-widget-fd
    115 	bindkey '\ec' fzf-cd-widget-fd
    116 fi
    117 
    118 ######################
    119 ####### Prompt #######
    120 ######################
    121 
    122 # set left prompt
    123 PROMPT='%(!.#.$>) %E'
    124 
    125 ######
    126 # This whole git prompt stuff was taken from Manjaro's zsh setup, slightly modified
    127 ######
    128 
    129 # Modify the colors and symbols in these variables as desired.
    130 GIT_PROMPT_SYMBOL=""                                            # clean repo
    131 GIT_PROMPT_PREFIX="["
    132 GIT_PROMPT_SUFFIX="]"
    133 GIT_PROMPT_AHEAD="ANUM"                                         # A"NUM" - ahead by "NUM" commits
    134 GIT_PROMPT_BEHIND="BNUM"                                        # B"NUM" - behind by "NUM" commits
    135 GIT_PROMPT_MERGING="%F{1}!%f"                                   # merge conflict
    136 GIT_PROMPT_UNTRACKED="%F{1}++%f"                                # untracked files
    137 GIT_PROMPT_MODIFIED="%F{3}+%f"                                  # tracked files modified
    138 GIT_PROMPT_STAGED="%F{2}->%f"                                   # staged changes present = ready for "git push"
    139 
    140 # Right prompt with exit status of previous command if not successful
    141 # Also show background process, git information and current dir
    142 RPROMPT='$(bg_process) $(git_prompt_string) %(?..[%?]) [%1~/]'
    143 
    144 #################
    145 ##### Misc ######
    146 #################
    147 
    148 # TMUX
    149 if [[ -z $TMUXAUTOATTACH ]]; then # Prevent from running if variable is set
    150     if [[ -z "$TMUX" ]] && [[ -n "$DISPLAY" ]]; then # Test if tmux is running
    151         ID="$( tmux ls | grep -vm1 attached | cut -d: -f1 )" # get the id of a deattached session
    152         if [[ -z "$ID" ]]; then # if not available create a new one
    153             tmux new-session
    154         else
    155             tmux attach-session -t "$ID" # if available attach to it
    156         fi
    157     fi
    158 fi
    159 if [ -n "$TMUX" ]; then # If tmux is running
    160     # create a global per-pane variable that holds the pane's PWD
    161     export PS1=$PS1'$( [ -n $TMUX ] && tmux setenv -g TMUX_PWD_$(tmux display -p "#D" | tr -d %) $PWD)'
    162 fi
    163 
    164 # Color man pages
    165 export LESS_TERMCAP_mb=$'\E[01;32m'
    166 export LESS_TERMCAP_md=$'\E[01;32m'
    167 export LESS_TERMCAP_me=$'\E[0m'
    168 export LESS_TERMCAP_se=$'\E[0m'
    169 export LESS_TERMCAP_so=$'\E[01;47;34m'
    170 export LESS_TERMCAP_ue=$'\E[0m'
    171 export LESS_TERMCAP_us=$'\E[01;36m'
    172 export LESS=-r
    173 
    174 # Load DIRCOLORS
    175 test -r "$XDG_DATA_HOME/dir_colors" && eval $(dircolors $XDG_DATA_HOME/dir_colors)
    176 
    177 # Add support for GnuPG
    178 export GPG_TTY=$(tty)
    179 
    180 # Disable graphical interface for SSH password
    181 unset SSH_ASKPASS
    182 
    183 # Customize tty
    184 if [ "$TERM" = "linux" ]; then
    185 	printf '\033]P03b4252'; # black
    186 	printf '\033]P1bf616a'; # red
    187 	printf '\033]P2a3be8c'; # green
    188 	printf '\033]P3ebcb8b'; # yellow
    189 	printf '\033]P481a1c1'; # blue
    190 	printf '\033]P5b48ead'; # magenta
    191 	printf '\033]P688c0d0'; # cyan
    192 	printf '\033]P7e5e9f0'; # white
    193 	printf '\033]P84c566a'; # bright black
    194 	printf '\033]P9bf616a'; # bright red
    195 	printf '\033]PAa3be8c'; # bright green
    196 	printf '\033]PBebcb8b'; # bright yellow
    197 	printf '\033]PC81a1c1'; # bright blue
    198 	printf '\033]PDb48ead'; # bright magenta
    199 	printf '\033]PE8fbcbb'; # bright cyan
    200 	printf '\003]PFeceff4'; # bright white
    201 	clear;
    202 	if [ -f "/usr/share/kbd/consolefonts/ter-v24n.psf.gz" ]; then
    203 		setfont ter-v24n
    204 	fi
    205 fi
    206 
    207 # added by travis gem
    208 [ -f /home/janis/.travis/travis.sh ] && source /home/janis/.travis/travis.sh
    209 
    210 # >>> conda initialize >>>
    211 # !! Contents within this block are managed by 'conda init' !!
    212 __conda_setup="$('/home/janis/.local/build/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
    213 if [ $? -eq 0 ]; then
    214     eval "$__conda_setup"
    215 else
    216     if [ -f "/home/janis/.local/build/anaconda3/etc/profile.d/conda.sh" ]; then
    217         . "/home/janis/.local/build/anaconda3/etc/profile.d/conda.sh"
    218     else
    219         export PATH="/home/janis/.local/build/anaconda3/bin:$PATH"
    220     fi
    221 fi
    222 unset __conda_setup
    223 # <<< conda initialize <<<
    224 
    225 # Start X in tty2
    226 if [[ "$(tty)" = "/dev/tty2" ]]; then
    227 	pgrep dwm || startx
    228 fi