diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-03-25 23:38:13 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-03-25 23:38:13 -0500 |
commit | e6051a38a672182c7f7dfa083ca1e72b97803c94 (patch) | |
tree | 734e251bab033169399432fe1c93fc879dfab578 /zsh | |
parent | bb375ba979dfc0c575443f8309ee52d0fd446a26 (diff) |
feat: migrated to gnu stow
Diffstat (limited to 'zsh')
-rw-r--r-- | zsh/.config/zsh/aliases.sh | 30 | ||||
-rw-r--r-- | zsh/.config/zsh/env.sh | 24 | ||||
-rw-r--r-- | zsh/.zshrc | 132 | ||||
-rw-r--r-- | zsh/keybindings.zsh | 116 |
4 files changed, 186 insertions, 116 deletions
diff --git a/zsh/.config/zsh/aliases.sh b/zsh/.config/zsh/aliases.sh new file mode 100644 index 0000000..3e87862 --- /dev/null +++ b/zsh/.config/zsh/aliases.sh @@ -0,0 +1,30 @@ +alias ls='ls --color=tty' +alias l='ls -lah' +alias la='ls -lAh' +alias ll='ls -lh' +alias lla='ls -lA' +alias lsa='ls -lah' +alias grep='grep --color' +alias ipa="ip -s -c -h a" +alias untar="tar -zxvf" +alias td=". td.sh" +alias vim=nvim +#python +alias pip=pip3 +alias python=python3 +# docker +alias dexec="docker exec -it" +alias dps="docker ps" +# docker compose +alias dc="docker compose" +alias dce="docker compose exec" +alias dcps="docker compose ps" +alias dcls="docker compose ls" +alias dcdn="docker compose down" +alias dcup="docker compose up" +alias dcupd="docker compose up -d" +alias dcl="docker compose logs" +alias dclf="docker compose logs -f" +# docker context +alias dct="docker context" +alias dcu="docker context use" diff --git a/zsh/.config/zsh/env.sh b/zsh/.config/zsh/env.sh new file mode 100644 index 0000000..2429dd6 --- /dev/null +++ b/zsh/.config/zsh/env.sh @@ -0,0 +1,24 @@ +# XDG +export XDG_CONFIG_HOME=~/.config +export XDG_CACHE_HOME=~/.cache +export XDG_DATA_HOME=~/.local/share +export XDG_RUNTIME_DIR=~/.xdg + +# Path +export PATH=$PATH:$HOME/.local/bin +export PATH=$PATH:$HOME/.scripts +export PATH=$PATH:$HOME/.go/bin +export PATH=$PATH:$HOME/.dotnet/tools +export PATH=$PATH:$HOME/.cargo/bin +export PATH=$PATH:/usr/local/texlive/2021/bin/x86_64-linux + +# Misc +export EDITOR="$(command -v vim 2>/dev/null || command -v vi)" +export VISUAL="code --wait" +export GPG_TTY=$(tty) +export MANPAGER="sh -c 'col -bx | bat -l man -p'" +export MANROFFOPT="-c" +export GOPATH=$HOME/.go +export STARSHIP_LOG="error" +export FZF_PREVIEW_COMMAND="bat --style=numbers,changes --wrap never --color always {} || cat {} || tree -C {}" +export FZF_CTRL_T_OPTS="--min-height 30 --preview-window down:60% --preview-window noborder --preview '($FZF_PREVIEW_COMMAND) 2> /dev/null'" diff --git a/zsh/.zshrc b/zsh/.zshrc new file mode 100644 index 0000000..6df7443 --- /dev/null +++ b/zsh/.zshrc @@ -0,0 +1,132 @@ +# Opts +HYPHEN_INSENSITIVE="true" +DISABLE_UPDATE_PROMPT="true" +DISABLE_AUTO_TITLE="true" +HISTFILE=~/.zsh_history +HISTSIZE=10000 +SAVEHIST=10000 + +setopt NO_BEEP +setopt MENU_COMPLETE +setopt auto_pushd # auto push to the directory stack on cd +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 share_history # share command history data + +# Exports +export ZDOTDIR=${XDG_CONFIG_HOME:-$HOME/.config}/zsh +export FZF_PREVIEW_COMMAND="bat --style=numbers,changes --wrap never --color always {} || cat {} || tree -C {}" +export FZF_DEFAULT_COMMAND="fd --type f || git ls-tree -r --name-only HEAD || rg --files || find ." +export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" +export FZF_CTRL_T_OPTS="--min-height 30 --preview-window down:60% --preview-window noborder --preview '($FZF_PREVIEW_COMMAND) 2> /dev/null'" +export GOPATH=$HOME/.go +typeset -A ZSH_HIGHLIGHT_STYLES +export ZSH_HIGHLIGHT_STYLES[path]='fg=cyan' +export ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern line) +export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd completion) + +# Load ZDOTDIR +for f in $ZDOTDIR/*.*sh; do source $f; done + +# Misc +command -v fd &>/dev/null && _fzf_compgen_path() { + fd --hidden --follow --exclude ".git" . "$1" +} + +command -v fd &>/dev/null && _fzf_compgen_dir() { + fd --type d --hidden --follow --exclude ".git" . "$1" +} + +eval "$(starship init zsh 2>/dev/null)" + +set_win_title() { + local prefix + + if [ "$USER" != "tobyv" ]; then + prefix="${USER} in " + fi + + if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + prefix="${prefix/in/on}${HOST} in " + fi + + echo -ne "\033]0;${prefix}${PWD/$HOME/~}\007" +} + +precmd_functions+=(set_win_title) + +bindkey '^ ' autosuggest-accept +bindkey '^[[Z' reverse-menu-complete + +# Plugins +function plugin-load { + local repo plugin_name plugin_dir initfile initfiles + export ZPLUGINDIR=${ZPLUGINDIR:-${ZDOTDIR:-$HOME/.config/zsh}/plugins} + for repo in $@; do + plugin_name=${repo:t} + plugin_dir=$ZPLUGINDIR/$plugin_name + initfile=$plugin_dir/$plugin_name.plugin.zsh + + if [[ ! -d $plugin_dir ]]; then + echo "Cloning $repo" + git clone -q --depth 1 --recursive --shallow-submodules https://github.com/$repo $plugin_dir + fi + + if [[ ! -e $initfile ]]; then + initfiles=($plugin_dir/*.plugin.{z,}sh(N) $plugin_dir/*.{z,}sh{-theme,}(N)) + [[ ${#initfiles[@]} -gt 0 ]] || { echo "Plugin has no init file '$repo'." >&2 && continue } + ln -sf "${initfiles[1]}" "$initfile" + fi + + fpath+=$plugin_dir + (( $+functions[zsh-defer] )) && zsh-defer . $initfile || . $initfile + done +} + +repos=( + romkatv/zsh-defer + jirutka/zsh-shift-select + zsh-users/zsh-completions + Aloxaf/fzf-tab + joshskidmore/zsh-fzf-history-search + srijanshetty/zsh-pandoc-completion + zsh-users/zsh-syntax-highlighting + zsh-users/zsh-autosuggestions +) + +plugin-load $repos + +function comp-load { + local comp src name comp_file + export ZCOMPDIR=${ZCOMPDIR:-${XDG_DATA_HOME:-$HOME/.local/share}/zsh/site-functions} + mkdir -p $ZCOMPDIR + for comp in $@; do + src="$(echo $comp | sed 's/[:][^:]*$//')" + name="$(echo $comp | sed 's/.*[:]//' | sed 's/^[^_]/_&/')" + + if [[ -n $name ]]; then + name="$(basename $src | sed 's/^[^_]/_&/')" + fi + + comp_file=$ZCOMPDIR/$name + + if [[ ! -f $comp_file ]]; then + curl -sL https://raw.githubusercontent.com/$src >$comp_file + fi + done + + fpath+=$ZCOMPDIR + + autoload -U compinit + compinit -i + + zstyle ':completion:*' menu select +} + +comps=( + dotnet/cli/master/scripts/register-completions.zsh:_dotnet + docker/cli/master/contrib/completion/zsh/_docker +) diff --git a/zsh/keybindings.zsh b/zsh/keybindings.zsh deleted file mode 100644 index 31b17fd..0000000 --- a/zsh/keybindings.zsh +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env zsh - -r-delregion() { - if ((REGION_ACTIVE)) then - zle kill-region - else - local widget_name=$1 - shift - zle $widget_name -- $@ - fi -} - -r-deselect() { - ((REGION_ACTIVE = 0)) - local widget_name=$1 - shift - zle $widget_name -- $@ -} - -r-select() { - ((REGION_ACTIVE)) || zle set-mark-command - local widget_name=$1 - shift - zle $widget_name -- $@ -} - -r-select-a() { - r-deselect beginning-of-line - r-select end-of-line -} - -r-undo() { - zle undo -} - -r-copy() { - if ((REGION_ACTIVE)) then - zle copy-region-as-kill - printf "$CUTBUFFER" | xclip -i - else - zle kill-whole-line - fi -} - -r-cut() { - if ((REGION_ACTIVE)) then - zle kill-region - else - zle kill-whole-line - fi - printf "$CUTBUFFER" | xclip -i -} - -for key kcap seq mode widget ( - sleft kLFT $'\e[1;2D' select backward-char - sright kRIT $'\e[1;2C' select forward-char - sup kri $'\e[1;2A' select up-line-or-history - sdown kind $'\e[1;2B' select down-line-or-history - - send kEND $'\E[1;2F' select end-of-line - send2 x $'\E[4;2~' select end-of-line - - shome kHOM $'\E[1;2H' select beginning-of-line - shome2 x $'\E[1;2~' select beginning-of-line - - left kcub1 $'\EOD' deselect backward-char - right kcuf1 $'\EOC' deselect forward-char - - end kend $'\EOF' deselect end-of-line - end2 x $'\E4~' deselect end-of-line - - home khome $'\EOH' deselect beginning-of-line - home2 x $'\E1~' deselect beginning-of-line - - csleft x $'\E[1;6D' select backward-word - csright x $'\E[1;6C' select forward-word - csend x $'\E[1;6F' select end-of-line - cshome x $'\E[1;6H' select beginning-of-line - - cleft x $'\E[1;5D' deselect backward-word - cright x $'\E[1;5C' deselect forward-word - - del kdch1 $'\E[3~' delregion delete-char - bs x $'^?' delregion backward-delete-char - - cz x "^Z" undo "" - cc x "^C" copy "" - cx x "^X" cut "" - ca x "^A" select-a "" - ) { - eval "key-$key() { - r-$mode $widget \$@ - }" - zle -N key-$key - bindkey ${terminfo[$kcap]-$seq} key-$key -} - -bindkey '^ ' autosuggest-accept -bindkey '^[[Z' reverse-menu-complete - -# register ctrl+c as interupt -function ctrl_c_intr() { - stty intr \^C <$TTY >$TTY -} - -# register ctrl+y as interupt -function ctrl_y_intr() { - stty intr \^Y <$TTY >$TTY -} - -# make sure we can register hooks -autoload -Uz add-zsh-hook || return - -# register the functions as hooks -add-zsh-hook preexec ctrl_c_intr -add-zsh-hook precmd ctrl_y_intr |