diff --git a/README.md b/README.md index f3ec4c9..6d78cc5 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,3 @@ This project is currently a work-in-progress. Only the fish shell is supported a - Command Memory/Env Support - Double wh does an la, not ls - Clipboard functionality - - Binary File MIME Types diff --git a/do_what.py b/do_what.py index 1687e6c..5816198 100644 --- a/do_what.py +++ b/do_what.py @@ -2,6 +2,9 @@ import sys import os import subprocess import configparser +import magic + +mime = magic.Magic(mime=True) # supported values: fish, bash, zsh shell="fish" @@ -16,6 +19,7 @@ change_dir="cd" print_dir="pwd" help_command="man" path_locator="which" +open_file="xdg-open" # general function for setting a shell's environment variable def set_runtime_var(name, value, options=""): @@ -80,6 +84,8 @@ if ( os.path.isfile(ENV_HOME+'/.config/do_what/what.config') ): path_locator = config['DEFAULT']['path_locator'] if ( 'list_git_directory' in config['DEFAULT'] ): list_git_directory = config['DEFAULT']['list_git_directory'] + if ( 'open_file' in config['DEFAULT'] ): + open_file = config['DEFAULT']['open_file'] else: config = configparser.ConfigParser() config['DEFAULT'] = { @@ -90,6 +96,7 @@ else: 'help_command': help_command, 'path_locator': path_locator, 'list_git_directory': list_git_directory, + 'open_file': open_file } print("echo Default config loaded.") with open(ENV_HOME+'/.config/do_what/what.config', 'w') as configfile: @@ -135,7 +142,8 @@ elif ( (not active and len(sys.argv) == 2) or (active and len(sys.argv) == 3) ): elif ( os.path.isfile(path) and not active ): # check if file is binary if ( is_binary_file(path) ): - print("echo Binary file.") + filemime = mime.from_file(path) + print("echo Binary file: "+filemime) else: trows, tcolumns = os.popen('stty size', 'r').read().split() # if file is taller than the terminal, pipe it to a pretty-print display @@ -149,7 +157,7 @@ elif ( (not active and len(sys.argv) == 2) or (active and len(sys.argv) == 3) ): # if file, open in editor (active) elif ( os.path.isfile(path) and active ): if ( is_binary_file(path) ): - print("echo Binary file.") + print(open_file+" "+path) else: if ( os.access(path, os.W_OK) ): print(edit_file+" "+path) diff --git a/requires.txt b/requires.txt index 1cad056..5600ad8 100644 --- a/requires.txt +++ b/requires.txt @@ -1,2 +1,2 @@ source-highlight - +pip python-magic