# File: ~/.zshrc # Description: zsh configuration file source ~/.guix-home/profile/bin/z.sh precmd () { z --add "$(pwd -P)" } # Use zsh-autosuggestions (requires pacman package) source ~/.guix-home/profile/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh # TODO: temporary fpath=( ~/.guix-home/profile/share/zsh/site-functions "${fpath[@]}" ) # The following lines were added by compinstall zstyle ':completion:*' completer _list _expand _complete _ignored _match _correct _approximate _prefix zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|[._-/,+]=** r:|=**' 'l:|=* r:|=*' zstyle ':completion:*' max-errors 5 zstyle ':completion:*' preserve-prefix '//[^/]##/' zstyle :compinstall filename '/home/collin/.zshrc' autoload -Uz compinit compinit autoload -U promptinit; promptinit prompt spaceship # End of lines added by compinstall # Lines for zsh setup HISTFILE="$HOME/.zsh_history" HISTSIZE=10000000 SAVEHIST=10000000 setopt AUTO_CD # Change directories without cd setopt BANG_HIST # Treat the '!' character specially during expansion. setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format. setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. setopt SHARE_HISTORY # Share history between all sessions. setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history. setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again. setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate. setopt HIST_FIND_NO_DUPS # Do not display a line previously found. setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space. setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file. setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry. setopt HIST_VERIFY # Don't execute immediately upon history expansion. setopt HIST_BEEP # Beep when accessing nonexistent history. setopt COMPLETE_ALIASES # Complete command line switches for aliases # End of zsh history setup # Use emacs keybindings bindkey -e # Lines to add fzf fuzzy completion widgets supplied by fzf package source ~/.guix-home/profile/share/fzf/key-bindings.zsh source ~/.guix-home/profile/share/fzf/completion.zsh # Rebind C-t for fzf-file-widget to ESC-t bindkey -r '^T' bindkey '\et' fzf-file-widget # Rebind C-r for ffz-history-widget to ESC-r bindkey -r '^R' bindkey '\er' fzf-history-widget export FZF_DEFAULT_OPTS='--no-height --no-reverse' export FZF_ALT_C_COMMAND="find -L . -mindepth 1 \\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune -o -type d -print 2> /dev/null | cut -b3-" #export FZF_CTRL_T_COMMAND="find -L . -mindepth 1 \\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune -o -type f -print -o -type d -print -o -type l -print 2> /dev/null | cut -b3-" export FZF_CTRL_T_COMMAND="ag --hidden --ignore .git -g '' 2> /dev/null" export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null'" export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden --bind '?:toggle-preview'" # End of zsh fzf widget setup # Check for a tramp session and set a compatible PS1 # See: https://www.emacswiki.org/emacs/TrampMode [[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return # Check for an interactive session [ -z "$PS1" ] && return # Preferably, setup of man/info would be automatically be handled by 'guix shell' itself, # however this is not the case, as the profile hook for man/info pages will not be triggered # unless man or info respectively is also explicitly included in the profile. if [ ! -z "$GUIX_ENVIRONMENT" ]; then # When using guix shell (formally environment) command, automatically add the temporary # environments man page directory to MANPATH, if it exists. if [ -d "$GUIX_ENVIRONMENT/share/man" ]; then export MANPATH="$GUIX_ENVIRONMENT/share/man:$MANPATH" fi # Similarly to man, automatically add the temporary environments info page directory to # INFOPATH, if it exists. if [ -d "$GUIX_ENVIRONMENT/share/info" ]; then export INFOPATH="$GUIX_ENVIRONMENT/share/info:$INFOPATH" fi fi # Alias' to make command output prettier (use color with some commands by default) alias ls='ls --color=auto' alias ll='ls -l' alias la='ls -a' alias lla='ls -al' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' alias f='find' compdef f='find' alias b='bat' # #compdef b='bat' # No completions for bat installed/available alias x='eza' alias xs='eza' alias xl='eza -l' alias xla='eza -la' alias xx='x -alT --git' compdef x='eza' compdef xs='eza' compdef xl='eza' compdef xla='eza' compdef xx='eza' alias av='aws-vault' alias avl='aws-vault login ${AWS_PROFILE:-default}' alias ave='aws-vault exec ${AWS_PROFILE:-default} --' alias aven='aws-vault exec --no-session ${AWS_PROFILE:-default} --' compdef av='aws-vault' compdef avl='aws-vault' compdef ave='aws-vault' compdef aven='aws-vault' AWS_ALIAS='aws-vault exec --no-session ${AWS_PROFILE:-default} -- aws' AWS_SHELL_ALIAS='aws-vault exec --no-session ${AWS_PROFILE:-default} -- aws-shell' alias aws="$AWS_ALIAS" alias aws-shell="$AWS_SHELL_ALIAS" alias unaws='unset AWS_{PROFILE,SECRET_ACCESS_KEY,ACCESS_KEY_ID,SDK_LOAD_CONFIG}' alias alias-aws="alias aws='${AWS_ALIAS}'; alias aws-shell='${AWS_SHELL_ALIAS}'" alias unalias-aws='unalias aws; unalias aws-shell' alias ff='firefox' alias ffp='firefox --private-window' alias e='emacsclient -t' alias kssh='kitty +kitten ssh' alias qemu="qemu-system-$(uname -m) -enable-kvm" alias lock='cmatrix; clear; vlock' alias vv="remote-viewer --connect qemu:///session" alias xc="xclip -selection clipboard" # alias mplayer-ascii='mplayer -vo aa:driver=curses -monitorpixelaspect 0.5 -really-quiet' alias s='sudo' alias si='sudo -i' compdef s='sudo' compdef si='sudo' # Use colordiff in place of diff #alias diff='colordiff' # # TODO: uncomment # # # Shortcuts for ssh # function ssht() { # if [ "$#" -lt 1 ]; then # echo Invalid use of ssht # return 1 # else # hostname="$1" # shift # other_options="$*" # ssh -t $other_options $hostname -- /bin/sh -c 'tmux attach || (echo tmux not found, trying screen. && screen -R || echo No terminal multiplexer found. Have a shell. && $SHELL)' # fi # } # # Set colors to use with grep # export GREP_COLOR="1;33" # # Use source-highlight to make code in less syntax highlighted # export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" # export LESS=' -R ' # # Set text/background colors for ls # export LS_COLORS="di=01;37" # Turn off noscroll stty stop undef # Setup direnv hook eval "$(direnv hook zsh)" # Use zsh-source-highlight source ~/.guix-home/profile/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh # Setup nix package manager source /run/current-system/profile/etc/profile.d/nix.sh # TODO: not packaged on guix # # Initialize nvm for managing node environments # source /usr/share/nvm/init-nvm.sh # TODO: not packaged on guix # # Use hub completion # eval "$(hub alias -s zsh)" # # Use aws-cli completion # source /usr/bin/aws_zsh_completer.sh # TODO: not packaged on guix # # Use doctl completion # source <(doctl completion zsh) # TODO: not packaged on guix # # Use kubectl completion # source <(kubectl completion zsh) # TODO: not packaged on guix # # Use helm completion # source <(helm completion zsh) # # Set GOPATH and add $GOPATH/bin to PATH # export GOPATH=~/.go # export PATH="${PATH}:${GOPATH}/bin" # # Use gcloud completion # source /opt/google-cloud-sdk/completion.zsh.inc # # Setup libvirt default session uri # export LIBVIRT_DEFAULT_URI=qemu:///system # # Set default vagrant provider to libvirt # export VAGRANT_DEFAULT_PROVIDER=libvirt # # Setup ESP-32 sdk # export IDF_PATH=/opt/esp-idf-sdk # . ${IDF_PATH}/add_path.sh > /dev/null 2>&1 # Access pem ssh keys from password store pass-ssh() { psw="$1" shift key_file="$(mktemp)" pass "$psw" > "$key_file" ssh -i "$key_file" $@ rm "$key_file" } # Alias shell scripts in ~/.bin directory for i in ~/.bin/*.sh; do alias $(basename $i | sed -E 's/^(.*)\.sh$/\1/')=$i done # Startx when on tty1 if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then exec ~/.bin/startx.sh fi # Required for emacs vterm # See: https://github.com/akermu/emacs-libvterm vterm_printf(){ if [ -n "$TMUX" ]; then # Tell tmux to pass the escape sequences through # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324) printf "\ePtmux;\e\e]%s\007\e\\" "$1" elif [ "${TERM%%-*}" = "screen" ]; then # GNU screen (screen, screen-256color, screen-256color-bce) printf "\eP\e]%s\007\e\\" "$1" else printf "\e]%s\e\\" "$1" fi } # Ease message passing to vterm vterm_cmd() { local vterm_elisp vterm_elisp="" while [ $# -gt 0 ]; do vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" shift done vterm_printf "51;E$vterm_elisp" } if [[ "$INSIDE_EMACS" = 'vterm' ]]; then # Override man to run emacs man man() { vterm_cmd man "$@" } # Override info to run emacs info info() { vterm_cmd info "$@" } find-file() { vterm_cmd find-file "$@" } message() { vterm_cmd message "$@" } vterm-clear-scrollback() { vterm_cmd vterm-clear-scrollback "$@" } # For emacs vterm directory and prompt tracking # https://github.com/akermu/emacs-libvterm#directory-tracking-and-prompt-tracking vterm_prompt_end() { vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"; } setopt PROMPT_SUBST PROMPT=$PROMPT'%{$(vterm_prompt_end)%}' fi