Merge pull request #2 from glmdev/tool_config

config support
master
Garrett Mills 6 years ago committed by GitHub
commit 7ec23a19d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,5 +18,6 @@ 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
- Git Repo detection for ls
- Dynamic handler selection (e.g. exa vs ls)
- Clipboard functionality
- sudo vim
- Active Mode

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

@ -0,0 +1,5 @@
[DEFAULT]
print_file = cat
pretty_print_file = less -R
edit_file = vim
list_directory = ls --color=auto
Loading…
Cancel
Save