revamp .zshrc a bit.
This commit is contained in:
		
							parent
							
								
									73aa17f319
								
							
						
					
					
						commit
						98fa42926b
					
				
					 1 changed files with 149 additions and 131 deletions
				
			
		
							
								
								
									
										280
									
								
								zsh/.zshrc
									
										
									
									
									
								
							
							
						
						
									
										280
									
								
								zsh/.zshrc
									
										
									
									
									
								
							| 
						 | 
					@ -13,25 +13,23 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#set important shell variables
 | 
					#set important shell variables
 | 
				
			||||||
    #set default editor and pager.
 | 
					#set default editor and pager.
 | 
				
			||||||
    export EDITOR=nvim
 | 
					export EDITOR=nvim
 | 
				
			||||||
    export VISUAL=nvim
 | 
					export VISUAL=nvim
 | 
				
			||||||
    export PAGER=less
 | 
					export PAGER=less
 | 
				
			||||||
    #default options for less
 | 
					#default options for less
 | 
				
			||||||
    export LESS="-R"
 | 
					export LESS="-R"
 | 
				
			||||||
    export LESSHISTFILE="/dev/null"
 | 
					export LESSHISTFILE="/dev/null"
 | 
				
			||||||
    #set the w3m homepage
 | 
					#set ssh-agent to play nice with systemd.
 | 
				
			||||||
    export WWW_HOME="duckduckgo.com/lite/"
 | 
					export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
 | 
				
			||||||
    #set ssh-agent to play nice with systemd.
 | 
					export TIMEFMT="%J  %*U user %*S system %P cpu %*E total"
 | 
				
			||||||
    export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
 | 
					export PIPENV_VENV_IN_PROJECT=true
 | 
				
			||||||
    export TIMEFMT="%J  %*U user %*S system %P cpu %*E total"
 | 
					export POETRY_VIRTUALENVS_IN_PROJECT=true
 | 
				
			||||||
    export PIPENV_VENV_IN_PROJECT=true
 | 
					#turns out its ok to have nonexistent paths in $PATH
 | 
				
			||||||
    export POETRY_VIRTUALENVS_IN_PROJECT=true
 | 
					export PATH="$PATH:$HOME/.local/bin/"
 | 
				
			||||||
    #turns out its ok to have nonexistent paths in $PATH
 | 
					export PATH="$PATH:/opt"
 | 
				
			||||||
    export PATH="$PATH:$HOME/.local/bin/"
 | 
					export PATH="$PATH:$HOME/.cargo/bin"
 | 
				
			||||||
    export PATH="$PATH:/opt"
 | 
					export PATH="$PATH:$HOME/.nix-profile/bin"
 | 
				
			||||||
    export PATH="$PATH:$HOME/.cargo/bin"
 | 
					 | 
				
			||||||
    export PATH="$PATH:$HOME/.nix-profile/bin"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#prompt
 | 
					#prompt
 | 
				
			||||||
