From 19ab90f1b47ca493b698023677aedbb6319239a1 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 23 Apr 2017 16:40:43 +0200 Subject: Add new zsh conf --- zsh/.zsh/aliases.zsh | 45 +++++++++++++--- zsh/.zsh/keybindings.zsh | 7 +++ zsh/.zsh/keychain.zsh | 2 +- zsh/.zsh/nodejs.zsh | 2 +- zsh/.zsh/plugins.zsh | 3 ++ zsh/.zsh/plugins/zsh-autosuggestions | 1 + zsh/.zsh/plugins/zsh-history-substring-search | 1 + zsh/.zsh/plugins/zsh-syntax-highlighting | 1 + zsh/.zsh/prompt.zsh | 74 ++++++++++++++++++++++++--- 9 files changed, 120 insertions(+), 16 deletions(-) create mode 100644 zsh/.zsh/plugins.zsh create mode 160000 zsh/.zsh/plugins/zsh-autosuggestions create mode 160000 zsh/.zsh/plugins/zsh-history-substring-search create mode 160000 zsh/.zsh/plugins/zsh-syntax-highlighting (limited to 'zsh/.zsh') diff --git a/zsh/.zsh/aliases.zsh b/zsh/.zsh/aliases.zsh index 8fe9d93..9ca6090 100755 --- a/zsh/.zsh/aliases.zsh +++ b/zsh/.zsh/aliases.zsh @@ -16,15 +16,13 @@ # #█▓▒░ aliases alias xyzzy="echo nothing happens" -alias ls="ls -hF --color=auto" -alias ll="ls -lahF --color=auto" -alias lsl="ls -lhF --color=auto" -alias "cd.."="cd ../" +alias ".."="cd ../" +alias "..."="cd ../.." alias up="cd ../" alias rmrf="rm -rf" alias psef="ps -ef" alias mkdir="mkdir -p" -alias cp="cp -r" +alias cp="cp -r -i" alias scp="scp -r" alias mkdir="mkdir -p" alias xsel="xsel -b" @@ -65,13 +63,46 @@ alias rustofat="toilet -t -f rustofat" alias lol="base64 /dev/null +} + +parse_git_state() { + # Show different symbols as appropriate for various Git repository states + # Compose this value via multiple conditional appends. + local GIT_STATE="" + local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')" + if [ "$NUM_AHEAD" -gt 0 ]; then + GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD} + fi + local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')" + if [ "$NUM_BEHIND" -gt 0 ]; then + GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND} + fi + local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)" + if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then + GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING + fi + if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then + GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED + fi + if ! git diff --quiet 2> /dev/null; then + GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED + fi + if ! git diff --cached --quiet 2> /dev/null; then + GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED + fi + if [[ -n $GIT_STATE ]]; then + echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX" + fi +} #█▓▒░ allow functions in the prompt @@ -42,6 +90,17 @@ else # root! USER_LEVEL="${COLOR_ROOT}" fi +git_prompt_string() { + local git_where="$(parse_git_branch)" + + # If inside a Git repository, print its branch and state + [ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX" + + # If not inside the Git repo, print exit codes of last command (only if it failed) + [ ! -n "$git_where" ] && echo "%{$fg[red]%}%(?..%?)" +} + + #█▓▒░ git prompt GIT_PROMPT() { test=$(git rev-parse --is-inside-work-tree 2> /dev/null) @@ -116,6 +175,7 @@ ${USER_LEVEL}└─ - %f' ;; #█▓▒░ classic *) -PROMPT='${USER_LEVEL}[${COLOR_NORMAL}%~${USER_LEVEL}]$(GIT_PROMPT)── - %f' +PROMPT='%F{cyan}┌─[$USER@$HOST]─[$(git_prompt_string)${USER_LEVEL}]─[${COLOR_NORMAL}%~${USER_LEVEL}] +└─ - %f' ;; esac -- cgit v1.2.1