From 4c1989287a4fd327e31d2721c04f3ec7b6ab3a3e Mon Sep 17 00:00:00 2001 From: Cuan Date: Wed, 2 Mar 2022 04:28:05 -0500 Subject: [PATCH] Added exception handling for entry list generation with an empty directory --- bin/sshyp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/sshyp b/bin/sshyp index f0f906c..21fd7f9 100755 --- a/bin/sshyp +++ b/bin/sshyp @@ -34,7 +34,7 @@ def entry_list_gen(): # generates and prints a list of all folders and entries for _root, _directories, _files in walk(path.expanduser('~/.password-pasture')): for _dir in sorted(_directories): _inner_dir = f"{_root.replace(path.expanduser('~/.password-pasture'), '')}/{_dir}" - print(f"\n\u001b[38;5;228m{_inner_dir}/") + print(f"\n\u001b[38;5;228m{_inner_dir}/\u001b[0m") _entry_list, _color_alternator = [], 1 for _s_root, _s_directories, _s_files in walk(path.expanduser(f"~/.password-pasture{_inner_dir}")): for _entry in sorted(_s_files): @@ -49,7 +49,10 @@ def entry_list_gen(): # generates and prints a list of all folders and entries _width = len(' '.join(_entry_list)) else: _width = (len(' '.join(_entry_list))/(_real/get_terminal_size()[0]) - 50) - print(fill(' '.join(_entry_list), width=_width)) + try: + print(fill(' '.join(_entry_list), width=_width)) + except ValueError: + print('\u001b[38;5;208m-empty directory!-\u001b[0m') def replace_line(file_name, line_num, text): # replaces text in a given line with different text