commit cc07189b1648c45ff24926cf39134d2c7e3ed2fe
parent ba1f9b78521993fb2318e88bb2a73a4b5fff9d2f
Author: gearsix <gearsix@tuta.io>
Date: Mon, 6 Sep 2021 09:23:20 +0000
prompt to install if dotfile does not exist
Also added exception catch if os.remove call fails
Diffstat:
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/dotfm.py b/src/dotfm.py
@@ -5,7 +5,7 @@
#=========================
# authors: gearsix
# created: 2020-01-15
-# updated: 2021-04-22
+# updated: 2021-09-06
#---------
# IMPORTS
@@ -25,7 +25,7 @@ HOME = os.getenv('HOME')
USER = os.getenv('USER')
ARGS = []
EDITOR = os.getenv('EDITOR') or 'nano'
-VERSION = 'v2.2.0'
+VERSION = 'v2.2.1'
INSTALLED = []
INSTALLED_FILE = '/home/{}/.local/share/dotfm/installed.csv'.format(USER)
KNOWN = [ # dotfiles that dotfm knows by default
@@ -183,7 +183,8 @@ def install(dotfile):
os.system('mkdir -vp {}'.format(os.path.dirname(location)))
if os.path.lexists(location):
install_oca(dotfile, location)
- os.system('ln -vs {} {}'.format(dotfile, location))
+ if dotfile != location:
+ os.system('ln -vs {} {}'.format(dotfile, location))
debug('appending to {} installed...'.format(location))
aliases.insert(0, location)
INSTALLED.append(aliases)
@@ -265,7 +266,10 @@ def remove(dotfile):
confirm = ''
while confirm == '':
confirm = ask('remove "{}", are you sure [y/n]?'.format(dotfile))
- os.remove(dotfile)
+ try:
+ os.remove(dotfile)
+ except OSError as err:
+ warn('cannot remove "{}"...\n{}'.format(dotfile, err))
del INSTALLED[index]
writeinstalled()
@@ -274,12 +278,30 @@ def edit(dotfile):
debug('editing {}'.format(dotfile))
index = isdotfile(INSTALLED, dotfile)
if index == -1:
- warn('could not find installed dotfile matching "{}"'.format(dotfile))
- return
+ if edit_promptinstall(dotfile) == 'y':
+ index = isdotfile(INSTALLED, dotfile)
+ else:
+ return
target = INSTALLED[index][0]
os.system('{} {}'.format(EDITOR, target))
info('You might need to re-open the terminal, or re-execute the relevant dotfile')
+def edit_promptinstall(dotfile):
+ yn = '-'
+ while yn[0] != 'y' and yn[0] != 'n':
+ yn = ask('could not find installed dotfile matching "{}", install [y/n]? '.format(dotfile))
+ if len(yn) == 0:
+ yn = '-'
+ if yn[0] == 'y':
+ location = ask('input source filepath: ')
+ if len(location) == 0:
+ location = '/home/{}/.{}'.format(USER, dotfile)
+ log('setting location to "{}"'.format(location))
+ f = open(location, 'w')
+ f.close()
+ install(location)
+ return yn[0]
+
# main/list
def list(dotfiles):
debug('listing dotfiles: {}'.format(dotfiles))