From 7d77bc328d1e2771030d8c16433d40aad7b2f8f5 Mon Sep 17 00:00:00 2001 From: Benedikt Rips Date: Mon, 19 Oct 2020 22:49:42 +0200 Subject: [PATCH] Set the maximum length of a shortcut as left column width --- goto.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/goto.sh b/goto.sh index 1a1c8b8..490123d 100644 --- a/goto.sh +++ b/goto.sh @@ -128,8 +128,15 @@ _goto_list_aliases() { local IFS=$' ' if [ -f "$GOTO_DB" ]; then + local maxlength=0 while read -r name directory; do - printf '\e[1;36m%20s \e[0m%s\n' "$name" "$directory" + local length=${#name} + if [[ $length -gt $maxlength ]]; then + local maxlength=$length + fi + done < "$GOTO_DB" + while read -r name directory; do + printf "\e[1;36m%${maxlength}s \e[0m%s\n" "$name" "$directory" done < "$GOTO_DB" else echo "You haven't configured any directory aliases yet."