fix bug and add linux-custom-rc.zsh
This commit is contained in:
parent
961dfe65ef
commit
9900ce304b
71
sync.py
71
sync.py
@ -1,4 +1,3 @@
|
|||||||
from turtle import back
|
|
||||||
from typing import Callable, Iterable, TypeVar
|
from typing import Callable, Iterable, TypeVar
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from math import nan
|
from math import nan
|
||||||
@ -77,29 +76,33 @@ class BackupItem:
|
|||||||
|
|
||||||
def execute_sync (backupItem: BackupItem) -> None:
|
def execute_sync (backupItem: BackupItem) -> None:
|
||||||
print(f">>> executing backup for {backupItem.name}")
|
print(f">>> executing backup for {backupItem.name}")
|
||||||
all_files_tmp: list[str] = []
|
exec_gallery: list[Callable] = []
|
||||||
### for file mode
|
### for file mode
|
||||||
if (path.isfile(backupItem.origin_dir)) or (path.isfile(backupItem.backup_dir)):
|
if (path.isfile(backupItem.origin_dir)) or (path.isfile(backupItem.backup_dir)):
|
||||||
compare_file(backupItem, None)
|
exec_gallery.append(compare_file(backupItem, None))
|
||||||
### for dir mode
|
### for dir mode
|
||||||
def walk_dir (walking_dir: str):
|
else:
|
||||||
for root, dirs, files in os.walk(walking_dir):
|
all_files_tmp: list[str] = []
|
||||||
common_root: str = path.commonpath([root, walking_dir])
|
def walk_dir (walking_dir: str):
|
||||||
if common_root == walking_dir:
|
for root, dirs, files in os.walk(walking_dir):
|
||||||
relative_root: str = root[len(walking_dir):]
|
common_root: str = path.commonpath([root, walking_dir])
|
||||||
else:
|
if common_root == walking_dir:
|
||||||
print(f"WARN: cannot find common root for {root} and {walking_dir}, will break this dir.")
|
relative_root: str = root[len(walking_dir):]
|
||||||
continue
|
else:
|
||||||
for file in files:
|
print(f"WARN: cannot find common root for {root} and {walking_dir}, will break this dir.")
|
||||||
relative_file_path = de_abs_path(path.join(relative_root, file))
|
continue
|
||||||
# print(f"find file in source: {`relative_file_path`}")
|
for file in files:
|
||||||
all_files_tmp.append(relative_file_path)
|
relative_file_path = de_abs_path(path.join(relative_root, file))
|
||||||
walk_dir(backupItem.origin_dir)
|
# print(f"find file in source: {`relative_file_path`}")
|
||||||
walk_dir(backupItem.backup_dir)
|
all_files_tmp.append(relative_file_path)
|
||||||
all_files: list[str] = sorted_paths(set(all_files_tmp))
|
walk_dir(backupItem.origin_dir)
|
||||||
exec_gallery: list[Callable] = []
|
walk_dir(backupItem.backup_dir)
|
||||||
for file in all_files:
|
all_files: list[str] = sorted_paths(set(all_files_tmp))
|
||||||
exec_gallery.append(compare_file(backupItem, file))
|
for file in all_files:
|
||||||
|
exec_gallery.append(compare_file(backupItem, file))
|
||||||
|
if exec_gallery.__len__() == 0:
|
||||||
|
print("no files to sync ~")
|
||||||
|
return
|
||||||
while True:
|
while True:
|
||||||
print("! sync those files now? [y/n] ", end="")
|
print("! sync those files now? [y/n] ", end="")
|
||||||
_in = input()
|
_in = input()
|
||||||
@ -109,8 +112,6 @@ def execute_sync (backupItem: BackupItem) -> None:
|
|||||||
return
|
return
|
||||||
elif _in == 'n':
|
elif _in == 'n':
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
print("! sync those files now? [y/n] ", end="")
|
|
||||||
|
|
||||||
def compare_file (rootBackItem: BackupItem, relative_file_path: str|None) -> Callable:
|
def compare_file (rootBackItem: BackupItem, relative_file_path: str|None) -> Callable:
|
||||||
class NewerStatus (Enum):
|
class NewerStatus (Enum):
|
||||||
@ -164,19 +165,16 @@ def compare_file (rootBackItem: BackupItem, relative_file_path: str|None) -> Cal
|
|||||||
# print(f"((origin_item: {origin_item.path}))")
|
# print(f"((origin_item: {origin_item.path}))")
|
||||||
def wait_for_if_remove (onSync = Callable, onRemove = Callable) -> Callable[[str], Callable|None]:
|
def wait_for_if_remove (onSync = Callable, onRemove = Callable) -> Callable[[str], Callable|None]:
|
||||||
def implementation (_in: str) -> Callable|None:
|
def implementation (_in: str) -> Callable|None:
|
||||||
|
match _in:
|
||||||
while True:
|
case "s":
|
||||||
_in = input()
|
return onSync
|
||||||
match _in:
|
case "r":
|
||||||
case "s":
|
return onRemove
|
||||||
return onSync
|
case "i":
|
||||||
case "r":
|
return lambda: None
|
||||||
return onRemove
|
case _:
|
||||||
case "i":
|
print("sync or remove? [s=sync/r=remove/i=ignore] ", end="")
|
||||||
return lambda: None
|
return None
|
||||||
case _:
|
|
||||||
print("sync or remove? [s=sync/r=remove/i=ignore] ", end="")
|
|
||||||
return None
|
|
||||||
return implementation
|
return implementation
|
||||||
match FileSameCheck(origin_item, backup_item):
|
match FileSameCheck(origin_item, backup_item):
|
||||||
case NewerStatus.SAME:
|
case NewerStatus.SAME:
|
||||||
@ -250,6 +248,7 @@ else:
|
|||||||
sys_type: SysType = SysType.WINDOWS
|
sys_type: SysType = SysType.WINDOWS
|
||||||
print(f"dot-config: your dot-config path is {backup_root}")
|
print(f"dot-config: your dot-config path is {backup_root}")
|
||||||
print(f"dot-config: your system type is {sys_type}")
|
print(f"dot-config: your system type is {sys_type}")
|
||||||
|
print(f"dot-config: dry run mode is {dry_run}")
|
||||||
print(f"Is all the information correct? [y/n] ", end="")
|
print(f"Is all the information correct? [y/n] ", end="")
|
||||||
while True:
|
while True:
|
||||||
_in = input()
|
_in = input()
|
||||||
|
22
zsh/linux.custom_rc.zsh
Normal file
22
zsh/linux.custom_rc.zsh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
#=== bat (cat)
|
||||||
|
alias cat='bat'
|
||||||
|
#=== lsd
|
||||||
|
alias cols='lsd'
|
||||||
|
alias crls='cols'
|
||||||
|
alias ccls='crls -g'
|
||||||
|
alias cl='ccls -lA'
|
||||||
|
alias cll='ccls -l'
|
||||||
|
alias cla='ccls -la'
|
||||||
|
alias lc='ccls'
|
||||||
|
alias ls='lc'
|
||||||
|
alias l='cl'
|
||||||
|
alias ll='cll'
|
||||||
|
alias la='cla'
|
||||||
|
alias lgg='ccls --tree'
|
||||||
|
|
||||||
|
#=== zoxide (cd)
|
||||||
|
# zoxide must init after compinit is called
|
||||||
|
eval "$(zoxide init zsh)"
|
||||||
|
alias cd='z'
|
Loading…
Reference in New Issue
Block a user