Skip to content

Instantly share code, notes, and snippets.

@softmoth
Last active July 20, 2018 07:40
Show Gist options
  • Save softmoth/2910577d28970c80b58f8b55c34d58c1 to your computer and use it in GitHub Desktop.
Save softmoth/2910577d28970c80b58f8b55c34d58c1 to your computer and use it in GitHub Desktop.
zsh-prompt-newt preview
Note
This gist holds screenshots for my ZSH prompt theme, newt.
#! /bin/sh
# Run this setup, and then press <F4> repeatedly
# Notes:
# - Set $columns to fit Github's 900px display
# - The editor must not show any extra info (line numbers, etc.)
columns=110
zapped=
if which zaprc > /dev/null 2>&1; then
zaprc newt
zapped=1
fi
reset_layout=\
'select-layout even-vertical ; '\
'resize-pane -t 1 -y 10 ; '\
'split-window -t 2 -h ; '\
'send-keys "prompt restore" Enter "clear" Enter ": Placeholder pane" ; '\
'resize-pane -t 2 -x '$columns' ; '\
'select-pane -t 2 ; '\
'select-pane -t 1 ; '
tmux \
new-window vim -u NONE -N +'/^[^#]' +'set cursorline' script ';' \
split-window -c "$HOME" -h env -u PROMPT_NEWT_STYLE ${SHELL:-/usr/bin/zsh} ';' \
resize-pane -t 2 -x $columns ';' \
if-shell -t 1 'test #{pane_width} -lt 80' \
"$reset_layout" \
'select-pane -t 1'
tmux bind-key -n F4 \
select-pane -t 1 '\;' \
copy-mode '\;' \
send-keys -X select-line '\;' \
send-keys -X copy-selection-and-cancel '\;' \
send-keys j '\;' \
select-pane -t 2 '\;' \
paste-buffer
if [ -n $zapped ]; then
printf '%s' 'Done? Hit Enter to zaprc... '
read x && zaprc real
fi
# Press <F4> to run each line in the adjacent pane.
# Call `./demo` to set this up.
clear
prompt newt meadow
DEFAULT_USER=other ;: Show $USER when it is not DEFAULT_USER
prompt newt denver
ssh daffy
cd ~/code
sleep 3 & return 42 ;: Demo background jobs, exit status
prompt newt forest
touch x y; git add x
prompt newt jdoe '' 33 '' 40 '' 196
export GIT_DIR=$HOME/.dotfiles GIT_WORK_TREE=$HOME
: Alert because $GIT_DIR is clobbering $PWD
cd /etc
unset GIT_DIR GIT_WORK_TREE
sudo -Es
: Alert in directory because root user. It can be styled...
zstyle :prompt-theme:newt:jdoe:dir:root fg 184
cd ~/code
: Alert in VCS segment, since using vcs as root is often a mistake
exit
exit
cd ~/code
date > x
prompt newt mono; return 42
zstyle :prompt-theme:newt:mono left dir time exec_time vcs
zstyle :prompt-theme:newt:mono right status jobs vi_mode context
prompt newt ;: Run prompt setup to apply segment choices
git reset HEAD x; rm x y
prompt newt default
cd
: The End.
zstyle -d :prompt-theme:newt:mono
zaprc newt; source ~/.zshrc
tmux send-keys -t 1 "gg/^[^#]" Enter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment