From 18054755542e7dd7caa45119904ecc5ea91b2a11 Mon Sep 17 00:00:00 2001 From: cubernetes Date: Thu, 15 Oct 2026 15:47:45 +0200 Subject: [PATCH] Improve cd function to run like ls -artlh but truncated --- modules/home-manager/bash.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/home-manager/bash.nix b/modules/home-manager/bash.nix index c239ac9..d691982 100644 --- a/modules/home-manager/bash.nix +++ b/modules/home-manager/bash.nix @@ -61,8 +61,20 @@ } cd () { - : 'Run cd and if it succeeds, run ls' - builtin cd "''$@" && command ls --color -Ah + : 'Run cd; on success in a terminal, show the 4 newest entries (with a count of hidden ones)' + + builtin cd "''$@" || return + [[ -t 1 ]] || return 0 + command -v ls &>/dev/null || return 0 + + local -a lines + mapfile -t lines < <(command ls --color=always --quoting-style=shell-escape -lArth) + if (( ''${#lines[@]} > 5 )); then + printf '\033[7m... %d more entries ...\033[27m\n' "$(( ''${#lines[@]} - 5 ))"; + printf '%s\n' "''${lines[@]: -4}" + else + printf '%s\n' "''${lines[@]}" + fi } drop_caches () {