diff --git a/README.md b/README.md new file mode 100644 index 0000000..6939824 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# My Zsh Config + +```sh +git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions +git clone https://code.waks.be/nishiki/zsh-config.git ~/.zsh/nishiki +echo 'source "~/.zsh/nishiki/plugin.zsh" > ~/.zshrc' +``` diff --git a/aliases.zsh b/aliases.zsh new file mode 100644 index 0000000..e5ef866 --- /dev/null +++ b/aliases.zsh @@ -0,0 +1,4 @@ +alias vim="nvim" +alias vimdiff="nvim -d" +alias grep="rg" +alias cat="batcat -p" diff --git a/completion.zsh b/completion.zsh new file mode 100644 index 0000000..8707786 --- /dev/null +++ b/completion.zsh @@ -0,0 +1,21 @@ +autoload -Uz compinit +compinit + +zstyle ':completion:*' auto-description 'specify: %d' +zstyle ':completion:*' completer _expand _complete _correct _approximate +zstyle ':completion:*' format 'Completing %d' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' menu select=2 +eval "$(dircolors -b)" +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' list-colors '' +zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s +zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' +zstyle ':completion:*' menu select=long +zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s +zstyle ':completion:*' use-compctl false +zstyle ':completion:*' verbose true + +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' +zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' + diff --git a/plugin.zsh b/plugin.zsh new file mode 100644 index 0000000..986ed52 --- /dev/null +++ b/plugin.zsh @@ -0,0 +1,8 @@ +HISTSIZE=1000 +SAVEHIST=1000 +HISTFILE=~/.zsh_history + +source "${0:h}/aliases.zsh" +source "${0:h}/prompt.zsh" +source "${0:h}/completion.zsh" +source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh diff --git a/prompt.zsh b/prompt.zsh new file mode 100644 index 0000000..8106f99 --- /dev/null +++ b/prompt.zsh @@ -0,0 +1,55 @@ +autoload -U colors && colors + +function set_prompt() { + PS1="[%{$fg[yellow]%}%D{%H:%M:%S}%{$reset_color%}] %{$fg[green]%}%n%{$fg[cyan]%}@%m %{$fg[magenta]%}%~%{$reset_color%} $(git_prompt_info)%(?..%{$fg[red]%})$ %{$reset_color%}" +} + +function __git_prompt_git() { + GIT_OPTIONAL_LOCKS=0 command git "$@" +} + +function git_prompt_info() { + if ! __git_prompt_git rev-parse --git-dir &> /dev/null ; then + return 0 + fi + echo "%{$reset_color%}\ue725 on %{$fg[green]%}$(git_current_branch)$(parse_git_dirty)%{$reset_color%} " +} + +function git_current_branch() { + local ref + ref=$(__git_prompt_git symbolic-ref --quiet HEAD 2> /dev/null) + local ret=$? + if [[ $ret != 0 ]]; then + [[ $ret == 128 ]] && return # no git repo. + ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) || return + fi + echo ${ref#refs/heads/} +} + +function parse_git_dirty() { + local STATUS + local -a FLAGS + FLAGS=('--porcelain') + if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then + if [[ "${DISABLE_UNTRACKED_FILES_DIRTY:-}" == "true" ]]; then + FLAGS+='--untracked-files=no' + fi + case "${GIT_STATUS_IGNORE_SUBMODULES:-}" in + git) + # let git decide (this respects per-repo config in .gitmodules) + ;; + *) + # if unset: ignore dirty submodules + # other values are passed to --ignore-submodules + FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}" + ;; + esac + STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1) + fi + if [[ -n $STATUS ]]; then + echo "%{$fg[yellow]%}%1{±%}" + fi +} + +set_prompt +chpwd_functions+=(set_prompt)