Skip to content

Instantly share code, notes, and snippets.

@Sh-ui
Last active May 20, 2021 12:53
Show Gist options
  • Save Sh-ui/f8ed7a35309c3da9a5870a1adc8144ae to your computer and use it in GitHub Desktop.
Save Sh-ui/f8ed7a35309c3da9a5870a1adc8144ae to your computer and use it in GitHub Desktop.
My terminal config with hyper terminal oh-my-zsh, and antibody with static loading

Customizing my Terminal

terminal_screenshot

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:


main setup

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.

configs

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.


#1 clean setup (with newline)

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):

with_newline_screenshot


#2 clean look (without newline)

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:

without_newline_screenshot


#3 with a custom start line

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).

welcome_screenshot

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.


#4 toggleable custom start line

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):

toggleable_without_custom_screenshot

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.

module.exports = {
config: {
updateChannel: 'stable',
fontSize: 16,
fontFamily: '"Roboto Mono for Powerline", "Roboto Mono", Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
fontWeight: 'normal',
fontWeightBold: 'bold',
lineHeight: 1,
letterSpacing: 0,
cursorColor: '#FD7CFC',
cursorAccentColor: '#000',
cursorShape: 'UNDERLINE',
cursorBlink: true,
foregroundColor: '#fff',
backgroundColor: '#161B1E', // #161B1E
selectionColor: 'rgba(248,28,229,0.3)',
borderColor: '#rgba(144,144,149,0.0)',
accentColor: '#354049',
css: '',
termCSS: '',
showHamburgerMenu: '',
showWindowControls: false,
padding: '18px 10px 10px 18px',
hyperWindowSize: {
width: 720,
height: 420,
startX: 720,
startY: 450
},
alwaysOnTop: {
debug: false,
default: false // enabled on application start
},
hyperTransparentDynamic: {
alpha: 0.50 // default 50%
},
colors: {
black: '#000000',
red: '#EF2217',
green: '#20DB24',
yellow: '#C7C329',
blue: '#0A2FC4',
magenta: '#C839C5',
cyan: '#20C5C6',
white: '#C7C7C7',
lightBlack: '#686868',
lightRed: '#FD6F6B',
lightGreen: '#67F86F',
lightYellow: '#FFFA72',
lightBlue: '#6A76FB',
lightMagenta: '#FD7CFC',
lightCyan: '#68FDFE',
lightWhite: '#FFFFFF',
},
shell: '',
shellArgs: ['--login'],
env: {},
bell: 'SOUND',
copyOnSelect: false,
defaultSSHApp: true,
},
plugins: [
"hyper-window-size",
"hyper-always-on-top",
"hyperpower",
"hyper-tabs-enhanced",
"hypercwd",
"hyperterm-paste",
"hyper-transparent-dynamic",
"hyperminimal"
],
localPlugins: [],
keymaps: {},
};
# using the static loading method for antibody (see https://getantibody.github.io)
zsh-users/zsh-history-substring-search
robbyrussell/oh-my-zsh path:plugins/z
zdharma/fast-syntax-highlighting
RobSis/zsh-completion-generator
zsh-users/zsh-autosuggestions
zsh-users/zsh-completions
denysdovhan/spaceship-prompt # theme
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
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: ▶ ❯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment