diff --git a/dotfiles_install.py b/dotfiles_install.py index 7ce12b2..ef13872 100644 --- a/dotfiles_install.py +++ b/dotfiles_install.py @@ -13,7 +13,7 @@ def make_backup(files_dir): Path.get_home(), file.replace(f'{files_dir}/', '')) to_pos = os.path.join( current_backup_dir, file.replace(f'{files_dir}/', '')) - if os.path.isfile(from_pos): + if Path.check_file_exists(from_pos): Path.copy(from_pos, to_pos) Print.action('Backup complete') @@ -29,7 +29,12 @@ def check_installation(): Print.err('Dotfiles installation cancelled - zsh not installed') return False - global oh_my_zsh_path + global oh_my_zsh_path, zsh_highlight_path + + zsh_highlight_path = None + if Path.check_file_exists('/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh'): + zsh_highlight_path = '/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' + oh_my_zsh_path = None if Path.check_dir_exists('~/.oh-my-zsh'): oh_my_zsh_path = '$HOME/.oh-my-zsh' @@ -50,18 +55,43 @@ def check_installation(): return False + def personalized_changes(file): if '.zshrc' in file: + global oh_my_zsh_path, zsh_highlight_path filedata = None with open(file, 'r') as f: filedata = f.read() filedata_old = filedata + + # Change path to oh-my-zsh filedata = filedata.replace('"$HOME/.config/oh-my-zsh"', f'"{oh_my_zsh_path}"') + + # Change path to zsh-color-highlight + if zsh_highlight_path is not None: + original_path='/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' + filedata = filedata.replace(f'source {original_path}', f'source {zsh_highlight_path}') + else: + if Install.package('zsh-syntax-highlighting', 'default'): + zsh_highlight_path = Input.question('Please specify path to your zsh-syntax-highlighting plugin (blank=do not include)') + if zsh_highlight_path != '': + filedata = filedata.replace(f'source {original_path}', f'source {zsh_highlight_path}') + else: + filedata = filedata.replace(f'source {original_path}', f'') + else: + filedata = filedata.replace(f'source {original_path}', f'') + if filedata_old != filedata: Print.commend('Changing oh-my-zsh location in .zshrc') with open(file, 'w') as f: f.write(filedata) + if 'vimrc' in file: + if not Input.yes_no('Do you wish to use .vimrc (If you choose yes, please install Vundle or you will get errors)'): + # TODO: Install vundle + return False + return True + def init(symlink): # Get path to files/ floder (contains all dotfiles) diff --git a/lib.py b/lib.py index 8d679a4..2fe09b6 100644 --- a/lib.py +++ b/lib.py @@ -202,6 +202,9 @@ class Input: else: return False + def question(text): + Print.question(text) + return input(' >>') class Install: @@ -296,11 +299,13 @@ class Install: return True else: Print.cancel('Skipping...') + return False else: Print.cancel( f'assuming {repository} already installed ({repository} is installed)') + return True - def package(package_name, install_text='default', use_yay=False, reinstall=False): + def package(package_name, install_text='default', aur=False, reinstall=False): '''Installation of package Arguments: @@ -314,16 +319,16 @@ class Install: Returns: bool -- installed ''' - if use_yay: + if aur: if Install.check_not_installed('yay'): - Print.warning( - f'Unable to install AUR package: {package_name}, yay is not installed') - return False + Print.cancel( + f'Unable to install with yay (not installed), installing AUR package: {package_name} with git instead') + Install.git_aur(package_name, install_text) if Install.check_not_installed(package_name) or reinstall: install_text = Install._generate_install_text( - install_text, package_name, yay=use_yay) + install_text, package_name, yay=aur) if Input.yes_no(install_text): - if use_yay: + if aur: Command.execute(f'yay -S {package_name}') else: Command.execute(f'sudo pacman -S {package_name}') @@ -333,7 +338,7 @@ class Install: return False else: Print.cancel(f'{package_name} already installed') - return False + return True def multiple_packages(packages, install_text, options=False, reinstall=False): '''Installation of multiple packages @@ -392,6 +397,26 @@ class Path: else: return False + def check_file_exists(paths): + '''Check for file/s existence + + Arguments: + paths {str} -- single path or multiple paths separated by spaces (absolute paths) + + Returns: + bool -- One of files exists/Single file exists + ''' + if type(paths) != str: + paths = str(paths) + paths = paths.split(' ') + for file_path in paths: + file_path = os.path.expanduser(file_path) + if os.path.isfile(file_path): + return True + break + else: + return False + def get_parent(file_path): '''Get Parent directory of specified file @@ -448,7 +473,7 @@ class Path: ''' if not absolute_path: path = pathlib.Path(path).absolute() - if os.path.isfile(path): + if Path.check_file_exists(path): path = Path.get_parent(path) if not Path.check_dir_exists(path): diff --git a/package_install.py b/package_install.py index 18c48c5..552d494 100644 --- a/package_install.py +++ b/package_install.py @@ -10,7 +10,6 @@ def main(): Install.package('networkmanager') Install.package( 'git', 'default + (Required for some installations, otherwise they\'ll be skipped)') - Install.package('zsh', 'default + shell') Install.package('sudo') # Desktop Enviroment @@ -21,23 +20,27 @@ def main(): 'SDDM (KDE)', 'GDM (Gnome)', 'LightDM']) Install.package('base-devel', 'default + (Required for makepkg installs)') - Install.git_aur( - 'yay', 'default + (Required for some installations, otherwise they\'ll be skipped)') + Install.package('yay', 'default', aur=True) + Install.package('vim') Install.package('exa', 'default + (Better ls tool)') + Install.package('zsh', 'default + (Shell)') + Install.package('zsh-syntax-highlighting', 'default') Install.package('terminator', 'default + (advanced terminal)') Install.package('konsole', 'default + (KDE terminal emulator)') Install.package( 'ark', 'default + (Managing various archive formats such as tar, gzip, zip, rar, etc.)') + Install.package('timeshift', 'default + (Backup Tool), aur=True') Install.package('cron', 'default + (Task scheduling)') Install.package('dolphin', 'default + (File Manager)') Install.package('nomacs', 'default + (Photo viewer & editor)') Install.package('discord', 'default + (Chat App)') + Install.package('caprine', 'default + (Unofficial Messenger Chat App)') Install.package( - 'spotify', 'default + (Online Music Player)', use_yay=True) + 'spotify', 'default + (Online Music Player)', aur=True) Install.package( 'spectacle', 'default + (Screenshot tool)') Install.package('qalculate-gtk-nognome', - 'Do you wish to install Qalculate! (Complex Calculator)?', use_yay=True) + 'Do you wish to install Qalculate! (Complex Calculator)?', aur=True) Install.package('gnome-system-monitor', 'Do you wish to install gnome system monitor?') Install.package(