Skip to content

Instantly share code, notes, and snippets.

View romkatv's full-sized avatar

Roman Perepelitsa romkatv

View GitHub Profile
function prompt_my_msa() {
p10k segment -e -t '$my_msa_content' -b black -f white
(( $+my_msa_content )) && return
typeset -g my_msa_content
local -r msa=~/minimal_spectrum_analyzer/build/analyzer
[[ -x $msa ]] || return
local fd
exec {fd}< <("$msa" --line_feed LF -a off -c 16 0<&- 2>&- &!) || return
@romkatv
romkatv / prompt-wave.zsh
Created March 3, 2024 15:14
Zsh prompt wave
function metronome() {
local -rF tick_sec=0.3
while true; do
zselect -t $((int(ceil(tick_sec * 100))))
print 2>/dev/null || break
done
}
function update-prompt() {
local -ri period=7
XTerm Control Sequences
Edward Moy
University of California, Berkeley
Revised by
Stephen Gildea
X Consortium (1994)
@romkatv
romkatv / migrate-zsh-dotfiles.zsh
Last active September 4, 2024 22:29
Migrate zsh dotfiles from the home directory to another directory on the same machine
# This command moves your zsh dotfiles (.zshrc, .zsh_history, etc.)
# from the home directory to ~/.config/zsh. It's been verified to
# work correctly if you are using zsh4humans. With other zsh configs
# your mileage may vary.
#
# How to:
#
# 1. Close all terminals except one.
# 2. Copy-paste this command into the only remaining terminal.
() {
@romkatv
romkatv / run-command.zsh
Last active February 9, 2024 12:48
Zsh function to run a command and capture its status, stdout and stderr
# Runs "$@" in a subshell with the caller's options, sets reply=(stdout stderr)
# and returns the status of the executed command. Both stdout and stderr are
# captured completely, including NUL bytes, incomplete UTF-8 characters and
# trailing LF, if any.
#
# Example:
#
# % zsh-run-command ls -d ~ /garbage
# % printf 'status: %s\nstdout: %s\nstderr: %s\n' $? "${(q+)reply[@]}"
# status: 2
@romkatv
romkatv / srand32.zsh
Last active May 4, 2024 05:04
srand32.zsh
# Returns a random 32-bit number.
# If /dev/urandom is cryptographically secure, so is srand32.
#
# If zsh is compiled with 64-bit number support, the result
# is non-negative. Otherwise it may be negative and the value
# is governed by the rules of unsigned-to-signed conversion in C.
#
# Examples:
#
# % print -r -- $(( srand32() ))
# Generated by Powerlevel10k configuration wizard on 2020-04-12 at 20:28 CEST.
# Based on romkatv/powerlevel10k/config/p10k-classic.zsh, checksum 30399.
# Wizard options: nerdfont-complete + powerline, small icons, classic, unicode, dark,
# 24h time, round separators, round heads, round tails, 2 lines, disconnected, no frame,
# sparse, many icons, concise, instant_prompt=quiet.
# Type `p10k configure` to generate another config.
#
# Config for Powerlevel10k with classic powerline prompt style. Type `p10k configure` to generate
# your own config based on it.
#
@romkatv
romkatv / README.md
Created February 14, 2020 07:39
Anecdote: gitstatus performance in a large Git repository
  • Source: starship/starship#921.
  • Timing for git status: between 12 and 15 seconds.
    • Method of timing: likely time git status.
    • Reported time: probably wall time.
    • Cold or hot: unknown.
  • Timing for gitstatus_query: between 3 and 4 seconds.
    • Method of timing: unknown.
    • Reported time: probably wall time.
    • Cold or hot: unknown.
  • gitstatusd command-line arguments: unknown.
@romkatv
romkatv / Advent of Code 2019.md
Last active December 31, 2019 16:48
Advent of Code 2019
@romkatv
romkatv / omz-prompt-bench.zsh
Last active November 30, 2019 11:04
Measure zsh prompt latency with various themes
# Measure zsh prompt latency with various themes:
#
# 1. Run the docker command.
# 2. Type `ZSH_THEME=XXX exec zsh` where `XXX` is a theme name such as
# `agnoster` or `powerlevel10k/powerlevel10k`.
# 3. Type `zsh-prompt-benchmark` and press and hold ENTER until benchmark
# results appear. It takes about 10 seconds.
docker run -e TERM -it --rm archlinux/base bash -uexc '
pacman -Sy --noconfirm zsh git
git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh