From 061c34b5818f918142dccde91b2382870c2dae3b Mon Sep 17 00:00:00 2001 From: developomp Date: Fri, 3 Jun 2022 23:53:37 +0900 Subject: [PATCH] replace `remove_directory` with `trash` - `trash` moves files and directories to the trash directory instead of permanently deleting them --- src/initialize.py | 1 + src/setup/system/zsh.py | 6 +++--- src/util.py | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/initialize.py b/src/initialize.py index ccd1824..321cea9 100644 --- a/src/initialize.py +++ b/src/initialize.py @@ -21,6 +21,7 @@ def initialize(): Initialize before running any code. """ + install_via_pacman("trash-cli") install_via_pacman("flatpak") install_via_pacman("pip") diff --git a/src/setup/system/zsh.py b/src/setup/system/zsh.py index 846c4fb..affb820 100644 --- a/src/setup/system/zsh.py +++ b/src/setup/system/zsh.py @@ -1,4 +1,4 @@ -from src.util import paru_install, copy_file, remove_directory +from src.util import paru_install, copy_file, trash from src.constants import content_dir, home_dir from src import log @@ -20,7 +20,7 @@ def setup(): log.log("Installing powerlevel10k theme") p10k_path = f"{home_dir}/.oh-my-zsh/custom/themes/powerlevel10k" - remove_directory(p10k_path) + trash(p10k_path) system( f"git clone --depth=1 https://github.com/romkatv/powerlevel10k.git {p10k_path}" ) @@ -29,7 +29,7 @@ def setup(): zsh_syntax_highlighting_path = ( f"{home_dir}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ) - remove_directory(zsh_syntax_highlighting_path) + trash(zsh_syntax_highlighting_path) system( f"git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git {zsh_syntax_highlighting_path}" ) diff --git a/src/util.py b/src/util.py index eb3451d..f3f4ddf 100644 --- a/src/util.py +++ b/src/util.py @@ -47,11 +47,13 @@ def smart_mkdir(path: str): pass -def remove_directory(path): +def trash(path): + """Moves a file or directory to freedesktop trash.""" + try: - system(f"rm -rf {path}") + system(f"trash-put {path}") except Exception as err: - print(f"Failed to remove directory: {path}") + print(f"Failed to remove: {path}") raise err