From ba8d4473d0e5506453f5c4c44baff02f6373c70c Mon Sep 17 00:00:00 2001 From: glmdev Date: Wed, 28 Nov 2018 22:20:46 -0600 Subject: [PATCH] add custom ls option for git repositories --- README.md | 1 - do_what.py | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f3e1fe3..f3ec4c9 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,5 @@ This project is currently a work-in-progress. Only the fish shell is supported a - Installation & Generalization - Command Memory/Env Support - Double wh does an la, not ls - - Git Repo detection for ls - Clipboard functionality - Binary File MIME Types diff --git a/do_what.py b/do_what.py index 3baab68..1687e6c 100644 --- a/do_what.py +++ b/do_what.py @@ -11,6 +11,7 @@ print_file="cat" pretty_print_file="less -R" edit_file="vim" list_directory="ls --color=auto" +list_git_directory="ls --color=auto" change_dir="cd" print_dir="pwd" help_command="man" @@ -77,6 +78,8 @@ if ( os.path.isfile(ENV_HOME+'/.config/do_what/what.config') ): help_command = config['DEFAULT']['help_command'] if ( 'path_locator' in config['DEFAULT'] ): path_locator = config['DEFAULT']['path_locator'] + if ( 'list_git_directory' in config['DEFAULT'] ): + list_git_directory = config['DEFAULT']['list_git_directory'] else: config = configparser.ConfigParser() config['DEFAULT'] = { @@ -86,6 +89,7 @@ else: 'print_file': print_file, 'help_command': help_command, 'path_locator': path_locator, + 'list_git_directory': list_git_directory, } print("echo Default config loaded.") with open(ENV_HOME+'/.config/do_what/what.config', 'w') as configfile: @@ -103,8 +107,11 @@ for arg in sys.argv: if ( (not active and len(sys.argv) == 1) or (active and len(sys.argv) == 2) ): # list the contents of the current directory - if ( not active ): - print(list_directory) + if ( not active ): + if ( os.path.isdir('.git') ): + print(list_git_directory) + else: + print(list_directory) # print the working directory (active) elif ( active ): print(print_dir) @@ -117,7 +124,10 @@ elif ( (not active and len(sys.argv) == 2) or (active and len(sys.argv) == 3) ): # if directory, list its contents if ( os.path.isdir(path) and not active ): - print(list_directory+" "+path) + if ( os.path.isdir(path+"/.git") ): + print(list_git_directory+" "+path) + else: + print(list_directory+" "+path) # if directory, change into it (active) elif ( os.path.isdir(path) and active ): print(change_dir+" "+path)