mirror of
				https://github.com/ItsDrike/dotfiles.git
				synced 2025-11-04 01:16:35 +00:00 
			
		
		
		
	Home directory cleanup, backups, vim config
This commit is contained in:
		
							parent
							
								
									f194e71dda
								
							
						
					
					
						commit
						b5a357f57b
					
				
					 7 changed files with 101 additions and 60 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
# Contains wakatime API which should remain private
 | 
					# Contains wakatime API which should remain private
 | 
				
			||||||
files/.wakatime.cfg
 | 
					files/.wakatime.cfg
 | 
				
			||||||
# Backup directory will get created by script, no need to push it
 | 
					# Backup directory will get created by script, no need to push it
 | 
				
			||||||
backup/
 | 
					Backups/
 | 
				
			||||||
# Don't include file backups
 | 
					# Don't include file backups
 | 
				
			||||||
*.bak
 | 
					*.bak
 | 
				
			||||||
# todo list
 | 
					# todo list
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,22 @@
 | 
				
			||||||
from lib import Input, Print, Install, Path
 | 
					from lib import Input, Print, Install, Path
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					from datetime import datetime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def make_backup(files_dir):
 | 
				
			||||||
def make_backup(backup_floder):
 | 
					 | 
				
			||||||
    if Input.yes_no('Do you wish to create a backup of current state of your dotfiles?'):
 | 
					    if Input.yes_no('Do you wish to create a backup of current state of your dotfiles?'):
 | 
				
			||||||
        Print.action('Creating dotfiles backup')
 | 
					        Print.action('Creating dotfiles backup')
 | 
				
			||||||
        Print.err('Backup is not yet implemented')
 | 
					        backup_dir = str(datetime.now()).replace(' ', '--')
 | 
				
			||||||
        # TODO: Create backup
 | 
					        current_backup_dir = os.path.join(Path.get_parent(__file__), 'Backups', backup_dir)
 | 
				
			||||||
 | 
					        Path.ensure_dirs(current_backup_dir)
 | 
				
			||||||
 | 
					        for file in Path.get_all_files(files_dir):
 | 
				
			||||||
 | 
					            from_pos = os.path.join(
 | 
				
			||||||
 | 
					            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):
 | 
				
			||||||
 | 
					                Path.copy(from_pos, to_pos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Print.action('Backup complete')
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        Print.warning('Proceeding without backup')
 | 
					        Print.warning('Proceeding without backup')
 | 
				
			||||||
| 
						 | 
					@ -59,8 +69,16 @@ def init(symlink):
 | 
				
			||||||
        Path.get_parent(__file__), 'files')
 | 
					        Path.get_parent(__file__), 'files')
 | 
				
			||||||
    # Create optional backup
 | 
					    # Create optional backup
 | 
				
			||||||
    make_backup(files_dir)
 | 
					    make_backup(files_dir)
 | 
				
			||||||
 | 
					    files_list, dirs_list = Path.get_all_dirs_and_files(files_dir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Create all dirs
 | 
				
			||||||
 | 
					    for directory in dirs_list:
 | 
				
			||||||
 | 
					        position = os.path.join(
 | 
				
			||||||
 | 
					            Path.get_home(), directory.replace(f'{files_dir}/', ''))
 | 
				
			||||||
 | 
					        Path.ensure_dirs(position)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Go through all files
 | 
					    # Go through all files
 | 
				
			||||||
    for file in Path.get_all_files(files_dir):
 | 
					    for file in files_list:
 | 
				
			||||||
        # Make personalized changes to files
 | 
					        # Make personalized changes to files
 | 
				
			||||||
        personalized_changes(file)
 | 
					        personalized_changes(file)
 | 
				
			||||||
        # Set symlink position ($HOME/filepath)
 | 
					        # Set symlink position ($HOME/filepath)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@ alias py2='python2'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Config access shortcuts
 | 
					# Config access shortcuts
 | 
				
			||||||
alias cfvim='vim ~/.vimrc'
 | 
					alias cfvim='vim ~/.vimrc'
 | 
				
			||||||
alias cfzsh='vim ~/config/zsh/.zsh_config'
 | 
					alias cfzsh='vim ~/.config/zsh/.zsh_config'
 | 
				
			||||||
alias cfzshrc='vim ~/.zshrc'
 | 
					alias cfzshrc='vim ~/.zshrc'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Replacements
 | 
					# Replacements
 | 
				
			||||||
| 
						 | 
					@ -54,6 +54,9 @@ alias tty-clock='tty-clock -Ssc' # Terminal clock screensaver
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Custom aliases
 | 
					# Custom aliases
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					alias nvidia='__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia' # Run app with nvidia (on hybrid mode with optimus)
 | 
				
			||||||
alias fhere='find . -name' # Find file/dir from currrent dir
 | 
					alias fhere='find . -name' # Find file/dir from currrent dir
 | 
				
			||||||
alias ssh-list='ss | grep ssh' # List all SSH connections
 | 
					alias ssh-list='ss | grep ssh' # List all SSH connections
 | 
				
			||||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
 | 
					alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
 | 
				
			||||||
| 
						 | 
					@ -72,7 +75,8 @@ alias pacman-extract='pacman -Syw --cachedir .' # Extract package/es into curren
 | 
				
			||||||
alias mount-table='df' # Show list of all mounted devices and their mount locations
 | 
					alias mount-table='df' # Show list of all mounted devices and their mount locations
 | 
				
			||||||
alias swapout='sudo swapoff -a; sudo swapon -a' # Reset swap (move everything to RAM)
 | 
					alias swapout='sudo swapoff -a; sudo swapon -a' # Reset swap (move everything to RAM)
 | 
				
			||||||
alias sound_control='alsamixer' # Sound control tool in alsa_utils package
 | 
					alias sound_control='alsamixer' # Sound control tool in alsa_utils package
 | 
				
			||||||
 | 
					alias md-to-pdf='pandoc -s -o' # Convert markdown to pdf
 | 
				
			||||||
 | 
					alias pdf-reader='mupdf' # Open pdf file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# If user is not root, pass all commands via sudo
 | 
					# If user is not root, pass all commands via sudo
 | 
				
			||||||
if [ $UID -ne 0 ]; then
 | 
					if [ $UID -ne 0 ]; then
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,19 +0,0 @@
 | 
				
			||||||
# Enable colors
 | 
					 | 
				
			||||||
autoload -U colors && colors
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Basic auto/tab complete
 | 
					 | 
				
			||||||
autoload -U compinit
 | 
					 | 
				
			||||||
zstyle ':completion:*' menu select
 | 
					 | 
				
			||||||
zmodload zsh/complist
 | 
					 | 
				
			||||||
compinit
 | 
					 | 
				
			||||||
_comp_options+=(globdots)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Setup aliases
 | 
					 | 
				
			||||||
if [ -f ~/.config/sh/.aliases ]; then
 | 
					 | 
				
			||||||
	source ~/.config/sh/.aliases
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Load zsh-syntax-highlighting (should be last)
 | 
					 | 
				
			||||||
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
 | 
					 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,12 @@ set laststatus=2				" Always show status line
 | 
				
			||||||
set wildmode=longest,list,full	" Enable autocompletion
 | 
					set wildmode=longest,list,full	" Enable autocompletion
 | 
				
			||||||
set splitbelow splitright		" Split in more natural way
 | 
					set splitbelow splitright		" Split in more natural way
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					" SET VIM Locations
 | 
				
			||||||
 | 
					set undodir=$XDG_DATA_HOME/vim/undo
 | 
				
			||||||
 | 
					set directory=$XDG_DATA_HOME/vim/swap
 | 
				
			||||||
 | 
					set backupdir=$XDG_DATA_HOME/vim/backup
 | 
				
			||||||
 | 
					set viminfo+='1000,n$XDG_DATA_HOME/vim/viminfo
 | 
				
			||||||
 | 
					set runtimepath=$XDG_CONFIG_HOME/vim,$VIMRUNTIME,$XDG_CONFIG_HOME/vim/after
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"set nomodeline     " Disable as a security precaution
 | 
					"set nomodeline     " Disable as a security precaution
 | 
				
			||||||
"set wildmenu       " Enable wildmenu
 | 
					"set wildmenu       " Enable wildmenu
 | 
				
			||||||
							
								
								
									
										55
									
								
								files/.zshrc
									
										
									
									
									
								
							
							
						
						
									
										55
									
								
								files/.zshrc
									
										
									
									
									
								
							| 
						 | 
					@ -1,17 +1,19 @@
 | 
				
			||||||
#save_aliases=$(alias -L)
 | 
					ZSH_CACHE="$HOME/.cache/zsh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# History in cache directory
 | 
					# History in cache directory
 | 
				
			||||||
HISTSIZE=10000
 | 
					HISTSIZE=10000
 | 
				
			||||||
SAVEHIST=10000
 | 
					SAVEHIST=10000
 | 
				
			||||||
HISTFILE=~/.cache/zsh/history
 | 
					HISTFILE=$ZSH_CACHE/history
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Move .zsh-update to $ZSH_CACHE
 | 
				
			||||||
 | 
					[ -f ~/.zsh-update ] && mv ~/.zsh-update $ZSH_CACHE/.zsh-update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Export oh-my-zsh location as $ZSH
 | 
					# Export oh-my-zsh location as $ZSH
 | 
				
			||||||
export ZSH="$HOME/.config/oh-my-zsh"
 | 
					 export ZSH="/usr/share/oh-my-zsh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Set theme
 | 
					# Set theme
 | 
				
			||||||
#ZSH_THEME="agnoster"
 | 
					 | 
				
			||||||
#ZSH_THEME="bira"
 | 
					 | 
				
			||||||
#ZSH_THEME="gnzh"
 | 
					 | 
				
			||||||
#ZSH_THEME="rkj-repos"i
 | 
					 | 
				
			||||||
ZSH_THEME="af-magic"
 | 
					ZSH_THEME="af-magic"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# How often should zsh be updated
 | 
					# How often should zsh be updated
 | 
				
			||||||
| 
						 | 
					@ -23,18 +25,33 @@ ENABLE_CORRECTION="false"
 | 
				
			||||||
# Run oh-my-zsh
 | 
					# Run oh-my-zsh
 | 
				
			||||||
source $ZSH/oh-my-zsh.sh
 | 
					source $ZSH/oh-my-zsh.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Load plugins
 | 
					 | 
				
			||||||
plugins=(
 | 
					 | 
				
			||||||
	git
 | 
					 | 
				
			||||||
	python
 | 
					 | 
				
			||||||
	pylint
 | 
					 | 
				
			||||||
	pyenv
 | 
					 | 
				
			||||||
	autopep8
 | 
					 | 
				
			||||||
	zsh-autosuggestions
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ -f "$HOME/.config/sh/zsh/.zsh_config" ]; then
 | 
					# Enable colors
 | 
				
			||||||
	source "$HOME/.config/sh/zsh/.zsh_config"
 | 
					autoload -U colors && colors
 | 
				
			||||||
fi
 | 
					
 | 
				
			||||||
 | 
					# Basic auto/tab complete
 | 
				
			||||||
 | 
					autoload -U compinit
 | 
				
			||||||
 | 
					zstyle ':completion:*' menu select
 | 
				
			||||||
 | 
					zmodload zsh/complist
 | 
				
			||||||
 | 
					compinit
 | 
				
			||||||
 | 
					_comp_options+=(globdots)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Setup aliases
 | 
				
			||||||
 | 
					[ -f ~/.config/sh/.aliases ] && source ~/.config/sh/.aliases
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# XDG Exports
 | 
				
			||||||
 | 
					export XDG_CONFIG_HOME="$HOME/.config"
 | 
				
			||||||
 | 
					export XDG_CACHE_HOME="$HOME/.cache"
 | 
				
			||||||
 | 
					export XDG_DATA_HOME="$HOME/.local/share"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# ~/ Clean-up
 | 
				
			||||||
 | 
					export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority" # Might break some DMs
 | 
				
			||||||
 | 
					export WGETRC="$HOME/.config/wget/wgetrc"
 | 
				
			||||||
 | 
					export LESSHISTFILE="-"
 | 
				
			||||||
 | 
					export VIMINIT=":source $XDG_CONFIG_HOME"/vim/vimrc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Load zsh-syntax-highlighting (should be last)
 | 
				
			||||||
 | 
					source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#neofetch --cpu_temp C --gtk2 off --gtk3 off --color_blocks on --pixterm
 | 
					#neofetch --cpu_temp C --gtk2 off --gtk3 off --color_blocks on --pixterm
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										43
									
								
								lib.py
									
										
									
									
									
								
							
							
						
						
									
										43
									
								
								lib.py
									
										
									
									
									
								
							| 
						 | 
					@ -381,6 +381,8 @@ class Path:
 | 
				
			||||||
        Returns:
 | 
					        Returns:
 | 
				
			||||||
            bool -- One of dirs exists/Single dir exists
 | 
					            bool -- One of dirs exists/Single dir exists
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
 | 
					        if type(paths) != str:
 | 
				
			||||||
 | 
					            paths = str(paths)
 | 
				
			||||||
        paths = paths.split(' ')
 | 
					        paths = paths.split(' ')
 | 
				
			||||||
        for dir_path in paths:
 | 
					        for dir_path in paths:
 | 
				
			||||||
            dir_path = os.path.expanduser(dir_path)
 | 
					            dir_path = os.path.expanduser(dir_path)
 | 
				
			||||||
| 
						 | 
					@ -416,7 +418,25 @@ class Path:
 | 
				
			||||||
                files_found.append(os.path.join(subdir, file))
 | 
					                files_found.append(os.path.join(subdir, file))
 | 
				
			||||||
        return files_found
 | 
					        return files_found
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def ensure_dirs(path, file_end=False, absolute_path=True):
 | 
					    def get_all_dirs_and_files(dir_path):
 | 
				
			||||||
 | 
					        '''Get list of all files and directories in specified directory (recursive)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Arguments:
 | 
				
			||||||
 | 
					            dir_path {str/Path} -- path to starting directory
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Returns:
 | 
				
			||||||
 | 
					            list, list-- files, dirs found
 | 
				
			||||||
 | 
					        '''
 | 
				
			||||||
 | 
					        files_found = []
 | 
				
			||||||
 | 
					        dirs_found = []
 | 
				
			||||||
 | 
					        for subdir, dirs, files in os.walk(dir_path):
 | 
				
			||||||
 | 
					            for file in files:
 | 
				
			||||||
 | 
					                files_found.append(os.path.join(subdir, file))
 | 
				
			||||||
 | 
					            for directory in dirs:
 | 
				
			||||||
 | 
					                dirs_found.append(os.path.join(subdir, directory))
 | 
				
			||||||
 | 
					        return files_found, dirs_found
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def ensure_dirs(path, absolute_path=True):
 | 
				
			||||||
        '''Ensure existence of directories (usually before creating files in it)
 | 
					        '''Ensure existence of directories (usually before creating files in it)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Arguments:
 | 
					        Arguments:
 | 
				
			||||||
| 
						 | 
					@ -428,17 +448,12 @@ class Path:
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
        if not absolute_path:
 | 
					        if not absolute_path:
 | 
				
			||||||
            path = pathlib.Path(path).absolute()
 | 
					            path = pathlib.Path(path).absolute()
 | 
				
			||||||
        parts = pathlib.Path(path).parts
 | 
					        if os.path.isfile(path):
 | 
				
			||||||
        if file_end:
 | 
					            path = Path.get_parent(path)
 | 
				
			||||||
            parts = parts[:-1]
 | 
					
 | 
				
			||||||
        cur_path = '/'
 | 
					        if not Path.check_dir_exists(path):
 | 
				
			||||||
        # ignore first element (it is root (/), which was specified earlier)
 | 
					            Command.execute(f'mkdir -p {path}')
 | 
				
			||||||
        parts = parts[1:]
 | 
					            Print.comment(f'Creating directory {path}')
 | 
				
			||||||
        for part in parts:
 | 
					 | 
				
			||||||
            cur_path = os.path.join(cur_path, part)
 | 
					 | 
				
			||||||
            if not Path.check_dir_exists(cur_path):
 | 
					 | 
				
			||||||
                Print.comment(f'Creating directory {cur_path}')
 | 
					 | 
				
			||||||
                os.mkdir(cur_path)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_home():
 | 
					    def get_home():
 | 
				
			||||||
        '''Get home path
 | 
					        '''Get home path
 | 
				
			||||||
| 
						 | 
					@ -455,7 +470,7 @@ class Path:
 | 
				
			||||||
            symlink_pointer {str} -- path where symlink should be pointing
 | 
					            symlink_pointer {str} -- path where symlink should be pointing
 | 
				
			||||||
            path {str} -- path in which the symlink should be created
 | 
					            path {str} -- path in which the symlink should be created
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
        Path.ensure_dirs(path, file_end=True)
 | 
					        Path.ensure_dirs(path)
 | 
				
			||||||
        Command.execute(f'ln -sf {symlink_pointer} {path}')
 | 
					        Command.execute(f'ln -sf {symlink_pointer} {path}')
 | 
				
			||||||
        Print.comment(f'Created symlink: {path} -> {symlink_pointer}')
 | 
					        Print.comment(f'Created symlink: {path} -> {symlink_pointer}')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -466,6 +481,6 @@ class Path:
 | 
				
			||||||
            path {str} -- path to original file
 | 
					            path {str} -- path to original file
 | 
				
			||||||
            copied_path {str} -- path to new file
 | 
					            copied_path {str} -- path to new file
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
        Path.ensure_dirs(copied_path, file_end=True)
 | 
					        Path.ensure_dirs(copied_path)
 | 
				
			||||||
        Command.execute(f'cp {path} {copied_path}')
 | 
					        Command.execute(f'cp {path} {copied_path}')
 | 
				
			||||||
        Print.comment(f'Copied {path} to {copied_path}')
 | 
					        Print.comment(f'Copied {path} to {copied_path}')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue