From 3d8f51cb877fb5ef7855e23620be157d321839e8 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Sat, 5 Mar 2022 03:23:22 -0600 Subject: Implement zsh prompt indicator for 'nix shell' Based on --- home/zshrc.nix | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/home/zshrc.nix b/home/zshrc.nix index 134ee5a..68c3958 100644 --- a/home/zshrc.nix +++ b/home/zshrc.nix @@ -1,13 +1,10 @@ { grml-zsh-config }: '' source ${grml-zsh-config}/etc/zsh/zshrc - #export PATH="$PATH:$HOME/.local/bin:$HOME/System/local/bin:$HOME/System/bin:$HOME/.cargo/bin" + export PATH="$PATH:$HOME/.cargo/bin" alias reset='tput reset' alias reload='exec zsh' - alias py=python - alias py2=python2 - alias py3=python3 function spawn() { if [ ! -x "$(command -v $1)" ]; then @@ -39,7 +36,26 @@ bindkey '\eOB' down-line-or-beginning-search bindkey '\e[B' down-line-or-beginning-search - zstyle ':prompt:grml:left:setup' items $([ ''${NO_USERATHOST:-0} -gt 0 ] || echo user at host) path percent + INSTALLABLES=() + while read -d: PATH_ITEM; do + if [[ "$PATH_ITEM" =~ "^/nix/store/[a-z0-9]+-([a-zA-Z][a-zA-Z0-9_]*(-[a-zA-Z][a-zA-Z0-9_]*)*)" ]]; then + INSTALLABLES+=("''${match[1]}") + fi + done <<<"$PATH" + + if [ "''${#INSTALLABLES[@]}" -gt 0 ]; then + _GRML_NIX_SHELL="{''${INSTALLABLES[@]}} " + fi + + unset INSTALLABLES PATH_ITEM + + function grml_nix_shell() { + REPLY="$_GRML_NIX_SHELL" + } + + grml_theme_add_token nix-shell -f grml_nix_shell '%F{red}' '%f' + + zstyle ':prompt:grml:left:setup' items $([ ''${NO_USERATHOST:-0} -gt 0 ] || echo user at host) path nix-shell percent zstyle ':prompt:grml:right:setup' items sad-smiley vcs $([ ''${NO_BATTERY:-0} -gt 0 ] || echo battery) time zstyle ':prompt:grml:right:items:time' pre ' %F{yellow}' -- cgit v1.2.3