diff options
author | EuAndreh <eu@euandre.org> | 2022-11-06 10:20:18 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-11-06 10:22:21 -0300 |
commit | ec942a79ae8ae40a2dd28927febcafcb2e01e2f1 (patch) | |
tree | 19577af252d02672bb527ac835fabbbab343a5db | |
parent | etc/sh/rc (PS1): Inline call to "vcs ps1" (diff) | |
download | dotfiles-ec942a79ae8ae40a2dd28927febcafcb2e01e2f1.tar.gz dotfiles-ec942a79ae8ae40a2dd28927febcafcb2e01e2f1.tar.xz |
etc/sh/rc (PS1): Use early returns on the helper functions
-rw-r--r-- | etc/sh/rc | 65 |
1 files changed, 37 insertions, 28 deletions
@@ -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` |