DISABLE_AUTO_UPDATE=true iscmd() { command -v "$1" > /dev/null } export TERM="xterm-256color" export OTHER=$HOME/.zsh export ZSH=$HOME/.oh-my-zsh __ptrc_prompt() { local c_green=$'%{\x1b[32m%}' local c_blue=$'%{\x1b[34m%}' local c_reset=$'%{\x1b[0m%}' local c_red=$'%{\x1b[31m%}' local c_cyan=$'%{\x1b[36m%}' if [ "$SSH_TTY" ]; then local hostprefix="${c_red}${USER}${c_reset}@${c_cyan}${HOST} " else local hostprefix="" fi echo "${hostprefix}${c_blue}%~ ${c_green}>$c_reset " } if iscmd starship; then source <(starship init zsh --print-full-init) else setopt promptsubst export PS1='$(__ptrc_prompt)' fi if [ -d /usr/share/zsh/plugins ] && [ -d /usr/share/zsh/plugins/zsh-autosuggestions ]; then plugins="/usr/share/zsh/plugins" else plugins="$HOME/.local/share/zsh-plugins" fi # Load completions autoload -Uz compinit && compinit ## History file configuration HISTFILE="$HOME/.zsh_history" HISTSIZE=50000000 SAVEHIST=$HISTSIZE HISTDUP=erase ## History command configuration setopt extended_history # record timestamp of command in HISTFILE setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE setopt hist_ignore_dups # ignore duplicated commands history list setopt hist_ignore_space # ignore commands that start with space setopt hist_verify # show command with history expansion to user before running it setopt appendhistory setopt sharehistory bindkey '^p' history-search-backward bindkey '^n' history-search-forward bindkey '^[w' kill-region if iscmd nvim; then export EDITOR=nvim else export EDITOR=vim fi alias c='docker-compose' if ! iscmd docker-compose; then alias c='docker compose' fi if ! iscmd docker && iscmd podman; then alias docker='podman' alias c='podman-compose' fi export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket" for f in $OTHER/*.zsh; do if [ -f $f ]; then source $f fi done # configure completion zstyle ':completion:*:*:*:*:*' menu select zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*' zstyle ':completion:*' special-dirs true zstyle ':completion:*' list-colors '' zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm -w -w" zstyle ':completion:*' use-cache yes zstyle ':completion:*' cache-path "$HOME/.cache/zsh" # https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/key-bindings.zsh # Make sure that the terminal is in application mode when zle is active, since # only then values from $terminfo are valid if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then zle-line-init() { echoti smkx } zle-line-finish() { echoti rmkx } zle -N zle-line-init zle -N zle-line-finish fi # Use emacs key bindings bindkey -e # Start typing + [Up-Arrow] - fuzzy find history forward if [[ -n "${terminfo[kcuu1]}" ]]; then autoload -U up-line-or-beginning-search zle -N up-line-or-beginning-search bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search fi # Start typing + [Down-Arrow] - fuzzy find history backward if [[ -n "${terminfo[kcud1]}" ]]; then autoload -U down-line-or-beginning-search zle -N down-line-or-beginning-search bindkey "${terminfo[kcud1]}" down-line-or-beginning-search fi # [Home] - Go to beginning of line if [[ -n "${terminfo[khome]}" ]]; then bindkey "${terminfo[khome]}" beginning-of-line fi # [End] - Go to end of line if [[ -n "${terminfo[kend]}" ]]; then bindkey "${terminfo[kend]}" end-of-line fi # [Shift-Tab] - move through the completion menu backwards if [[ -n "${terminfo[kcbt]}" ]]; then bindkey "${terminfo[kcbt]}" reverse-menu-complete fi # [Delete] - delete forward if [[ -n "${terminfo[kdch1]}" ]]; then bindkey "${terminfo[kdch1]}" delete-char else bindkey "^[[3~" delete-char bindkey "^[3;5~" delete-char fi # [Ctrl-RightArrow] - move forward one word bindkey '^[[1;5C' forward-word # [Ctrl-LeftArrow] - move backward one word bindkey '^[[1;5D' backward-word # Enable Ctrl-x-e to edit command line autoload -U edit-command-line zle -N edit-command-line bindkey '^xe' edit-command-line if iscmd fzf; then source <(fzf --zsh); export FZF_COMPLETION_OPTS='--border --info=inline --reverse' export FZF_CTRL_R_OPTS=" --preview 'echo {}' --preview-window up:3:hidden:wrap --bind 'ctrl-/:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --color header:italic --header 'Press CTRL-Y to copy command into clipboard'" # Preview file content using bat (https://github.com/sharkdp/bat) export FZF_CTRL_T_OPTS=" --walker-skip .git,node_modules,target --preview 'bat -n --color=always {}' --bind 'ctrl-/:change-preview-window(down|hidden|)'" # Print tree structure in the preview window export FZF_ALT_C_OPTS=" --walker-skip .git,node_modules,target --preview 'tree -C {}'" if iscmd fd; then _fzf_compgen_path() { fd --hidden --follow --exclude ".git" . "$1" } fi fi if iscmd zoxide; then eval "$(zoxide init zsh)" fi if iscmd tldr; then alias tldrf='tldr --list | fzf --preview "tldr {1} --color=always" --preview-window=right,70% | xargs tldr' fi if iscmd go; then export GOPATH=$HOME/.local/go fi function atransfer () { if [ $# -eq 0 ]; then echo "No arguments specified.\nUsage:\n transfer \n ... | transfer " 1>&2; return 1; fi; if tty -s; then file="$1"; file_name=$(basename "$file"); if [ ! -e "$file" ]; then echo "$file: No such file or directory" 1>&2; return 1; fi; if [ -d "$file" ]; then file_name="$file_name.zip" ,; ( cd "$file" && zip -r -q - . ) | curl --progress-bar --upload-file "-" "https://transfer.archivete.am/$file_name" | tee /dev/null,; else cat "$file" | curl --progress-bar --upload-file "-" "https://transfer.archivete.am/$file_name" | tee /dev/null; fi; else file_name=$1; curl --progress-bar --upload-file "-" "https://transfer.archivete.am/$file_name" | tee /dev/null; fi } DISABLE_MAGIC_FUNCTIONS=true source $OTHER/func.zsh source "$plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" source "$plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"