|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import configparser
|
|
|
|
|
|
|
|
|
|
# supported values: fish, bash
|
|
|
|
|
shell="bash"
|
|
|
|
|
shell="fish"
|
|
|
|
|
|
|
|
|
|
print_file="cat"
|
|
|
|
|
pretty_print_file="less -R"
|
|
|
|
@ -25,12 +26,45 @@ def is_binary_file(filepathname):
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def env_has(program):
|
|
|
|
|
whichcall = subprocess.Popen(['which', program], stdout=subprocess.PIPE)
|
|
|
|
|
return whichcall.returncode
|
|
|
|
|
|
|
|
|
|
def file_len(fname):
|
|
|
|
|
with open(fname) as f:
|
|
|
|
|
for i, l in enumerate(f):
|
|
|
|
|
pass
|
|
|
|
|
return i + 1
|
|
|
|
|
|
|
|
|
|
# bootstrap the config
|
|
|
|
|
ENV_HOME=os.environ['HOME']
|
|
|
|
|
subprocess.call(['mkdir', '-p', ENV_HOME+'/.config'])
|
|
|
|
|
if ( os.path.isfile(ENV_HOME+'/.config/what.config') ):
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
config.read(ENV_HOME+'/.config/what.config')
|
|
|
|
|
if ( 'DEFAULT' in config ):
|
|
|
|
|
if ( 'print_file' in config['DEFAULT'] ):
|
|
|
|
|
print_file = config['DEFAULT']['print_file']
|
|
|
|
|
if ( 'pretty_print_file' in config['DEFAULT'] ):
|
|
|
|
|
pretty_print_file = config['DEFAULT']['pretty_print_file']
|
|
|
|
|
if ( 'edit_file' in config['DEFAULT'] ):
|
|
|
|
|
pretty_print_file = config['DEFAULT']['edit_file']
|
|
|
|
|
if ( 'list_directory' in config['DEFAULT'] ):
|
|
|
|
|
list_directory = config['DEFAULT']['list_directory']
|
|
|
|
|
else:
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
config['DEFAULT'] = {
|
|
|
|
|
'list_directory': list_directory,
|
|
|
|
|
'edit_file': edit_file,
|
|
|
|
|
'pretty_print_file': pretty_print_file,
|
|
|
|
|
'print_file': print_file
|
|
|
|
|
}
|
|
|
|
|
print("echo Default config loaded.")
|
|
|
|
|
with open(ENV_HOME+'/.config/what.config', 'w') as configfile:
|
|
|
|
|
config.write(configfile)
|
|
|
|
|
configfile.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( len(sys.argv) == 1 ):
|
|
|
|
|
# list the contents of the current directory
|
|
|
|
|
print(list_directory)
|
|
|
|
|