summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-03-05 03:23:22 -0600
committerAlejandro Soto <alejandro@34project.org>2022-03-05 03:23:22 -0600
commit3d8f51cb877fb5ef7855e23620be157d321839e8 (patch)
treea02119b044086ca9395a0b345073a46dfb4c5c2b
parentacbd3003cfda75326cb3a72969dae0c5fc6f32aa (diff)
Implement zsh prompt indicator for 'nix shell'
Based on <https://discourse.nixos.org/t/using-zsh-with-grml-config-and-nix-shell-prompt-indicator/13838>
-rw-r--r--home/zshrc.nix26
1 files 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}'