13 Commits

Author SHA1 Message Date
2ac97afdd1 Update options
Fix spellings of various options, enable some new options found in
[https://github.com/willghatch/zsh-saneopt](zsh-saneopt).
2018-08-30 22:30:11 +01:00
f24253b8c1 Remove use of RPS1
Following on from the previous commit, use of `RPS1` results in the
prompt being redrawn when the terminal gets narrower, this makes the
line drawn by `fresh_line_one` scroll off the screen. By removing any
use of `RPS1` this behaviour goes away.
2018-08-30 21:57:18 +01:00
df819f58a8 Update fresh prompt
* When a command fails, don't print the error code at the end of the
  first line but directly after the git stats.
* Remove `cr` from `prompt_opts` since there is no longer a new line in
  `PS1`, combined with above, this result in no new lines being inserted
  when the terminal becomes narrower e.g. a horizontal tmux split.
* Remove `fresh_visible_length` function and instead use the length of
  string variables e.g. `${#userhost}`.
2018-08-30 21:04:05 +01:00
c636dd078c Update sandbox to use .enter and .exit 2018-08-28 22:15:33 +01:00
0992b65d17 Don't explicitly add python to PATH
After fixing the macOS `/etc/zprofile` issue rewriting the `PATH`
environment variable it is no longer necessary to explicitly add
`/usr/local/opt/python/libexec/bin` to `PATH` since Homebrew installed
python 2.x is installed in `/usr/local/bin` and is used by default.
2018-08-28 21:58:22 +01:00
9e9c43a0cf Fix error in build-dir when --build is not set 2018-08-28 14:44:19 +01:00
0ab04406ec Fix macOS PATH being rewritten in /etc/zprofile
macOS is obnoxious and overwrites the PATH from a users ~/.zshenv, which is
sourced first, in /etc/zprofile by calling `/usr/libexec/path_helper -s` so
this is required so that PATH is once again set to the desired value.
2018-08-26 20:19:12 +01:00
e17ff47d5e Only load layout when inside tmux 2018-08-26 19:11:29 +01:00
ff8bb3e4ab Change layout path to ~/.local/share/tmux/layouts 2018-08-26 18:39:02 +01:00
31d06e0f19 Add sandbox directory color to fresh_line_one 2018-08-26 15:37:30 +01:00
7bb6a459ee Fix autoenv's use of zstat 2018-08-25 15:45:11 +01:00
9e4c984822 Fix chsh to work on macOS 2018-08-24 18:26:13 +01:00
9af452a8e2 Update readme file 2018-08-24 12:29:15 +01:00
11 changed files with 97 additions and 88 deletions

View File

@@ -6,8 +6,8 @@
- brew: - brew:
- zsh - zsh
- command: - command:
- install: sudo chsh $USER -s `which zsh` - install: sudo chsh -s `which zsh` $USER
remove: sudo chsh $USER -s `which bash` remove: sudo chsh -s `which bash` $USER
- symlink: - symlink:
- {src: zlogin, dst: ~/.zlogin} - {src: zlogin, dst: ~/.zlogin}
- {src: zlogout, dst: ~/.zlogout} - {src: zlogout, dst: ~/.zlogout}

View File

@@ -51,10 +51,26 @@ display. This results in no noticeable lag when redrawing the prompt.
Plugins are sourced manually and their git repositories tracked by Plugins are sourced manually and their git repositories tracked by
[conduit][conduit], no plugin manager is used. [conduit][conduit], no plugin manager is used.
* [zsh-syntax-highlighting][syntax] Fish shell like syntax highlighting for Zsh. * [zsh-autosuggestions][zsh-autosuggestions] Fish-like autosuggestions for zsh.
* [fast-syntax-highlighting][syntax] Optimized and extended
zsh-syntax-highlighting - Fish shell like syntax highlighting for Zsh.
* [zsh-history-substring-search][search] Zsh port of the Fish shell's history * [zsh-history-substring-search][search] Zsh port of the Fish shell's history
search. search.
In addition to third party plugins the following are custom plugins residing in
this repository.
* [autoenv](autoenv/autoenv.zsh) is a inspired by [zsh-autoenv][zsh-autoenv] but
simplified by removing customization points and using a less intrusive UI.
* [build](build/build.plugin.zsh) is a collection of commands to make it easier
to build projects focuses on C/C++ development.
* [sandbox](sandbox/sandbox.plugin.zsh) is a command which sets up a throw away
directory for quickly testing ideas.
* [layout](layout/layout.plugin.zsh) is a command which setups up `tmux` panes
in a window with scripts.
* [notes](notes/notes.plugin.zsh) is a command to quickly edit markdown note
files.
## Environment & Settings ## Environment & Settings
The bulk of, if not all, configuration occurs in [`zshenv`](zshenv) and The bulk of, if not all, configuration occurs in [`zshenv`](zshenv) and
@@ -135,7 +151,9 @@ Various aliases are defined at the end of [zshrc](zshrc) for convenience.
[zsh]: https://www.zsh.org/ [zsh]: https://www.zsh.org/
[git]: https://git-scm.com/ [git]: https://git-scm.com/
[git-prompt]: https://github.com/olivierverdier/zsh-git-prompt [git-prompt]: https://github.com/olivierverdier/zsh-git-prompt
[syntax]: https://github.com/zsh-users/zsh-syntax-highlighting [zsh-autosuggestions]: https://github.com/zdharma/fast-syntax-highlighting
[zsh-autoenv]: https://github.com/Tarrasch/zsh-autoenv
[syntax]: https://github.com/zdharma/fast-syntax-highlighting
[search]: https://github.com/zsh-users/zsh-history-substring-search [search]: https://github.com/zsh-users/zsh-history-substring-search
[vim-mode]: https://github.com/sharat87/zsh-vim-mode [vim-mode]: https://github.com/sharat87/zsh-vim-mode
[tmux]: https://tmux.github.io [tmux]: https://tmux.github.io

View File

@@ -75,6 +75,9 @@ commands:
# Global entered directories array. # Global entered directories array.
_autoenv_entered=() _autoenv_entered=()
# Load zstat from stat module for inspecting modified time.
zmodload -F zsh/stat b:zstat
# Check if the given file is authorized, if not prompt the user to authorize, # Check if the given file is authorized, if not prompt the user to authorize,
# ignore, or view the file. Authorized files and their modified times are # ignore, or view the file. Authorized files and their modified times are
# stored in the ~/.cache/autoenv/authorized file to make authorization # stored in the ~/.cache/autoenv/authorized file to make authorization

View File

@@ -149,7 +149,9 @@ EOF
hash -d build=$build_dir hash -d build=$build_dir
# If `--build` is specified then evaluate the command. # If `--build` is specified then evaluate the command.
[[ -n $do_build ]] && eval build if [[ -n $do_build ]]; then
eval build
fi
fi fi
} }

