I didn't know anything about shell scripts before I started working on this. I originally downloaded hyper.js and followed the setup guide for spaceship prompt without knowing why I use doing most of what I was doing.
Long story short I later revisted my setup hoping to customize it more and I went down the rabbit hole. I installed antigen, pure prompt, clean prompt; then I went back and switched back to spaceship prompt, and switched from antigen to antibody.
This is what I've settled on now, using zsh, oh-my-zsh, antibody, spaceship prompt, and hyper terminal:
This was the basic config for most of the .zshrc
that I landed on:
source ~/.zsh_plugins.sh # point to the plugins file
# use with a bundle name to add it to the txt file
function antibody_new {
if ! [[ $# -eq 0 ]]; then
printf '%s\n%s\n' "$1" "$(cat ~/.zsh_plugins.txt)" >~/.zsh_plugins.txt
echo "added '$1' to ~/.zsh_plugins.txt"
fi # use without bundle name to just update your bundle list
antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh
antibody update
}
# Options
setopt hist_ignore_all_dups # remove older duplicate entries from history
setopt inc_append_history # save history entries as soon as they are entered
setopt hist_reduce_blanks # remove superfluous blanks from history items
setopt share_history # share history between different instances
setopt always_to_end # move cursor to end if word had one match
setopt auto_list # automatically list choices on ambiguous completion
setopt auto_menu # automatically use menu completion
setopt auto_cd # cd by typing directory name if it's not a command
# Enable autocompletions
autoload -Uz compinit
typeset -i updated_at=$(
date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null
)
if [ $(date +'%j') != $updated_at ]; then
compinit -i
else
compinit -C -i
fi
zmodload -i zsh/complist
# Improve autocompletion style
zstyle ':completion:*' menu select # select completions with arrow keys
zstyle ':completion:*' group-name '' # group results by category
zstyle ':completion:::::' completer _expand _complete _ignored _approximate # approximate matches
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=247' # color fitting my terminal bg, using 256 color code
# Save history for auto suggestions
HISTFILE=$HOME/.zsh_history
HISTSIZE=100000
SAVEHIST=$HISTSIZE
# Keybindings
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# Theme
# (see configurations below)
At the top I source the zsh plugins using antibody's static loading method. Then I define a custom function to add new plugins to my plugins txt file and update antibody's inventory of my plugins.
Next I set up all my options in zsh to my liking, which are fairly self explanatory.
Then I setup better completion, following instructions from another site.
When I used antigen I didn't need the history configuration, commands would still be autosuggested just fine without it. But when I switched to antibody I found I needed it there for autosuggestions to acutally pull from my command history.
Then the keybinding config makes it so that when I arrow up and down on an autosuggestion it actually goes through the history of the command currently there. So if I typed brew
it would show each command that started with brew
as I arrowed up and down. Without those keybindings, arrowing up and down just goes through every command I've ever entered in the prompt, regardless of what I've already typed.
I broke up the Theme section into multiple configurations I tested below.
Here are different configs I tested and screenshots of them in action, each of them can just pop in at the bottom of the code above, at the spot where it says # Theme
. Quick note if you're unfamiliar with the time tests shown with each config: the general rule is, the more small numbers there are the better.
SPACESHIP_PROMPT_ORDER=(
dir # Current directory section
git # Git section (git_branch + git_status)
jobs # Background jobs indicator
exec_time # Execution time
exit_code # Exit code section
line_sep # Line break
char # Prompt character
)
SPACESHIP_CHAR_SYMBOL="▶ " # my favs: ▶ ❯
This is a clean configuration using my standard order for the prompt. This configuration is of course the fastest (see time tests in screenshot):
SPACESHIP_PROMPT_ORDER=(
dir # Current directory section
git # Git section (git_branch + git_status)
jobs # Background jobs indicator
exec_time # Execution time
exit_code # Exit code section
line_sep # Line break
char # Prompt character
)
SPACESHIP_CHAR_SYMBOL="▶ " # my favs: ▶ ❯
SPACESHIP_PROMPT_ADD_NEWLINE=false
# launch the terminal without newline above prompt
TMOUT=1 # 1 second after terminal launch
TRAPALRM() {
SPACESHIP_PROMPT_ADD_NEWLINE=true
unset TMOUT # stops this from looping every second
}
This config allows every new command to start on a new line, except for when the terminal opens. Spaceship prompt has SPACESHIP_PROMPT_ADD_NEWLINE
on by default, which means that when a new terminal window opens there is a blank line at the top; this config was created to avoid that. Though this config results in a cleaner look, the code is dirtier; the startup time suffers as a result:
DEFAULT_ORDER=(
dir # Current directory section
git # Git section (git_branch + git_status)
jobs # Background jobs indicator
exec_time # Execution time
exit_code # Exit code section
line_sep # Line break
char # Prompt character
)
SPACESHIP_CHAR_SYMBOL="▶ " # my favs: ▶ ❯
SPACESHIP_PROMPT_ORDER=(char)
SPACESHIP_PROMPT_ADD_NEWLINE=false
# launch the terminal without newline above prompt
TMOUT=1 # 1 second after terminal launch
TRAPALRM() {
SPACESHIP_PROMPT_ORDER=($DEFAULT_ORDER)
SPACESHIP_PROMPT_ADD_NEWLINE=true
unset TMOUT # stops this from looping every second
}
wow; clear; echo "⚡ ${PWD##*/}" | lolcat # startup commands and a "welcome line"
Now the configuration is getting a lot more complicated. Here it's set so that when the terminal launches, the prompt is configured to only display the prompt character, then I'm using echo "⚡ ${PWD##*/}"
to have the the current directory (and only the current directory) displayed before the prompt character. The wow
command is part of a hyper plugin that makes the text have particle effects. Lolcat is a command line tool that makes text rainbow, (as you can see on the first line).
This configuration arguably looks the coolest, but it seriously slows down startup:
0.77 real 0.54 user 0.21 sys
0.25 real 0.16 user 0.09 sys
0.26 real 0.16 user 0.09 sys
0.25 real 0.16 user 0.08 sys
0.26 real 0.16 user 0.09 sys
0.25 real 0.15 user 0.08 sys
0.25 real 0.16 user 0.08 sys
0.26 real 0.16 user 0.09 sys
Why didn't include the time tests in the screenshot like I did with the other ones? Well the echo
command I use to make the first line of prompt gets run every time it performs one of tests. Another one of the many problems with this config.
DEFAULT_ORDER=(
dir # Current directory section
git # Git section (git_branch + git_status)
jobs # Background jobs indicator
exec_time # Execution time
exit_code # Exit code section
line_sep # Line break
char # Prompt character
)
SPACESHIP_CHAR_SYMBOL="▶ " # my favs: ▶ ❯
custom_prompt=false # default is true
welcome='wow; echo "⚡ ${PWD##*/}" | lolcat' # use for startup commands &/or custom first line
if $custom_prompt; then
SPACESHIP_PROMPT_ADD_NEWLINE=false # launch the terminal without newline above prompt
SPACESHIP_PROMPT_ORDER=(char) # start prompt with only the character (no dir or anything)
TMOUT=1 # 1 second after terminal launch
TRAPALRM() {
SPACESHIP_PROMPT_ORDER=($DEFAULT_ORDER)
SPACESHIP_PROMPT_ADD_NEWLINE=true
unset TMOUT # stops this from looping every second
}
eval $welcome
else
SPACESHIP_PROMPT_ORDER=($DEFAULT_ORDER)
fi
With this config, setting custom_prompt
to true
will give you config #3, and setting it to false will give you config #1.
This is the time tests for setting to true (like #3):
0.97 real 0.56 user 0.29 sys
0.25 real 0.15 user 0.08 sys
0.25 real 0.16 user 0.08 sys
0.26 real 0.16 user 0.08 sys
0.25 real 0.15 user 0.08 sys
0.25 real 0.15 user 0.09 sys
0.26 real 0.16 user 0.09 sys
And this is the times for setting to false (like #1):
The hope with config #4 was that I could have the best of both worlds, I'd be able to have the custom fancy welcome line, or I'd be able to just switch it off and have better performance — all without having to edit or swap out the code in the entire section of the config every time. But unfortunately the if statement seems to slow down startup whether or not I use a clean prompt. So I will probably just end up sticking with config #1, which I will attach below along with the other files I use in my setup.