From 8f9698bf75ff0f55f112f74ad56f878ea3b564d1 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Fri, 19 Oct 2018 15:45:51 -0700 Subject: [PATCH] Add Zsh config files Prior to this change, I was using Bash as the default shell, but I have now started using Zsh, which has more features. This change adds the zshrc and related plugin files to source control and installs them along with the bashrc files. This also updates tmux to use zsh as the default shell and command. --- install | 11 +++++++++ tmux.conf | 4 ++-- zsh/aliases.zsh | 26 ++++++++++++++++++++ zsh/completion.zsh | 7 ++++++ zsh/editing.zsh | 17 +++++++++++++ zsh/gpg.zsh | 3 +++ zsh/history.zsh | 7 ++++++ zsh/lscolors.zsh | 59 ++++++++++++++++++++++++++++++++++++++++++++++ zsh/prompt.zsh | 42 +++++++++++++++++++++++++++++++++ zshrc | 28 ++++++++++++++++++++++ 10 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 zsh/aliases.zsh create mode 100644 zsh/completion.zsh create mode 100644 zsh/editing.zsh create mode 100644 zsh/gpg.zsh create mode 100644 zsh/history.zsh create mode 100644 zsh/lscolors.zsh create mode 100644 zsh/prompt.zsh create mode 100644 zshrc diff --git a/install b/install index 9c9d9d2..3cec82c 100755 --- a/install +++ b/install @@ -227,3 +227,14 @@ then echo " source ~/.bashrc.common" fi +####################################################################### +# Install zsh files +####################################################################### +lnfile zshrc ~/.zshrc +mkfolder ~/.zshrc.d +mkfolder ~/.zshrc.d/functions +for plugin in zsh/*.zsh +do + lnfile $plugin ~/.zshrc.d/ +done + diff --git a/tmux.conf b/tmux.conf index a6a4e52..f880154 100644 --- a/tmux.conf +++ b/tmux.conf @@ -23,9 +23,9 @@ set-option -g mouse on set-option -g history-limit 100000 # Default settings -set-option -g default-command "/bin/bash" +set-option -g default-command "/bin/zsh" #set-option -g default-path "~" -set-option -g default-shell "/bin/bash" +set-option -g default-shell "/bin/zsh" # Display timeout set-option -g display-time 1500 diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh new file mode 100644 index 0000000..e7126f1 --- /dev/null +++ b/zsh/aliases.zsh @@ -0,0 +1,26 @@ +####################################################################### +# Aliases +####################################################################### +# Common aliases across systems +# ls aliases +alias ls='ls --color=auto' +alias ll='ls -l' + +# Git aliases +alias tgp='time git pull' +alias gf='git fetch' + +# Tmux aliases +# Attach to an existing tmux session +alias work='TERM=screen-256color-bce tmux -2 -u attach -d' +# Use this to launch in 256-color mode +alias tmux='TERM=screen-256color-bce tmux -2 -u' +# Trigger tmux to reopen the socket if it cannot attach +alias kick='pkill -USR1 -u $USER tmux' + +# Keep system specific aliases in a seperate file called .aliases +# If .aliases exists it will envoked by the next line: +if [[ -f $HOME/.aliases ]] +then + source $HOME/.aliases +fi diff --git a/zsh/completion.zsh b/zsh/completion.zsh new file mode 100644 index 0000000..3865142 --- /dev/null +++ b/zsh/completion.zsh @@ -0,0 +1,7 @@ +####################################################################### +# ZSH Completion +####################################################################### +zstyle :compinstall filename '/home/nkrishnan/.zshrc' + +autoload -Uz compinit +compinit diff --git a/zsh/editing.zsh b/zsh/editing.zsh new file mode 100644 index 0000000..bd5f321 --- /dev/null +++ b/zsh/editing.zsh @@ -0,0 +1,17 @@ +####################################################################### +# Key Bindings +####################################################################### +# Use emacs bindings by default +bindkey -e + +####################################################################### +# Default Editor and line editing +####################################################################### +export EDITOR=vim + +# Emacs style bindings +autoload -U edit-command-line +zle -N edit-command-line +bindkey '^xe' edit-command-line +bindkey '^x^e' edit-command-line + diff --git a/zsh/gpg.zsh b/zsh/gpg.zsh new file mode 100644 index 0000000..1d2e9c2 --- /dev/null +++ b/zsh/gpg.zsh @@ -0,0 +1,3 @@ +gpgconf --launch gpg-agent + +export SSH_AUTH_SOCK="$HOME/.gnupg/S.gpg-agent.ssh" diff --git a/zsh/history.zsh b/zsh/history.zsh new file mode 100644 index 0000000..a355def --- /dev/null +++ b/zsh/history.zsh @@ -0,0 +1,7 @@ +####################################################################### +# History configuration +####################################################################### +HISTFILE=~/.histfile +HISTSIZE=1000 +SAVEHIST=1000 +setopt appendhistory diff --git a/zsh/lscolors.zsh b/zsh/lscolors.zsh new file mode 100644 index 0000000..8b96ce8 --- /dev/null +++ b/zsh/lscolors.zsh @@ -0,0 +1,59 @@ +# Add ls coloring +# Don't bother setting LS_COLORS if it's alredy set +if [[ -n "$LS_COLORS" ]] +then + return +fi + +if [[ "`uname`" == *"Darwin"* ]] +then + # OS X uses BSD ls which is relatively restricted compared to + # GNU ls as far as coloring options go. Stick to the basics here. + # LSCOLORS is in pairs (fgcolor, bgcolor) + + # Colorscheme for LSCOLORS (BSD) + # a => black A => dark gray + # b => red B => bold red + # c => green C => bold green + # d => brown D => yellow + # e => blue E => bold blue + # f => magenta F => bold magenta + # g => cyan G => bold cyan + # h => gray H => white + # x => default + + # Ordering for LSCOLORS(BSD) + # 1. directory + # 2. symbolic link + # 3. socket + # 4. pipe + # 5. executable + # 6. block device + # 7. character device + # 8. executable with setuid set + # 9. executable with setguid set + # 10. directory writable by others, with sticky bit + # 11. directory writable by others, without sticky bit + + export LSCOLORS="ExGxbxdxCxegedabagacad" + + # Must use either CLICOLOR=1 or ls -G + export CLICOLOR=1 +fi + +DCFILE="$HOME/.dircolors" + +# We can presume we are on a GNU system, or at the very least, +# a system which has the GNU coreutils installed +if [[ -f $DCFILE ]] && [[ -s $DCFILE ]] +then + if [[ ! -z `which dircolors` ]] + then + eval `dircolors $DCFILE` + elif [[ ! -z `which gdircolors` ]] + then + # OS X with coreutils installed from MacPorts will have + # dircolors installed by default as gdircolors. + eval `gdircolors $DCFILE` + fi +fi diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh new file mode 100644 index 0000000..dfb2025 --- /dev/null +++ b/zsh/prompt.zsh @@ -0,0 +1,42 @@ +####################################################################### +# Git prompt functionality +####################################################################### +# Define a default __git_ps1 in case we don't have git prompt functionality +function __git_ps1 +{ + : +} + +# Import the Git prompt shell functions. These can be found +# @github:git/git/contrib/completion/git_prompt.sh +if [ -f $HOME/.git_prompt.sh ]; then + source $HOME/.git_prompt.sh +fi + +# Prompt header function, prints user, hostname and current directory +function prompt_header +{ + # Build the prompt prefix + local prefix + # Add the current date in YYYY-MM-DD HH:MM:SS format (yellow color) + prefix='%F{yellow}%D{%F %T}%f' + # Add @ (blue color) + prefix="$prefix %F{blue}%n@%m%f" + # Add current working directory (green color) + # This replaces the smartwd functionality with zsh conditionals + prefix="$prefix [%F{green}%(6~#%-3~/.../%2~#%~)%f]" + # Add the status of the last command, but only if it failed + prefix="$prefix %(?..%F{red}!! %? !!%f)" + + # Configuration for __git_ps1 + GIT_PS1_SHOWCOLORHINTS=yes + GIT_PS1_SHOWDIRTYSTATE=yes + GIT_PS1_SHOWUNTRACKEDFILES=yes + GIT_PS1_SHOWUPSTREAM=verbose + __git_ps1 $'\n'$prefix$'\n' '%# ' '(%s)' +} + +if [[ ! -z $TERM && "$TERM" != "dumb" ]] +then + add-zsh-hook precmd 'prompt_header' +fi diff --git a/zshrc b/zshrc new file mode 100644 index 0000000..82e2d61 --- /dev/null +++ b/zshrc @@ -0,0 +1,28 @@ +####################################################################### +# Add path entries +####################################################################### +function add_to_path { + if [[ ! ${path[(r)$1]} == $1 ]] + then + path=($1 $path) + fi +} + +add_to_path $HOME/bin + +####################################################################### +# Plugins +####################################################################### +autoload -U add-zsh-hook +fpath+="$HOME/.zshrc.d/functions" + +setopt nullglob +for plugin in $HOME/.zshrc.d/*.zsh +do + source $plugin +done +setopt nonullglob + + +# Additional options +setopt autocd extendedglob nomatch notify