update zsh prompt

* update colors
* replaced the needs_push call with arrows indicating whether a pull or push is needed (Thanks, pure)
* clean up file and add comments
* update README with thorough description of prompt
* add section on ~/.zshrc to the README
This commit is contained in:
Nick Nisi
2015-10-25 11:21:45 -05:00
parent 476bfa4236
commit 14d538d9d3
3 changed files with 83 additions and 42 deletions

View File

@@ -4,16 +4,16 @@ Welcome to my world. This is a collection of vim, tmux, and zsh configurations.
## Contents ## Contents
+ Initial setup + [Initial Setup and Installation](#initial-setup-and-installation)
+ vim setup and neovim setup + [ZSH Setup](#zsh-setup)
+ zsh setup + [Vim and Neovim Setup](#vim-and-neovim-setup)
+ tmux configuration + [Tmux Configuration](#tmux-configuration)
+ git configuration + [Git configuration](#git-configuration)
+ OSX configuration + [OSX configuration](osx-configuration)
+ Homebrew + [Homebrew](#homebrew)
+ Node.js + [Node Installation](#node-installation)
## Initial setup and installation ## Initial Setup and Installation
If on OSX, you will need to install the XCode CLI tools before continuing. To do so, open a terminal and type If on OSX, you will need to install the XCode CLI tools before continuing. To do so, open a terminal and type
@@ -33,7 +33,45 @@ cd ~/.dotfiles
Next, the isntall script will perform a check to see if it is running on an OSX machine. If so, it will install Homebrew if it is not currently installed and will install the homebrew packages listed in [`brew.sh`](install/brew.sh). Then, it will run [`installosx.sh`](installosx.sh) and change some OSX configurations. This file is pretty well documented and so it is advised that you __read through and comment out any changes you do not want__. Next, the script will call [`install/nvm.sh`](install/nvm.sh) to install Node.js (stable) using nvm. Next, the isntall script will perform a check to see if it is running on an OSX machine. If so, it will install Homebrew if it is not currently installed and will install the homebrew packages listed in [`brew.sh`](install/brew.sh). Then, it will run [`installosx.sh`](installosx.sh) and change some OSX configurations. This file is pretty well documented and so it is advised that you __read through and comment out any changes you do not want__. Next, the script will call [`install/nvm.sh`](install/nvm.sh) to install Node.js (stable) using nvm.
## vim and neovim setup ## ZSH Setup
ZSH is configured in the `zshrc.symlink` file, which will be symlinked to the home directory. The following occurs in this file:
* set the `EDITOR` to nvim
* Load any `~/.terminfo` setup
* Set the `CODE_DIR` variable, pointing to the location where the code projects exist for exclusive autocompletion with the `c` command
* Recursively search the `$DOTFILES/zsh` directory for files ending in .zsh and source them
* source a `~/.localrc` if it exists so that additional configurations can be made that won't be kept track of in this dotfiles repo. This is good for things like API keys, etc.
* Add the `~/bin` and `$DOTFILES/bin` directories to the path
* Setup NVM, RVM, and hub if they exist
* Set the base16 colorscheme to use for both the terminal (iTerm2) and vim/neovim by exporting the `$THEME` and `$BACKGROUND` environment variables
* And more...
### Prompt
The prompt is meant to be simple while still providing a lot of information to the user, particularly about the status of the git project, if the PWD is a git project. This prompt sets `precmd`, `PROMPT` and `RPROMPT`.
![](http://nicknisi.com/share/prompt.png)
The `precmd` shows the current working directory in it and the `RPROMPT` shows the git and suspended jobs info.
#### Prompt Git Info
The git info shown on the `RPROMPT` displays the current branch name, and whether it is clean or dirty.
![](http://nicknisi.com/share/git-branch-state.png)
Additionally, there are ⇣ and ⇡ arrows that indicate whether a commit has happened and needs to be pushed (⇡), and whether commits have happened on the remote branch that need to be pulled (⇣).
![](http://nicknisi.com/share/git-arrows.png)
#### Suspended Jobs
The prompt will also display a ✱ character in the `RPROMPT` indicating that there is a suspended job that exists in the background. This is helpful in keeping track of putting vim in the background by pressing CTRL-Z.
![](http://nicknisi.com/share/suspended-jobs.png)
## Vim and Neovim Setup
vim and neovim should just work once the correct plugins are installed. To install the plugins, you will need to open vim/neovim in the following way: vim and neovim should just work once the correct plugins are installed. To install the plugins, you will need to open vim/neovim in the following way:

View File

@@ -1,23 +1,13 @@
# heavily inspired by the wonderful pure theme # heavily inspired by the wonderful pure theme
# https://github.com/sindresorhus/pure # https://github.com/sindresorhus/pure
# For my own and others sanity # needed to get things like current git branch
# git:
# %b => current branch
# %a => current action (rebase/merge)
# prompt:
# %F => color dict
# %f => reset color
# %~ => current path
# %* => time
# %n => username
# %m => shortname host
# %(?..) => prompt conditional - %(condition.true.false)
autoload -Uz vcs_info autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git # You can add hg too if needed: `git hg` zstyle ':vcs_info:*' enable git # You can add hg too if needed: `git hg`
zstyle ':vcs_info:git*' formats ' %b' zstyle ':vcs_info:git*' use-simple true
zstyle ':vcs_info:git*' actionformats ' %b|%a' zstyle ':vcs_info:git*' max-exports 2
zstyle ':vcs_info:git*' formats ' %b' 'x%R'
zstyle ':vcs_info:git*' actionformats ' %b|%a' 'x%R'
autoload colors && colors autoload colors && colors
@@ -34,23 +24,35 @@ git_dirty() {
fi fi
} }
git_prompt_info() { # get the status of the current branch and it's remote
ref=$(/usr/bin/git symbolic-ref HEAD 2>/dev/null) || return # If there are changes upstream, display a ⇣
# echo "(%{\e[0;33m%}${ref#refs/heads/}%{\e[0m%})" # If there are changes that have been committed but not yet pushed, display a ⇡
echo "${ref#refs/heads/}" git_arrows() {
# do nothing if there is no upstream configured
command git rev-parse --abbrev-ref @'{u}' &>/dev/null || return
local arrows=""
local status
arrow_status="$(command git rev-list --left-right --count HEAD...@'{u}' 2>/dev/null)"
# do nothing if the command failed
(( !$? )) || return
# split on tabs
arrow_status=(${(ps:\t:)arrow_status})
local left=${arrow_status[1]} right=${arrow_status[2]}
(( ${right:-0} > 0 )) && arrows+="%F{011}⇣%f"
(( ${left:-0} > 0 )) && arrows+="%F{012}⇡%f"
echo $arrows
} }
needs_push() {
if [[ $(git cherry -v @{upstream} 2>/dev/null) == "" ]]
then
echo ""
else
echo "%{$fg_bold[magenta]%}☁%f "
fi
}
# indicate a job (for example, vim) has been backgrounded # indicate a job (for example, vim) has been backgrounded
# If there is a job in the background, display a ✱
suspended_jobs() { suspended_jobs() {
local sj
sj=$(jobs 2>/dev/null | tail -n 1) sj=$(jobs 2>/dev/null | tail -n 1)
if [[ $sj == "" ]]; then if [[ $sj == "" ]]; then
echo "" echo ""
@@ -61,8 +63,8 @@ suspended_jobs() {
precmd() { precmd() {
vcs_info vcs_info
print -P '\n%F{207}%~' print -P '\n%F{205}%~'
} }
export PROMPT='%(?.%F{magenta}.%F{red})%f ' export PROMPT='%(?.%F{205}.%F{red})%f '
export RPROMPT='`git_dirty`%F{241}$vcs_info_msg_0_%f `needs_push``suspended_jobs`' export RPROMPT='`git_dirty`%F{241}$vcs_info_msg_0_%f `git_arrows``suspended_jobs`'

View File

@@ -7,11 +7,12 @@ export REPORTTIME=10
[[ -e ~/.terminfo ]] && export TERMINFO_DIRS=~/.terminfo:/usr/share/terminfo [[ -e ~/.terminfo ]] && export TERMINFO_DIRS=~/.terminfo:/usr/share/terminfo
# define the code directory # define the code directory
# This is where my code exists and where I want the `c` autocomplete to work from exclusively
if [[ -d ~/code ]]; then if [[ -d ~/code ]]; then
export CODE_DIR=~/code export CODE_DIR=~/code
fi fi
# load all zsh config files # source all .zsh files inside of the zsh/ directory
for config ($ZSH/**/*.zsh) source $config for config ($ZSH/**/*.zsh) source $config
if [[ -a ~/.localrc ]]; then if [[ -a ~/.localrc ]]; then
@@ -25,7 +26,7 @@ compinit
for config ($ZSH/**/*completion.sh) source $config for config ($ZSH/**/*completion.sh) source $config
export EDITOR='vim' export EDITOR='nvim'
export PATH=/usr/local/bin:$PATH export PATH=/usr/local/bin:$PATH