💾 Archived View for ait.place › dot › zshrc.txt captured on 2022-07-16 at 13:47:24.

View Raw

More Information

-=-=-=-=-=-=-

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

#Displays the prosseses on top of the terminal
ps -u $USER -o %cpu,%mem,comm | sort -d -r -k2 | head


# Prompt
autoload -U colors && colors		# Add colors
DEFAULT_PS1="%2~ "			# Add path
PS1=$DEFAULT_PS1

stty stop undef		# Disable ctrl-s to freeze terminal.
setopt autocd		# Automatically cd into typed directory.
setopt interactive_comments


[ -f "$XDG_CONFIG_HOME/shell/aliasrc" ] && source "$XDG_CONFIG_HOME/shell/aliasrc"
#[ -f "$XDG_CONFIG_HOME/shell/shortcutrc" ] && source "$XDG_CONFIG_HOME/shell/shortcutrc"

# Bookmarks
mkdir -p $XDG_DATA_HOME/bookmarks

# History
HISTSIZE=10000
SAVEHIST=10000
mkdir -p $XDG_CACHE_HOME/zsh
HISTFILE=$XDG_CACHE_HOME/zsh/history

# Do not match urls with local files
unsetopt nomatch

# Basic auto/tab complete:
autoload -U compinit && compinit -u
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION
_comp_options+=(globdots)		# Include hidden files.

#vimode
bindkey -v
export KEYTIMEOUT=1

# Enable searching through history
bindkey '^R' history-incremental-pattern-search-backward

# Edit line in vim buffer ctrl-v
autoload edit-command-line; zle -N edit-command-line
bindkey '^v' edit-command-line
# Enter vim buffer from normal mode
autoload -U edit-command-line && zle -N edit-command-line && bindkey -M vicmd "^v" edit-command-line

# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history

# Fix backspace bug when switching modes
bindkey "^?" backward-delete-char

#echo -ne '\e[5 q' # Use beam shape cursor on startup.
#preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.

bindkey -s '^o' 'nnn\n'
bindkey -s '^f' 'cd "$(dirname "$(fzf)")"\n'
bindkey '^k' autosuggest-accept
bindkey '^[[P' delete-char

# Change cursor shape for different vi modes.
function zle-keymap-select () {
    case $KEYMAP in
        vicmd) echo -ne '\e[1 q';;      # block
        viins|main) echo -ne '\e[5 q';; # beam
    esac
}
zle -N zle-keymap-select
zle-line-init() {
    zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
    echo -ne "\e[5 q"
}

zle -N zle-line-init
echo -ne '\e[5 q' # Use beam shape cursor on startup.
preexec() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.

# Some commands to have the autocomplete of another command
compdef vic=which

# Display seconds in human readable fromat
# Based on http://stackoverflow.com/a/32164707/3859566
# USAGE:
#   _displaytime <seconds>
_displaytime() {
  local T=$1
  local D=$((T/60/60/24))
  local H=$((T/60/60%24))
  local M=$((T/60%60))
  local S=$((T%60))
  [[ $D > 0 ]] && printf '%dd ' $D
  [[ $H > 0 ]] && printf '%dh ' $H
  [[ $M > 0 ]] && printf '%dm ' $M
  printf '%ds' $S
}

# Execution time start
time_preexec_hook() {
  EXEC_TIME_start=$(date +%s)
}
# Execution time end
time_precmd_hook() {
  [[ -n $EXEC_TIME_duration ]] && unset EXEC_TIME_duration
  [[ -z $EXEC_TIME_start ]] && return
  local EXEC_TIME_stop=$(date +%s)
  EXEC_TIME_duration=$(( $EXEC_TIME_stop - $EXEC_TIME_start ))
  unset EXEC_TIME_start
  if [[ $EXEC_TIME_duration -ge 2 ]]; then
		PROMPT="$(_displaytime $EXEC_TIME_duration) $DEFAULT_PS1"
	else
		PROMPT="$DEFAULT_PS1"
  fi
}

autoload -Uz add-zsh-hook
add-zsh-hook preexec time_preexec_hook
add-zsh-hook precmd time_precmd_hook

# Load zsh-autosuggestions.
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh 2>/dev/null
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null