setprompt() {
 | 
					setprompt() {
 | 
				
			||||||
| 
						 | 
					@ -45,7 +43,7 @@ setprompt() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setopt prompt_subst
 | 
					        setopt prompt_subst
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        precmd_vcs() {vcs_info}
 | 
					        precmd_vcs() { vcs_info; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #when not in a repo, show full path to current directory. when in one, show path from base direcory of the repo.
 | 
					        #when not in a repo, show full path to current directory. when in one, show path from base direcory of the repo.
 | 
				
			||||||
        zstyle ':vcs_info:*' nvcsformats '%~'
 | 
					        zstyle ':vcs_info:*' nvcsformats '%~'
 | 
				
			||||||
| 
						 | 
					@ -53,9 +51,7 @@ setprompt() {
 | 
				
			||||||
        zstyle ':vcs_info:*' actionformats '%r/%S %F{green}[%b] %F{red}<%a>%f'
 | 
					        zstyle ':vcs_info:*' actionformats '%r/%S %F{green}[%b] %F{red}<%a>%f'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #the precmd function, called just before printing the prompt. 
 | 
					    #the precmd function, called just before printing the prompt. 
 | 
				
			||||||
    function precmd() {
 | 
					    function precmd() { precmd_vcs; }
 | 
				
			||||||
        precmd_vcs
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #Make the right prompt blank, just to be sure.
 | 
					    #Make the right prompt blank, just to be sure.
 | 
				
			||||||
    RPROMPT=''
 | 
					    RPROMPT=''
 | 
				
			||||||
| 
						 | 
					@ -64,135 +60,157 @@ setprompt() {
 | 
				
			||||||
    PROMPT=$'%F{cyan}[%n@%m]%f%F{red}├────┤%f${vcs_info_msg_0_} %F{white}[%D %T]%f\n»'
 | 
					    PROMPT=$'%F{cyan}[%n@%m]%f%F{red}├────┤%f${vcs_info_msg_0_} %F{white}[%D %T]%f\n»'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#starship if its installed, otherwise the prompt we just defined.
 | 
					#starship if its installed, otherwise the prompt we just defined.
 | 
				
			||||||
    command -v starship &> /dev/null && eval "$(starship init zsh)" || setprompt
 | 
					command -v starship &> /dev/null && eval "$(starship init zsh)" || setprompt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#show dots while waiting for tab-completion
 | 
					#show dots while waiting for tab-completion
 | 
				
			||||||
    expand-or-complete-with-dots() {
 | 
					expand-or-complete-with-dots() {
 | 
				
			||||||
        # toggle line-wrapping off and back on again
 | 
					    # toggle line-wrapping off and back on again
 | 
				
			||||||
        [[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti rmam
 | 
					    [[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti rmam
 | 
				
			||||||
        print -Pn "%{%F{red}......%f%}"
 | 
					    print -Pn "%{%F{red}......%f%}"
 | 
				
			||||||
        [[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti smam
 | 
					    [[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti smam
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        zle expand-or-complete
 | 
					    zle expand-or-complete
 | 
				
			||||||
        zle redisplay
 | 
					    zle redisplay
 | 
				
			||||||
    }
 | 
					}
 | 
				
			||||||
    zle -N expand-or-complete-with-dots
 | 
					zle -N expand-or-complete-with-dots
 | 
				
			||||||
    bindkey "^I" expand-or-complete-with-dots
 | 
					bindkey "^I" expand-or-complete-with-dots
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# editing stuff
 | 
					# editing stuff
 | 
				
			||||||
    # Enable the ZLE line editor, which is default behavior, but to be sure
 | 
					# Enable the ZLE line editor, which is default behavior, but to be sure
 | 
				
			||||||
    setopt ZLE
 | 
					setopt ZLE
 | 
				
			||||||
    #Enable vi mode for the ZLE. it should be set by default due to our EDITOR and VISUAL, but this is just to be safe.
 | 
					#Enable vi mode for the ZLE. it should be set by default due to our EDITOR and VISUAL, but this is just to be safe.
 | 
				
			||||||
    bindkey -v
 | 
					bindkey -v
 | 
				
			||||||
    #allow backspacing beyond the point you entered insert mode:
 | 
					#allow backspacing beyond the point you entered insert mode:
 | 
				
			||||||
    bindkey -v '^?' backward-delete-char
 | 
					bindkey -v '^?' backward-delete-char
 | 
				
			||||||
    bindkey "^W" backward-kill-word 
 | 
					bindkey "^W" backward-kill-word 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#misc
 | 
					#misc
 | 
				
			||||||
    # Sends cd commands without the need for 'cd'
 | 
					# Sends cd commands without the need for 'cd'
 | 
				
			||||||
    setopt AUTO_CD
 | 
					setopt AUTO_CD
 | 
				
			||||||
    # Kill all child processes when we exit, dont leave them running
 | 
					# Turn off terminal beep on autocomplete.
 | 
				
			||||||
    unsetopt NO_HUP
 | 
					unsetopt BEEP
 | 
				
			||||||
    #Allows comments in interactive shell.
 | 
					# Kill all child processes when we exit, dont leave them running
 | 
				
			||||||
    setopt INTERACTIVE_COMMENTS
 | 
					unsetopt NO_HUP
 | 
				
			||||||
    # Ctrl+S and Ctrl+Q usually disable/enable tty input. This disables those inputs
 | 
					#Allows comments in interactive shell.
 | 
				
			||||||
    unsetopt FLOW_CONTROL
 | 
					setopt INTERACTIVE_COMMENTS
 | 
				
			||||||
    mkdir -p ~/.cache/zsh
 | 
					# Ctrl+S and Ctrl+Q usually disable/enable tty input. This disables those inputs
 | 
				
			||||||
    local zshCache=~/.cache/zsh
 | 
					unsetopt FLOW_CONTROL
 | 
				
			||||||
 | 
					mkdir -p ~/.cache/zsh
 | 
				
			||||||
 | 
					local zshCache=~/.cache/zsh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ZSH history
 | 
					#ZSH history
 | 
				
			||||||
    #make a history file outside our home directory
 | 
					#make a history file outside our home directory
 | 
				
			||||||
    HISTFILE=$zshCache/history
 | 
					HISTFILE=$zshCache/history
 | 
				
			||||||
    #save a lot of history
 | 
					#save a lot of history
 | 
				
			||||||
    SAVEHIST=1000
 | 
					SAVEHIST=1000
 | 
				
			||||||
    HISTSIZE=1000
 | 
					HISTSIZE=1000
 | 
				
			||||||
    #save more information in history
 | 
					#save more information in history
 | 
				
			||||||
    setopt EXTENDED_HISTORY
 | 
					setopt EXTENDED_HISTORY
 | 
				
			||||||
    #share history among zsh sessions
 | 
					#share history among zsh sessions
 | 
				
			||||||
    setopt APPEND_HISTORY
 | 
					setopt APPEND_HISTORY
 | 
				
			||||||
    setopt SHARE_HISTORY
 | 
					setopt SHARE_HISTORY
 | 
				
			||||||
    #skip dupes when going through history
 | 
					#skip dupes when going through history
 | 
				
			||||||
    setopt HIST_FIND_NO_DUPS
 | 
					setopt HIST_FIND_NO_DUPS
 | 
				
			||||||
    #delete dupes first when histsize becomes full
 | 
					#delete dupes first when histsize becomes full
 | 
				
			||||||
    setopt HIST_EXPIRE_DUPS_FIRST
 | 
					setopt HIST_EXPIRE_DUPS_FIRST
 | 
				
			||||||
    #dont write dupes of the last command to histfile
 | 
					#dont write dupes of the last command to histfile
 | 
				
			||||||
    setopt HIST_IGNORE_DUPS
 | 
					setopt HIST_IGNORE_DUPS
 | 
				
			||||||
    #write history file as we type
 | 
					#write history file as we type
 | 
				
			||||||
    setopt INC_APPEND_HISTORY
 | 
					setopt INC_APPEND_HISTORY
 | 
				
			||||||
    #remove extra whitespace from history
 | 
					#remove extra whitespace from history
 | 
				
			||||||
    setopt HIST_REDUCE_BLANKS
 | 
					setopt HIST_REDUCE_BLANKS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#autocomplete
 | 
					#autocomplete
 | 
				
			||||||
    autoload -Uz compinit
 | 
					autoload -Uz compinit
 | 
				
			||||||
    compinit
 | 
					compinit
 | 
				
			||||||
    #have the menu highlight while we cycle through options
 | 
					#have the menu highlight while we cycle through options
 | 
				
			||||||
    zstyle ':completion:*' menu select
 | 
					zstyle ':completion:*' menu select
 | 
				
			||||||
    #case insensitive completion
 | 
					#case insensitive completion
 | 
				
			||||||
    zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
 | 
					zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
 | 
				
			||||||
    #allow completion from midword
 | 
					#allow completion from midword
 | 
				
			||||||
    setopt COMPLETE_IN_WORD
 | 
					setopt COMPLETE_IN_WORD
 | 
				
			||||||
    #move cursor to end of word after completing
 | 
					#move cursor to end of word after completing
 | 
				
			||||||
    setopt ALWAYS_TO_END
 | 
					setopt ALWAYS_TO_END
 | 
				
			||||||
    #complete aliases as well
 | 
					#complete aliases as well
 | 
				
			||||||
    setopt COMPLETE_ALIASES
 | 
					setopt COMPLETE_ALIASES
 | 
				
			||||||
    #select first item when you press tab the first time.
 | 
					#select first item when you press tab the first time.
 | 
				
			||||||
    setopt MENU_COMPLETE
 | 
					setopt MENU_COMPLETE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#globbing
 | 
					#globbing
 | 
				
			||||||
    #case insensitive globbing
 | 
					#case insensitive globbing
 | 
				
			||||||
    setopt NO_CASE_GLOB
 | 
					setopt NO_CASE_GLOB
 | 
				
			||||||
    #sort globs that expand to numbers by number rather than alphabeticly
 | 
					#sort globs that expand to numbers by number rather than alphabeticly
 | 
				
			||||||
    setopt NUMERIC_GLOB_SORT
 | 
					setopt NUMERIC_GLOB_SORT
 | 
				
			||||||
    #allows for some neat globbing.
 | 
					#allows for some neat globbing.
 | 
				
			||||||
    setopt EXTENDED_GLOB
 | 
					setopt EXTENDED_GLOB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#aliases
 | 
					#aliases
 | 
				
			||||||
    alias vim="nvim"
 | 
					alias vim="nvim"
 | 
				
			||||||
    alias vimdiff="nvim -d"
 | 
					alias vimdiff="nvim -d"
 | 
				
			||||||
    alias please='sudo $(fc -ln -1)'
 | 
					alias please='sudo $(fc -ln -1)'
 | 
				
			||||||
    alias la='ls -lha'
 | 
					alias la='ls -lha'
 | 
				
			||||||
    alias ll='ls -lh'
 | 
					alias ll='ls -lh'
 | 
				
			||||||
    alias say='espeak -p 10 -s 150 -a 200 2> /dev/null'
 | 
					alias say='espeak -p 10 -s 150 -a 200 2> /dev/null'
 | 
				
			||||||
    alias tmux='tmux -u'
 | 
					alias tmux='tmux -u'
 | 
				
			||||||
    alias pdfmk='latexmk -lualatex -pvc'
 | 
					alias pdfmk='latexmk -lualatex -pvc'
 | 
				
			||||||
    # needs to have a number immediately after it.
 | 
					# needs to have a number immediately after it.
 | 
				
			||||||
    alias slideshow='feh --full-screen --randomize --auto-zoom --recursive --slideshow-delay'
 | 
					alias slideshow='feh --full-screen --randomize --auto-zoom --recursive --slideshow-delay'
 | 
				
			||||||
    # converts all .doc and .docx files in the local directory to pdfs using libreoffice
 | 
					# converts all .doc and .docx files in the local directory to pdfs using libreoffice
 | 
				
			||||||
    alias doc2pdf='loffice --convert-to pdf --headless *.docx'
 | 
					alias doc2pdf='loffice --convert-to pdf --headless *.docx'
 | 
				
			||||||
    #common options for sshfs
 | 
					#common options for sshfs
 | 
				
			||||||
    alias sshmnt='sshfs -o idmap=user,compression=no,reconnect,follow_symlinks,dir_cache=yes,ServerAliveInterval=15'
 | 
					alias sshmnt='sshfs -o idmap=user,compression=no,reconnect,follow_symlinks,dir_cache=yes,ServerAliveInterval=15'
 | 
				
			||||||
    alias pyactivate='source ./.venv/bin/activate'
 | 
					alias pyactivate='source ./.venv/bin/activate'
 | 
				
			||||||
    tre() { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
 | 
					tre() { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#setup grep to be a bit more nice
 | 
					#setup grep to be a bit more nice
 | 
				
			||||||
    local GREP_OPTIONS=""
 | 
					local GREP_OPTIONS=""
 | 
				
			||||||
    # color grep results
 | 
					# color grep results
 | 
				
			||||||
    GREP_OPTIONS+=" --color=auto"
 | 
					GREP_OPTIONS+=" --color=auto"
 | 
				
			||||||
    # ignore VCS folders (if the necessary grep flags are available)
 | 
					# ignore VCS folders (if the necessary grep flags are available)
 | 
				
			||||||
    local VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
 | 
					local VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
 | 
				
			||||||
    GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
 | 
					GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
 | 
				
			||||||
    GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
 | 
					GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
 | 
				
			||||||
    # export grep settings
 | 
					# export grep settings
 | 
				
			||||||
    alias grep="grep $GREP_OPTIONS"
 | 
					alias grep="grep $GREP_OPTIONS"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#fzf stuff
 | 
					#fzf stuff
 | 
				
			||||||
    testPath="/usr/share/fzf/key-bindings.zsh"
 | 
					testPath="/usr/share/fzf/key-bindings.zsh"
 | 
				
			||||||
    [ -f "$testPath" ] && source $testPath
 | 
					[ -f "$testPath" ] && source "$testPath"
 | 
				
			||||||
    testPath="/usr/share/fzf/completion.zsh"
 | 
					testPath="/usr/share/fzf/completion.zsh"
 | 
				
			||||||
    [ -f "$testPath" ] && source $testPath
 | 
					[ -f "$testPath" ] && source "$testPath"
 | 
				
			||||||
    #if it was installed using git, can just source the one file:
 | 
					#if it was installed using git, can just source the one file:
 | 
				
			||||||
    testPath="$HOME/.fzf.zsh"
 | 
					testPath="$HOME/.fzf.zsh"
 | 
				
			||||||
    [ -f "$testPath" ] && source $testPath
 | 
					[ -f "$testPath" ] && source "$testPath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#zoxide stuff
 | 
					#zoxide stuff
 | 
				
			||||||
    command -v zoxide &> /dev/null && eval "$(zoxide init zsh)"
 | 
					command -v zoxide &> /dev/null && eval "$(zoxide init zsh)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#check for existence of pyenv before setting it up.
 | 
					#cheat.sh is a wonderful tool, the less typing needed the better.
 | 
				
			||||||
    if command -v pyenv &> /dev/null; then
 | 
					cheat(){
 | 
				
			||||||
        export PYENV_ROOT="$HOME/.pyenv"
 | 
					    for i in "$@"; do
 | 
				
			||||||
        [[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
 | 
					        curl cheat.sh/"$i"
 | 
				
			||||||
        eval "$(pyenv init -)"
 | 
					    done
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#the tre command has some shell integration.
 | 
				
			||||||
 | 
					tre() { command tre "$@" --editor && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
 | 
				
			||||||
 | 
					tred() { command tre "$@" --editor=z --directories && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#moves a file, leaving a symlink in its place.
 | 
				
			||||||
 | 
					mvln(){
 | 
				
			||||||
 | 
					    set -eu
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Check for correct number of arguments
 | 
				
			||||||
 | 
					    if [ "$#" -ne 2 ]; then
 | 
				
			||||||
 | 
					        echo "Usage: $0 <source> <destination>"
 | 
				
			||||||
 | 
					        exit 1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					    source="$1" destination="$2"
 | 
				
			||||||
 | 
					    # Check if source exists
 | 
				
			||||||
 | 
					    if [ ! -e "$source" ]; then
 | 
				
			||||||
 | 
					        echo "$source does not exist."
 | 
				
			||||||
 | 
					        exit 1
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#fancy way of testing if a command exists
 | 
					    mv -- "$source" "$destination"
 | 
				
			||||||
command -v ruby &>/dev/null && export PATH="$PATH:$(ruby -e 'puts Gem.user_dir' 2> /dev/null)/bin/"
 | 
					    ln -s -- "$(realpath "$destination/$(basename "$source")")" "$(realpath "$source")"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue