From ec942a79ae8ae40a2dd28927febcafcb2e01e2f1 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 6 Nov 2022 10:20:18 -0300 Subject: etc/sh/rc (PS1): Use early returns on the helper functions --- etc/sh/rc | 65 ++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/etc/sh/rc b/etc/sh/rc index 95b0e2d..469addd 100644 --- a/etc/sh/rc +++ b/etc/sh/rc @@ -148,19 +148,24 @@ error_marker() { } shell_status_level() { - if [ -n "${SHLVL:-}" ]; then - if [ -n "${TMUX:-}" ]; then - LVL=$((SHLVL - 1)) - else - LVL="$SHLVL" - fi - if [ "$LVL" != 1 ]; then - color -c white "$LVL" - if [ -n "${RANGER_LEVEL:-}" ]; then - color -c white '|' - color -c bluei 'r' - fi - fi + if [ -z "${SHLVL:-}" ]; then + return + fi + + if [ -n "${TMUX:-}" ]; then + LVL=$((SHLVL - 1)) + else + LVL="$SHLVL" + fi + + if [ "$LVL" = 1 ]; then + return + fi + + color -c white "$LVL" + if [ -n "${RANGER_LEVEL:-}" ]; then + color -c white '|' + color -c bluei 'r' fi } @@ -198,26 +203,30 @@ path() { } guix_env() { - if [ -n "${GUIX_ENVIRONMENT:-}" ]; then - printf '\n' - color -c blacki '~> ' - color -c purple 'guix environment ' - printf '(' - color -c blueb "$GUIX_ENVIRONMENT" - printf ')' + if [ -z "${GUIX_ENVIRONMENT:-}" ]; then + return fi + + printf '\n' + color -c blacki '~> ' + color -c purple 'guix environment ' + printf '(' + color -c blueb "$GUIX_ENVIRONMENT" + printf ')' } in_nix_shell() { - if [ -n "${IN_NIX_SHELL:-}" ]; then - printf '\n' - color -c blacki '~> ' - color -c purpleb "$IN_NIX_SHELL " - color -c purple 'nix-shell ' - printf '(' - color -c blueb "${name:-}" - printf ')' + if [ -z "${IN_NIX_SHELL:-}" ]; then + return fi + + printf '\n' + color -c blacki '~> ' + color -c purpleb "$IN_NIX_SHELL " + color -c purple 'nix-shell ' + printf '(' + color -c blueb "${name:-}" + printf ')' } PS1='`error_marker`'$(timestamp)' '$(path)' `shell_status``vcs ps1``guix_env``in_nix_shell` -- cgit v1.2.3