Skip to content

Commit

Permalink
TIMEFMT is fantastic
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Deeb-Swihart committed Sep 15, 2020
1 parent 5caf6cd commit 805a30c
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zsh/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ export CARGO_HOME="$HOME/.cargo"
export CHOOSENIM_NO_ANALYTICS=1
export DESTDIR="$HOME/.local"
which direnv >/dev/null && eval "$(direnv hook zsh)"

if [[ `uname` == Darwin ]]; then
MAX_MEMORY_UNITS=KB
else
MAX_MEMORY_UNITS=MB
fi

export TIMEFMT='%J %U user %S system %P cpu %*E total'$'\n'\
'avg shared (code): %X KB'$'\n'\
'avg unshared (data/stack): %D KB'$'\n'\
'total (sum): %K KB'$'\n'\
'max memory: %M '$MAX_MEMORY_UNITS''$'\n'\
'page faults from disk: %F'$'\n'\
'other page faults: %R'
198 changes: 198 additions & 0 deletions zsh/prompt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
# uses changed in 2012, and older versions will display incorrectly,
# in confusing ways.
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
# it has significantly better color fidelity.
#
# # Goals
#
# The aim of this theme is to only show you *relevant* information. Like most
# prompts, it will only show git information when in a git working directory.
# However, it goes a step further: everything from the current user and
# hostname to whether the last call exited with an error to whether background
# jobs are running in this shell will all be displayed automatically when
# appropriate.

### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts

CURRENT_BG='NONE'

# Special Powerline characters

() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
# NOTE: This segment separator character is correct. In 2012, Powerline changed
# the code points they use for their special characters. This is the new code point.
# If this is not working for you, you probably have an old version of the
# Powerline-patched fonts installed. Download and install the new version.
# Do not submit PRs to change this unless you have reviewed the Powerline code point
# history and have new information.
# This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
# what font the user is viewing this source code in. Do not replace the
# escape sequence with a single literal character.
# Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
SEGMENT_SEPARATOR=$'\ue0b0'
}

# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,

prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}

# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}

### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown

# Context: user@hostname (who am I and where am I)
prompt_whoami() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black white "%(!.%{%F{yellow}%}.)$USER"
fi
}

# Git: branch/detached head, dirty status
prompt_hg() {
(( $+commands[hg] )) || return
local rev status
if $(hg id >/dev/null 2>&1); then
if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added
prompt_segment red white
st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification
prompt_segment yellow black
st='±'
else
# if working copy is clean
prompt_segment green black
fi
echo -n $(hg prompt "☿ {rev}@{branch}") $st
else
st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null)
if `hg st | grep -q "^\?"`; then
prompt_segment red black
st='±'
elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black
st='±'
else
prompt_segment green black
fi
echo -n "$rev@$branch" $st
fi
fi
}

# Dir: current working directory
prompt_dir() {
# prompt_segment blue black '%~'
prompt_segment black white '%4(~:...:)%2~'
}

# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment blue black "py:`basename $virtualenv_path`"
fi
}

prompt_git() {
local branch=$(g branch -q --color=never 2>/dev/null| grep '^\*' | cut -d ' ' -f2)
if [[ ! -z "$branch" ]]; then
prompt_segment blue white "git:$branch"
fi
}

RUST_DEFAULT=$(test -f ~/.rustup/settings.toml && (grep default_toolchain ~/.rustup/settings.toml | cut -d '=' -f2 | tr -d ' "\n'))

prompt_rustenv() {
if test -f ~/.rustup/settings.toml; then
local override=$(grep "$(pwd)" ~/.rustup/settings.toml | cut -d '=' -f2 | tr -d ' "\n' | cut -d '-' -f1)
if [[ ! -z "$override" ]] && [[ "$RUST_DEFAULT" != "$override" ]]; then
prompt_segment blue black "rs:$override"
fi
fi
}

prompt_codenv() {
prompt_rustenv
prompt_virtualenv
}

# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"

[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
prompt_time() {
prompt_segment black white $(echo -n `date +"%H:%M:%S"`)
}

## Main prompt
build_prompt() {
RETVAL=$?
prompt_time
prompt_status
prompt_dir
#prompt_virtualenv
#prompt_whoami
prompt_codenv
prompt_git
prompt_end
}

if [[ ! -z "$(which starship)" ]]
then
eval "$(starship init zsh)"
else
setopt PROMPT_SUBST
PROMPT='%{%f%b%k%}$(build_prompt) '
fi

0 comments on commit 805a30c

Please sign in to comment.