View File

@@ -1,7 +1,7 @@
#compdef layout #compdef layout
__get_layouts() { __get_layouts() {
ls -1 ~/.config/tmux/layouts 2>/dev/null | \ ls -1 ~/.local/share/tmux/layouts 2>/dev/null | \
while read -r layout; do echo $layout; done while read -r layout; do echo $layout; done
} }

View File

@@ -2,7 +2,7 @@ layout() {
if [[ "$1" == "" ]]; then if [[ "$1" == "" ]]; then
echo "usage: layout <layout> [name]" echo "usage: layout <layout> [name]"
else else
tmux source-file ~/.config/tmux/layouts/$1 tmux source-file ~/.local/share/tmux/layouts/$1
if [[ "$2" != "" ]]; then if [[ "$2" != "" ]]; then
tmux rename-window $2 tmux rename-window $2
fi fi

View File

@@ -19,8 +19,8 @@ prompt_fresh_setup() {
autoload -U add-zsh-hook autoload -U add-zsh-hook
# Hook to print the first line of the "two line" prompt, this line is not # Hook to print the first line of the "two line" prompt, this line is not
# actually part of the prompt so does not get redrawn which can sometimes # actually part of the prompt so does not get redrawn, this is preferable
# cause lines before the prompt to disappear. # since sometimes lines before the prompt can disappear.
add-zsh-hook precmd fresh_line_one add-zsh-hook precmd fresh_line_one
if [ $almostontop -eq 1 ]; then if [ $almostontop -eq 1 ]; then
@@ -31,24 +31,22 @@ prompt_fresh_setup() {
add-zsh-hook -d preexec fresh_almostontop add-zsh-hook -d preexec fresh_almostontop
fi fi
if [ "$USERNAME" = "root" ]; then if [ "$USER" = "root" ]; then
local user="%{%F{9}%}%n%{%f%}" local user="%{%F{1}%}%n%{%f%}"
else else
local user="%{%F{35}%}%n%{%f%}" local user="%{%F{35}%}%n%{%f%}"
fi fi
local userhost=$USER
if [ "$SSH_CONNECTION" != "" ]; then if [ "$SSH_CONNECTION" != "" ]; then
local user="%{%F{35}%}$user%{%f%}@%{%F{244}%}%M%{%f%}" local user="$user@%{%F{244}%}%M%{%f%}"
local userhost="$userhost@`hostname`"
fi fi
local length=`fresh_visible_length "$user"`
PS1="«$user» " PS1="«$user» "
PS2="${(l:$length + 1:: :)}» " PS2="«${(l:${#userhost}:: :)}» "
RPS1='$(fresh_rprompt)' prompt_opts=(percent sp subst)
prompt_opts=(cr percent sp subst)
} }
prompt_cleanup() { prompt_cleanup() {
@@ -61,7 +59,9 @@ fresh_line_one() {
# Construct the time and directory portions of the prompt # Construct the time and directory portions of the prompt
local time_stamp="%{%F{244}%}%D{%H:%M:%S}%{%f%}" local time_stamp="%{%F{244}%}%D{%H:%M:%S}%{%f%}"
local directory="%{%F{37}%}%~%{%f%}" [[ -n $SANDBOX_HOME ]] && \
local directory="%{%F{3}%}$SANDBOX_NAME${PWD#$SANDBOX_HOME}%{%f%}" || \
local directory="%{%F{37}%}%~%{%f%}"
# Check we are in a git repository # Check we are in a git repository
if `git rev-parse --git-dir > /dev/null 2>&1`; then if `git rev-parse --git-dir > /dev/null 2>&1`; then
@@ -87,7 +87,7 @@ fresh_line_one() {
fi fi
# Construct the git prompt # Construct the git prompt
local git="%{%F{66}%}$branch%{%f%}$ahead$behind " local git=" %{%F{66}%}$branch%{%f%}$ahead$behind "
if [ -f ~/.cache/zsh/git-prompt ]; then if [ -f ~/.cache/zsh/git-prompt ]; then
# Get the change counts from git-prompt # Get the change counts from git-prompt
@@ -117,29 +117,23 @@ fresh_line_one() {
fi fi
fi fi
# Construct the prompt string # If the last command failed, display its error code at the right
local line="$time_stamp $directory $git" if [[ $exit_code -ne 0 ]]; then
local result=" %{%B%F{1}%}$exit_code%{%f%b%}"
fi
# If a virtualenv is enabled, display it's basename
if [[ ! -z "$VIRTUAL_ENV" ]]; then
py=" %{%F{4}%}py%{%f%}%{%F{3}%}$(basename $VIRTUAL_ENV)%{%f%}"
fi
# If docker-machine env is active, display the machines name
if [[ ! -z "$DOCKER_MACHINE_NAME" ]]; then
docker=" %{%F{6}%}$DOCKER_MACHINE_NAME%{%f%}"
fi
# Print the first line of the prompt # Print the first line of the prompt
if [[ $exit_code -eq 0 ]]; then print -P "$time_stamp $directory$git$py$docker$result"
print -P "$line"
else
# The last command failed, display its error code at the right
local result="%{%B%F{1}%}$exit_code%{%f%b%}"
local length=`fresh_visible_length "$line$result"`
print -P "$line${(l:COLUMNS - $length - 1:: :)}$result"
fi
}
fresh_rprompt() {
rprompt=""
if [[ ! -z "$DOCKER_MACHINE_NAME" ]]; then
rprompt="$rprompt %{%F{3}%}$DOCKER_MACHINE_NAME%{%f%}"
fi
if [[ ! -z "$VIRTUAL_ENV" ]]; then
rprompt="$rprompt %{%F{3}%}$(basename $VIRTUAL_ENV)%{%f%}"
fi
echo $rprompt
} }
fresh_almostontop() { fresh_almostontop() {
@@ -148,15 +142,10 @@ fresh_almostontop() {
print -P "$PROMPT"'$1' print -P "$PROMPT"'$1'
} }
fresh_visible_length() {
echo $(( ${#${(S%%)1//(\%(KF1]|)\{*\}|\%[Bbkf])}} ))
}
fresh_compile_git_prompt() { fresh_compile_git_prompt() {
# Compile a simple C executable which parses the output of `git status # Compile a simple C program which parses the output of `git status
# --procelain` to greatly decrease the time taken to render the prompt # --procelain` to greatly decrease the time taken to draw the prompt
local cache=~/.cache/zsh local cache=~/.cache/zsh; [ ! -d $cache ] && mkdir -p $cache
if [ ! -d $cache ]; then mkdir -p $cache; fi
if [ ! -f $cache/git-prompt ]; then if [ ! -f $cache/git-prompt ]; then
cc -x c -std=gnu99 -O3 -DNDEBUG -o $cache/git-prompt - 2> /dev/null << EOF cc -x c -std=gnu99 -O3 -DNDEBUG -o $cache/git-prompt - 2> /dev/null << EOF
#include <stdio.h> #include <stdio.h>

View File

@@ -1,9 +1,3 @@
if [[ "" == $SANDBOX_ENV_IN_FILE ]]; then
export SANDBOX_ENV_IN_FILE=$AUTOENV_IN_FILE
fi
if [[ "" == $SANDBOX_ENV_OUT_FILE ]]; then
export SANDBOX_ENV_OUT_FILE=$AUTOENV_OUT_FILE
fi
if [[ "" == $SANDBOX_ROOT ]]; then if [[ "" == $SANDBOX_ROOT ]]; then
export SANDBOX_ROOT=$HOME/Sandbox export SANDBOX_ROOT=$HOME/Sandbox
fi fi
@@ -33,11 +27,11 @@ sandbox() {
begin=$PWD begin=$PWD
cd $sandbox cd $sandbox
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $SANDBOX_ENV_IN_FILE echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> .enter
echo "SANDBOX_NAME=$2" >> $SANDBOX_ENV_IN_FILE echo "SANDBOX_NAME=$2" >> .enter
echo "unset SANDBOX_NAME" >> $SANDBOX_ENV_OUT_FILE echo "unset SANDBOX_NAME" >> .exit
echo "unset SANDBOX_HOME" >> $SANDBOX_ENV_OUT_FILE echo "unset SANDBOX_HOME" >> .exit
git init &> /dev/null git init &> /dev/null

View File

@@ -1,2 +1,7 @@
# .zprofile [1] Used for executing user's commands at start, will be sourced # .zprofile [1] Used for executing user's commands at start, will be sourced
# when starting as a login shell. # when starting as a login shell.
# macOS is obnoxious and overwrites the PATH from a users ~/.zshenv, which is
# sourced first, in /etc/zprofile by calling `/usr/libexec/path_helper -s` so
# this is required so that PATH is once again set to the desired value.
[ `uname` = Darwin ] && source ~/.zshenv

22
zshenv
View File

@@ -5,22 +5,32 @@
# Enable saving command history to file # Enable saving command history to file
[ ! -d $HOME/.cache/zsh ] && mkdir -p $HOME/.cache/zsh [ ! -d $HOME/.cache/zsh ] && mkdir -p $HOME/.cache/zsh
HISTFILE=$HOME/.cache/zsh/histfile HISTFILE=$HOME/.cache/zsh/histfile
HISTSIZE=5000 HISTSIZE=20000
SAVEHIST=5000 SAVEHIST=20000
# Enable time stats for long lasting commands # Enable time stats for long lasting commands
REPORTTIME=5 REPORTTIME=5
# Add Homebrew python to PATH on macOS if present
[ "`uname`" = "Darwin" ] && [ -d /usr/local/opt/python/libexec/bin ] &&
PATH=/usr/local/opt/python/libexec/bin:$PATH
# Add ~/.local to the environment # Add ~/.local to the environment
fpath+=$HOME/.local/share/zsh/site-functions fpath+=$HOME/.local/share/zsh/site-functions
PATH=$HOME/.local/bin:$PATH PATH=$HOME/.local/bin:$PATH
MANPATH=$HOME/.local/share/man:$MANPATH MANPATH=$HOME/.local/share/man:$MANPATH
INFOPATH=$HOME/.local/share/info:$INFOPATH INFOPATH=$HOME/.local/share/info:$INFOPATH
if [ `uname` = Darwin ]; then
[ -f /usr/local/bin/ccache ] && \
PATH=/usr/local/opt/ccache/libexec:$PATH
else
[ -f /usr/bin/ccache ] && \
PATH=/usr/lib/ccache:$PATH
fi
# Remove duplicates from environment variables
typeset -U fpath
typeset -U PATH; export PATH
typeset -U MANPATH; export MANPATH
typeset -U INFOPATH; export INFOPATH
# Use ~/.local for pip installs on macOS # Use ~/.local for pip installs on macOS
[ "`uname`" = "Darwin" ] && export PYTHONUSERBASE=$HOME/.local [ "`uname`" = "Darwin" ] && export PYTHONUSERBASE=$HOME/.local

34
zshrc
View File

@@ -32,18 +32,19 @@ source-plugin build
source-plugin sandbox source-plugin sandbox
# Layout tmux window commands # Layout tmux window commands
source-plugin layout [ "$TMUX" != "" ] && source-plugin layout
# Note taking commands # Note taking commands
source-plugin notes source-plugin notes
# Remove duplicates from history # Remove duplicates from history
setopt hist_ignore_all_dups setopt histignoredups
setopt hist_reduce_blanks
setopt hist_save_no_dups
# Enable multi-terminal history # Enable multi-terminal history
setopt inc_append_history setopt share_history
# Disable error when no glob matches are found
setopt nonomatch
# Enable comments in the prompt # Enable comments in the prompt
setopt interactive_comments setopt interactive_comments
@@ -52,10 +53,13 @@ setopt interactive_comments
setopt ignore_eof setopt ignore_eof
# Disable sound # Disable sound
unsetopt beep setopt nobeep
# Disable tty flow control, allows vim to use '<Ctrl>S' # Disable tty flow control, allows vim to use '<Ctrl>S'
unsetopt flow_control && stty -ixon setopt noflowcontrol
# Enable completions in the middle of a word
setopt completeinword
# Initialize completions # Initialize completions
autoload -U compinit autoload -U compinit
@@ -158,22 +162,6 @@ fi
# Load work related config # Load work related config
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc [ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc
# Remove duplicates from environment variables
typeset -U PATH
typeset -U MANPATH
typeset -U INFOPATH
# Add ccache symlink directory to start of PATH, this must be after
# `typeset -U PATH` because on macOS this reorders the list so ccache's
# symlinks will no longer be at the start of PATH rendering it unusable.
if [ `uname` = Darwin ]; then
[ -f /usr/local/bin/ccache ] && \
PATH=/usr/local/opt/ccache/libexec:$PATH
else
[ -f /usr/bin/ccache ] && \
PATH=/usr/lib/ccache:$PATH
fi
# Aliases # Aliases
alias grep='grep --color=always' alias grep='grep --color=always'
which cmake &> /dev/null && \ which cmake &> /dev/null && \