config support

This commit is contained in:
glmdev 2018-11-28 14:27:01 -06:00
parent 53320c8259
commit 401d09992c
3 changed files with 42 additions and 2 deletions

View File

@ -18,5 +18,6 @@ This project is currently a work-in-progress. Only the fish shell is supported a
- Command Memory/Env Support - Command Memory/Env Support
- Double wh does an la, not ls - Double wh does an la, not ls
- Git Repo detection for ls - Git Repo detection for ls
- Dynamic handler selection (e.g. exa vs ls)
- Clipboard functionality - Clipboard functionality
- sudo vim
- Active Mode

View File

@ -1,9 +1,10 @@
import sys import sys
import os import os
import subprocess import subprocess
import configparser
# supported values: fish, bash # supported values: fish, bash
shell="bash" shell="fish"
print_file="cat" print_file="cat"
pretty_print_file="less -R" pretty_print_file="less -R"
@ -25,12 +26,45 @@ def is_binary_file(filepathname):
else: else:
return False return False
def env_has(program):
whichcall = subprocess.Popen(['which', program], stdout=subprocess.PIPE)
return whichcall.returncode
def file_len(fname): def file_len(fname):
with open(fname) as f: with open(fname) as f:
for i, l in enumerate(f): for i, l in enumerate(f):
pass pass
return i + 1 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 ): if ( len(sys.argv) == 1 ):
# list the contents of the current directory # list the contents of the current directory
print(list_directory) print(list_directory)

5
what.config Normal file
View File

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