|
|
|
@ -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)
|
|
|
|
|