From fa2ad42ecfd2caa14cc46eb1732912bf8c9a44f6 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Mon, 30 Sep 2024 13:55:32 +0300 Subject: [PATCH] PS1 : Add shell lvl. --- home/program/bash/default.nix | 5 +++++ home/program/bash/module/Dvd.nix | 2 +- home/program/bash/module/Nix.nix | 6 +++--- home/program/bash/module/Ps1.nix | 8 +++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/home/program/bash/default.nix b/home/program/bash/default.nix index 40467e1..5a6d736 100644 --- a/home/program/bash/default.nix +++ b/home/program/bash/default.nix @@ -14,6 +14,11 @@ in { export -f $(find_function | tr '\n' ' ') export -f find_function + # Nested shell indicator support. + if [ -z ''${SHLVLMIN} ]; then + export SHLVLMIN=''${SHLVL} + fi + # Autostart Sway. if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then exec sway diff --git a/home/program/bash/module/Dvd.nix b/home/program/bash/module/Dvd.nix index 24a9d9b..3d44cda 100644 --- a/home/program/bash/module/Dvd.nix +++ b/home/program/bash/module/Dvd.nix @@ -37,7 +37,7 @@ # Spawn Nix shell with required tools. function dvd_shell() { - NIX_SHELL="dvd" tmpshell dvdplusrwtools cdrkit + SHELL_NAME="dvd" tmpshell dvdplusrwtools cdrkit } ''; } diff --git a/home/program/bash/module/Nix.nix b/home/program/bash/module/Nix.nix index e136e03..bba27ce 100644 --- a/home/program/bash/module/Nix.nix +++ b/home/program/bash/module/Nix.nix @@ -32,7 +32,7 @@ # Create Nix GC root in .NixRoot{NAME}. nix build ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" -o ".NixRoot''${target^}" - NIX_SHELL="''${target}" nix develop ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" + SHELL_NAME="''${target}" nix develop ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" } alias shell="nix_shell" @@ -42,7 +42,7 @@ local IFS=$'\n' local input=("''${@}") local pkgs=() - local tag="''${NIX_SHELL}" + local tag="''${SHELL_NAME}" if [[ "''${input}" = "" ]]; then help nix_tmpshell @@ -55,7 +55,7 @@ pkgs+=("nixpkgs#''${pkg}") done - NIX_SHELL="''${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ''${pkgs[@]} + SHELL_NAME="''${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ''${pkgs[@]} } alias tmpshell="nix_tmpshell" diff --git a/home/program/bash/module/Ps1.nix b/home/program/bash/module/Ps1.nix index c3529a2..5dc49d9 100644 --- a/home/program/bash/module/Ps1.nix +++ b/home/program/bash/module/Ps1.nix @@ -85,9 +85,11 @@ in { # Command on new line. PS1+="\n" - # Show nix shell name. - if [ -n "''${NIX_SHELL}" ]; then - PS1+="''${NIX_SHELL} " + # Show nix shell name or shell depth. + if [ -n "''${SHELL_NAME}" ]; then + PS1+="''${SHELL_NAME} " + elif [[ "''${SHLVL}" -gt "''${SHLVLMIN}" ]]; then + PS1+="($((''${SHLVL} - ''${SHLVLMIN}))) " fi # Show remote connections.