diff options
author | Mateja <mail@matejamaric.com> | 2021-06-20 22:01:05 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-06-20 22:01:05 +0200 |
commit | 5c68b137a6b1ecf59e4c89ac5ca9352c0ef3e849 (patch) | |
tree | c4b91179b698d74b2f8b0c7ea92266678e556f65 /.config/zsh | |
parent | 740c3cc87b71c9f7a68f83f5c6a1434600f04220 (diff) | |
download | dotfiles-5c68b137a6b1ecf59e4c89ac5ca9352c0ef3e849.tar.gz dotfiles-5c68b137a6b1ecf59e4c89ac5ca9352c0ef3e849.zip |
Added zsh configuration files.
Diffstat (limited to '.config/zsh')
-rw-r--r-- | .config/zsh/.gitignore | 2 | ||||
-rw-r--r-- | .config/zsh/.zshrc | 1 | ||||
-rw-r--r-- | .config/zsh/zsh-aliases | 24 | ||||
-rw-r--r-- | .config/zsh/zsh-exports | 21 | ||||
-rw-r--r-- | .config/zsh/zsh-functions | 31 | ||||
-rw-r--r-- | .config/zsh/zsh-prompt | 40 | ||||
-rw-r--r-- | .config/zsh/zsh-vim-mode | 26 | ||||
-rw-r--r-- | .config/zsh/zshrc | 70 |
8 files changed, 215 insertions, 0 deletions
diff --git a/.config/zsh/.gitignore b/.config/zsh/.gitignore new file mode 100644 index 0000000..da6ab73 --- /dev/null +++ b/.config/zsh/.gitignore @@ -0,0 +1,2 @@ +.zcompdump +plugins/ diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc new file mode 100644 index 0000000..c0473d9 --- /dev/null +++ b/.config/zsh/.zshrc @@ -0,0 +1 @@ +source $ZDOTDIR/zshrc diff --git a/.config/zsh/zsh-aliases b/.config/zsh/zsh-aliases new file mode 100644 index 0000000..5015453 --- /dev/null +++ b/.config/zsh/zsh-aliases @@ -0,0 +1,24 @@ +#!/bin/sh + +alias ls='ls --color=auto' +alias ll='ls --color=auto -lAh' +#alias l='ls -CF' + +alias dir='dir --color=auto' +alias vdir='vdir --color=auto' + +# Colorize grep output (good for log files) +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' + + +alias yts="mpv --ytdl-format='bestvideo[height<=360]+bestaudio'" +alias ytd='youtube-dl -o "%(playlist_index)d-%(title)s.%(ext)s"' +alias ytv3="youtube-dl --write-auto-sub -f 'bestvideo[height<=360]+bestaudio/best[height<=360]' -o '%(playlist_index)d-%(title)s.%(ext)s'" +alias ytv4="youtube-dl --write-auto-sub -f 'bestvideo[height<=480]+bestaudio/best[height<=480]' -o '%(playlist_index)d-%(title)s.%(ext)s'" +alias ytv7="youtube-dl --write-auto-sub -f 'bestvideo[height<=720]+bestaudio/best[height<=720]' -o '%(playlist_index)d-%(title)s.%(ext)s'" +alias ytv10="youtube-dl --write-auto-sub -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' -o '%(playlist_index)d-%(title)s.%(ext)s'" +alias yta='youtube-dl --extract-audio -o "%(playlist_index)d-%(title)s.%(ext)s"' + +alias zsh-update-plugins="find "$ZDOTDIR/plugins" -type d -exec test -e '{}/.git' ';' -print0 | xargs -I {} -0 git -C {} pull -q" diff --git a/.config/zsh/zsh-exports b/.config/zsh/zsh-exports new file mode 100644 index 0000000..b16dfd3 --- /dev/null +++ b/.config/zsh/zsh-exports @@ -0,0 +1,21 @@ +#!/bin/sh + +eval $(keychain --eval --agents gpg,ssh --quiet) +export XDG_CONFIG_HOME=$HOME/.config +export XDG_CACHE_HOME=$HOME/.cache +export XDG_DATA_HOME=$HOME/.local/share +export ZDOTDIR=$HOME/.config/zsh + +HISTFILE="$XDG_DATA_HOME"/zsh/history +HISTSIZE=1000000 +SAVEHIST=1000000 + +export PATH=$PATH:/sbin:/usr/sbin:$HOME/.local/bin/:$HOME/.config/composer/vendor/bin:$HOME/.local/share/go/bin + +export EDITOR='nvim' +export VISUAL='nvim' + +export MANPAGER='nvim +Man!' +export MANWIDTH=999 + +export GOPATH=$HOME/.local/share/go diff --git a/.config/zsh/zsh-functions b/.config/zsh/zsh-functions new file mode 100644 index 0000000..ede0039 --- /dev/null +++ b/.config/zsh/zsh-functions @@ -0,0 +1,31 @@ +# Function to source files if they exist +function zsh_add_file() { + [ -f "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1" +} + +function zsh_add_plugin() { + PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2) + if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then + # For plugins + zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" || \ + zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh" + else + git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" + fi +} + +function zsh_add_completion() { + PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2) + if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then + # For completions + completion_file_path=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*) + fpath+="$(dirname "${completion_file_path}")" + zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" + else + git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME" + fpath+=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*) + [ -f $ZDOTDIR/.zccompdump ] && $ZDOTDIR/.zccompdump + fi + completion_file="$(basename "${completion_file_path}")" + if [ "$2" = true ] && compinit "${completion_file:1}" +} diff --git a/.config/zsh/zsh-prompt b/.config/zsh/zsh-prompt new file mode 100644 index 0000000..f0a86dc --- /dev/null +++ b/.config/zsh/zsh-prompt @@ -0,0 +1,40 @@ +#!/bin/sh + +## autoload vcs and colors +autoload -Uz vcs_info +autoload -U colors && colors + +# enable only git +zstyle ':vcs_info:*' enable git + +# setup a hook that runs before every ptompt. +precmd_vcs_info() { vcs_info } +precmd_functions+=( precmd_vcs_info ) +setopt prompt_subst + +# add a function to check for untracked files in the directory. +# from https://github.com/zsh-users/zsh/blob/master/Misc/vcs_info-examples +zstyle ':vcs_info:git*+set-message:*' hooks git-untracked +# ++vi-git-untracked(){ + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ + git status --porcelain | grep '??' &> /dev/null ; then + # This will show the marker if there are any untracked files in repo. + # If instead you want to show the marker only if there are untracked + # files in $PWD, use: + #[[ -n $(git ls-files --others --exclude-standard) ]] ; then + hook_com[staged]+='!' # signify new files with a bang + fi +} + +zstyle ':vcs_info:*' check-for-changes true +# zstyle ':vcs_info:git:*' formats " %r/%S %b %m%u%c " +zstyle ':vcs_info:git:*' formats " %{$fg[blue]%}(%{$fg[red]%}%m%u%c%{$fg[yellow]%}%{$fg[magenta]%} %b%{$fg[blue]%})" + +# format our main prompt for hostname current folder, and permissions. +PROMPT="%B%{$fg[blue]%}[%{$fg[white]%}%n%{$fg[red]%}@%{$fg[white]%}%m%{$fg[blue]%}] %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )%{$fg[cyan]%}%c%{$reset_color%}" +# PROMPT="%{$fg[green]%}%n@%m %~ %{$reset_color%}%#> " +PROMPT+="\$vcs_info_msg_0_ " +# TODO look into this for more colors +# https://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ +# also ascii escape codes diff --git a/.config/zsh/zsh-vim-mode b/.config/zsh/zsh-vim-mode new file mode 100644 index 0000000..862c963 --- /dev/null +++ b/.config/zsh/zsh-vim-mode @@ -0,0 +1,26 @@ +# bindkey -e will be emacs mode +bindkey -v +export KEYTIMEOUT=1 + +# 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 +bindkey -v '^?' backward-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. diff --git a/.config/zsh/zshrc b/.config/zsh/zshrc new file mode 100644 index 0000000..9b14614 --- /dev/null +++ b/.config/zsh/zshrc @@ -0,0 +1,70 @@ +#!/bin/sh + +# some useful options (man zshoptions) +setopt autocd extendedglob nomatch menucomplete +setopt interactive_comments +stty stop undef # Disable ctrl-s to freeze terminal. +zle_highlight=('paste:none') + +# beeping is annoying +unsetopt BEEP + + +# completions +autoload -Uz compinit +zstyle ':completion:*' menu select +# zstyle ':completion::complete:lsof:*' menu yes select +zmodload zsh/complist +# compinit +_comp_options+=(globdots) # Include hidden files. + +autoload -U up-line-or-beginning-search +autoload -U down-line-or-beginning-search +zle -N up-line-or-beginning-search +zle -N down-line-or-beginning-search + +# Colors +autoload -Uz colors && colors + +# Useful Functions +source "$ZDOTDIR/zsh-functions" + +# Normal files to source +zsh_add_file "zsh-exports" +zsh_add_file "zsh-vim-mode" +zsh_add_file "zsh-aliases" +zsh_add_file "zsh-prompt" + +# Plugins +zsh_add_plugin "zsh-users/zsh-autosuggestions" +zsh_add_plugin "zsh-users/zsh-syntax-highlighting" +# For more plugins: https://github.com/unixorn/awesome-zsh-plugins +# More completions https://github.com/zsh-users/zsh-completions + +# Key-bindings +bindkey -s '^o' 'ranger^M' +bindkey -s '^f' 'zi^M' +bindkey -s '^s' 'ncdu^M' +# bindkey -s '^n' 'nvim $(fzf)^M' +# bindkey -s '^v' 'nvim\n' +bindkey -s '^z' 'zi^M' +bindkey '^[[P' delete-char +bindkey "^p" up-line-or-beginning-search # Up +bindkey "^n" down-line-or-beginning-search # Down +bindkey "^k" up-line-or-beginning-search # Up +bindkey "^j" down-line-or-beginning-search # Down +bindkey -r "^u" +bindkey -r "^d" + +# FZF +# TODO update for mac +[ -f /usr/share/fzf/completion.zsh ] && source /usr/share/fzf/completion.zsh +[ -f /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh +[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh +[ -f $ZDOTDIR/completion/_fnm ] && fpath+="$ZDOTDIR/completion/" +# export FZF_DEFAULT_COMMAND='rg --hidden -l ""' +compinit + +# Edit line in vim with ctrl-e: +autoload edit-command-line; zle -N edit-command-line +# bindkey '^e' edit-command-line |