From 7de29c4333d88ac3ecd971e2ebf548d91cb5373a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 14:05:36 +0300 Subject: [PATCH 01/32] Remove setup_file, add deploy_list.json --- dotman.py | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/dotman.py b/dotman.py index 0a8c6cd..d902f77 100755 --- a/dotman.py +++ b/dotman.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Ferit Yiğit BALABAN , 2022 +# Ferit Yiğit BALABAN , 2023 # import os.path from subprocess import run @@ -11,16 +11,17 @@ from termcolor import colored, cprint # Modify SETTINGS dictionary to set runtime variables # Access values in dictionary using pre-defined names SETTINGS = { - 'DOTFILES_REPOSITORY': '$HOME/repos/dotfiles', - 'REMOTE_REPOSITORY': 'https://github.com/fybx/dotfiles', - 'LOCAL_CONFIG': '$HOME/.config', - 'SETUP_FILE': 'same-directory' + 'URL_REPO': 'https://github.com/fybx/dotfiles', + 'DIR_REPO': '$HOME/repos/dotfiles', + 'DIR_CONF': '$HOME/.config', + 'F_DEPLOY': '$HOME/.config/dotman/deploy_list.json', } + WHEREAMI = '$HOME/scripts' -VER = 'v1.7' +VER = 'v1.8' WER = 'v1.1' help_message = f''' -dotman {VER} dotfiles manager by fyb +dotman {VER} dotfiles manager by ferityigitbalaban Unrecognized keys are ignored. If every key supplied is unrecognized, this have the same effect as calling dotman without any key. @@ -35,6 +36,10 @@ Keys: ''' +DL_FILES = [] +DL_DIRS = [] + + def get_nth_key(n: int, d: dict[str, str]): c = 0 for k in d.keys(): @@ -50,18 +55,25 @@ def read_file(path: str): return content -def read_setup(): - path = SETTINGS['SETUP_FILE'] - lines = read_file(f'{WHEREAMI}setup.dtm') if path == 'same-directory' else read_file(os.path.expandvars(path)) - lines = [line.strip() for line in lines if not line.startswith('#') and line.replace(' ', '') != ''] - for line in lines: - key = line.split(':', 1)[0].rstrip() - value = line.split(':', 1)[1].lstrip() - SETTINGS[key] = value +def read_deploy_list(): + """ + Reads file from SETTINGS.F_DEPLOY to get list of directories and files to deploy + """ + path_deploy_list = SETTINGS['F_DEPLOY'] + if os.path.exists(path_deploy_list): + with open(path_deploy_list, 'r') as f: + file = f.read() + f.close() + dict_deploy_list = json.loads(file) + DL_FILES = dict_deploy_list['files'] + DL_DIRS = dict_deploy_list['dirs'] -def write_setup(): - path = f'{WHEREAMI}setup.dtm' if SETTINGS['SETUP_FILE'] == 'same-directory' else os.path.expandvars(SETTINGS['SETUP_FILE']) +def create_deploy_list(): + """ + Creates the default deploy_list.json in path SETTINGS.F_DEPLOY + """ + default = {} def rrem(text: str, char: str): From 1a5570664e20c20b9a889e73c05054aa5f26095e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 14:10:48 +0300 Subject: [PATCH 02/32] Add method create_deploy_list --- dotman.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dotman.py b/dotman.py index d902f77..4c98060 100755 --- a/dotman.py +++ b/dotman.py @@ -67,13 +67,21 @@ def read_deploy_list(): dict_deploy_list = json.loads(file) DL_FILES = dict_deploy_list['files'] DL_DIRS = dict_deploy_list['dirs'] + else: + create_deploy_list() def create_deploy_list(): """ Creates the default deploy_list.json in path SETTINGS.F_DEPLOY """ - default = {} + dl_default = { + "files": [], + "dirs": ["dotman"], + } + with open(SETTINGS['F_DEPLOY'], 'w') as f: + f.write(json.dumps(dl_default, indent = 4)) + f.close() def rrem(text: str, char: str): From d29ac4616804af9d479995d28c813d7861e5f42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 14:21:04 +0300 Subject: [PATCH 03/32] + method expand_settings, key SETTINGS.SHN_REPO --- dotman.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/dotman.py b/dotman.py index 4c98060..6b35f49 100755 --- a/dotman.py +++ b/dotman.py @@ -11,10 +11,11 @@ from termcolor import colored, cprint # Modify SETTINGS dictionary to set runtime variables # Access values in dictionary using pre-defined names SETTINGS = { - 'URL_REPO': 'https://github.com/fybx/dotfiles', - 'DIR_REPO': '$HOME/repos/dotfiles', - 'DIR_CONF': '$HOME/.config', - 'F_DEPLOY': '$HOME/.config/dotman/deploy_list.json', + 'URL_REPO': 'https://github.com/fybx/dotfiles', # remote repository URL + 'SHN_REPO': 'fybx/dotfiles' # remote shortname + 'DIR_REPO': '$HOME/repos/dotfiles', # local repository directory + 'DIR_CONF': '$HOME/.config', # local .config directory + 'F_DEPLOY': '$HOME/.config/dotman/deploy_list.json', # path to deploy_list.json file } WHEREAMI = '$HOME/scripts' @@ -172,16 +173,21 @@ def commit_then_push(): return 0, None if code == 0 else 2, None return 1, None +def expand_settings(): + """ + Expands variables used in SETTINGS + """ + SETTINGS['DIR_REPO'] = os.path.expandvars(SETTINGS['DIR_REPO']) + SETTINGS['DIR_CONF'] = os.path.expandvars(SETTINGS['DIR_CONF']) + SETTINGS['F_DEPLOY'] = os.path.expandvars(SETTINGS['F_DEPLOY']) + def main(): global WHEREAMI WHEREAMI = rrem(sys.argv[0], '/') - read_setup() - SETTINGS['DOTFILES_REPOSITORY'] = os.path.expandvars(SETTINGS['DOTFILES_REPOSITORY']) - SETTINGS['LOCAL_CONFIG'] = os.path.expandvars(SETTINGS['LOCAL_CONFIG']) - remote_shortname = SETTINGS['REMOTE_REPOSITORY'].removeprefix("https://github.com/") + expand_settings() - local_repo_exists = os.path.exists(SETTINGS['DOTFILES_REPOSITORY']) + local_repo_exists = os.path.exists(SETTINGS['DIR_REPO']) flag_interactive = False flag_backup = False @@ -204,7 +210,7 @@ def main(): flag_interactive = True if flag_interactive: - print(f"dotman {VER} by fyb, 2022") + print(f"dotman {VER} by ferityigitbalaban") if not local_repo_exists: print(colored('Important warning:', 'red'), 'dotfiles repository cannot be located at: ', colored(SETTINGS['DOTFILES_REPOSITORY'], 'yellow')) From d01aeee139c08c2b01f0240ffe7cba6d15f5ea69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 14:27:14 +0300 Subject: [PATCH 04/32] Start rewriting main logic --- dotman.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dotman.py b/dotman.py index 6b35f49..fdf8154 100755 --- a/dotman.py +++ b/dotman.py @@ -187,7 +187,7 @@ def main(): WHEREAMI = rrem(sys.argv[0], '/') expand_settings() - local_repo_exists = os.path.exists(SETTINGS['DIR_REPO']) + exists_dir_repo = os.path.exists(SETTINGS['DIR_REPO']) flag_interactive = False flag_backup = False @@ -209,6 +209,17 @@ def main(): else: flag_interactive = True + if exists_dir_repo: + # local repository directory exists. Backup or deploy is possible. + else: + # local repository directory does not exist. Only deploy is possible. + + + # ^^^ new logic ^^^ + # + # vvv old logic vvv + return + if flag_interactive: print(f"dotman {VER} by ferityigitbalaban") if not local_repo_exists: From c9546beefadafb4761a5816b738faae6df421469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 14:33:39 +0300 Subject: [PATCH 05/32] Map out logic if exists_dir_repo is True --- dotman.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dotman.py b/dotman.py index fdf8154..8106c48 100755 --- a/dotman.py +++ b/dotman.py @@ -211,6 +211,25 @@ def main(): if exists_dir_repo: # local repository directory exists. Backup or deploy is possible. + if flag_interactive: + # if interactive flag was fed, ignore backup and deploy key + # ask user for action (backup or deploy) + ans = input('(B)ackup or (D)eploy is possible, select one: ') + if ans.lower() = 'b': + # interactive backup + elif ans.lower() = 'd': + # interactive deploy + else: + # ask again + else: + # continue according to set flag, XOR + if flag_backup and not flag_deploy: + # backup + elif flag_deploy and not flag_backup: + # deploy + else: + # either both flags are set OR both are unset + # quit script else: # local repository directory does not exist. Only deploy is possible. From 836d79a731a639e84b44044c4591a421afa04980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 14:41:44 +0300 Subject: [PATCH 06/32] Convert logical statement to loop --- dotman.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dotman.py b/dotman.py index 8106c48..61ac593 100755 --- a/dotman.py +++ b/dotman.py @@ -213,14 +213,16 @@ def main(): # local repository directory exists. Backup or deploy is possible. if flag_interactive: # if interactive flag was fed, ignore backup and deploy key - # ask user for action (backup or deploy) - ans = input('(B)ackup or (D)eploy is possible, select one: ') - if ans.lower() = 'b': + # ask user for action (backup or deploy) + while True: + ans = input('(B)ackup or (D)eploy is possible, select one: ').lower() + if ans == 'b' or ans == 'd': + break + if ans = 'b': # interactive backup - elif ans.lower() = 'd': + elif ans = 'd': # interactive deploy - else: - # ask again + else: # continue according to set flag, XOR if flag_backup and not flag_deploy: From 90870ead8d92bd579619da301d0581059f7c4520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 9 Feb 2023 16:30:15 +0300 Subject: [PATCH 07/32] Add logic if local repository dir is not present --- dotman.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dotman.py b/dotman.py index 61ac593..4f13a9f 100755 --- a/dotman.py +++ b/dotman.py @@ -231,9 +231,17 @@ def main(): # deploy else: # either both flags are set OR both are unset - # quit script + exit(0) else: # local repository directory does not exist. Only deploy is possible. + # if interactive, ask for deploy, else if deploy flag is set, deploy, otherwise quit. + if flag_interactive: + # ask for deploy + return + elif flag_deploy: + # deploy + return + quit(0) # ^^^ new logic ^^^ From 1bac6c3f2a42bc262ac95078bc9c56f591b91a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Fri, 10 Feb 2023 22:33:28 +0300 Subject: [PATCH 08/32] Implement no local repository logic --- dotman.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dotman.py b/dotman.py index 4f13a9f..9b58854 100755 --- a/dotman.py +++ b/dotman.py @@ -236,13 +236,14 @@ def main(): # local repository directory does not exist. Only deploy is possible. # if interactive, ask for deploy, else if deploy flag is set, deploy, otherwise quit. if flag_interactive: - # ask for deploy - return - elif flag_deploy: - # deploy - return - quit(0) - + print(f"local repository directory for {SETTINGS.SHN_REPO} does not exist") + print("You can clone and deploy this repository to local config directory") + ans = input("Continue (y/N): ").lower() + if ans == "n" and not ans == "y": + exit(0) + if not flag_interactive and not flag_deploy: + exit(0) + # run deploy # ^^^ new logic ^^^ # From 2d2616febf2f4da20bc9ef2c46bf62fc3c93c537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Fri, 10 Feb 2023 22:38:23 +0300 Subject: [PATCH 09/32] + logic for method deploy() --- dotman.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/dotman.py b/dotman.py index 9b58854..a5b611b 100755 --- a/dotman.py +++ b/dotman.py @@ -173,6 +173,18 @@ def commit_then_push(): return 0, None if code == 0 else 2, None return 1, None + +def deploy(): + """ + Kindly executes the steps to get a up-to-date local repository, + deploy (copy) files and directories to the local config directory. + """ + # if no local repo + # go to ../local_repo and clone remote_url + # go to local_repo and exec git fetch && git pull + # copy files & directories + + def expand_settings(): """ Expands variables used in SETTINGS From 2b6004a7b35d55cbc606a8f62d33b1753a182ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Fri, 10 Feb 2023 22:46:54 +0300 Subject: [PATCH 10/32] + logic for method backup() --- dotman.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dotman.py b/dotman.py index a5b611b..d010b28 100755 --- a/dotman.py +++ b/dotman.py @@ -174,6 +174,23 @@ def commit_then_push(): return 1, None +def backup(): + """ + Aggresively executes the steps to do checksum comparisons between local + config directory and local repository to decide which files to copy, + copy only changed files, commit and push to remote. + """ + # get list of files and directories to change (F_DEPLOY) + # get list of checksums of (F_DEPLOY), compute and compare with local repository + # if checksum(local_config) != checksum(local_repo) + # copy local_config to local_repo + # if exists(local_config in local_repo) is False + # copy local_config to local_repo + # if exists(F_DEPLOY) but not in local_config + # warn for lost file, user must either copy from local_repo to local_config or delete from F_DEPLOY + # exec git commit -m "[message]" && git push + + def deploy(): """ Kindly executes the steps to get a up-to-date local repository, From 3c2a10ce3cf8d9040c0da59319b1736515d043a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 00:41:39 +0300 Subject: [PATCH 11/32] + partially implement method deploy() --- dotman.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dotman.py b/dotman.py index d010b28..c3163fb 100755 --- a/dotman.py +++ b/dotman.py @@ -2,7 +2,8 @@ # # Ferit Yiğit BALABAN , 2023 # -import os.path +import os +import shlex from subprocess import run import sys from datetime import datetime as dt @@ -196,9 +197,11 @@ def deploy(): Kindly executes the steps to get a up-to-date local repository, deploy (copy) files and directories to the local config directory. """ - # if no local repo - # go to ../local_repo and clone remote_url - # go to local_repo and exec git fetch && git pull + if not os.path.exists(SETTINGS.DIR_REPO): + r = SETTINGS.DIR_REPO + r.removesuffix("/")[:r.removesuffix("/").rindex("/")] + run(shlex.split(f"/usr/bin/git clone {SETTINGS[URL_REPO]}"), text=True, cwd=r) + run(shlex.split("/usr/bin/git pull")) # copy files & directories From 72ee899ba2cf337266d076b6f80d3cf5c862cc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 00:46:12 +0300 Subject: [PATCH 12/32] + implement method deploy() --- dotman.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dotman.py b/dotman.py index c3163fb..d0bab8c 100755 --- a/dotman.py +++ b/dotman.py @@ -201,8 +201,11 @@ def deploy(): r = SETTINGS.DIR_REPO r.removesuffix("/")[:r.removesuffix("/").rindex("/")] run(shlex.split(f"/usr/bin/git clone {SETTINGS[URL_REPO]}"), text=True, cwd=r) - run(shlex.split("/usr/bin/git pull")) - # copy files & directories + run(shlex.split("/usr/bin/git pull"), text=True, cwd=r) + for files in DL_FILES: + copy(files) + for dirs in DL_DIRS: + copy(dirs) def expand_settings(): From 78dd963035d9903be68b5376552cccb9711b48e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 00:47:26 +0300 Subject: [PATCH 13/32] ! refactor var. name in deploy() --- dotman.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dotman.py b/dotman.py index d0bab8c..3cd0f73 100755 --- a/dotman.py +++ b/dotman.py @@ -202,10 +202,10 @@ def deploy(): r.removesuffix("/")[:r.removesuffix("/").rindex("/")] run(shlex.split(f"/usr/bin/git clone {SETTINGS[URL_REPO]}"), text=True, cwd=r) run(shlex.split("/usr/bin/git pull"), text=True, cwd=r) - for files in DL_FILES: + for file in DL_FILES: copy(files) - for dirs in DL_DIRS: - copy(dirs) + for directory in DL_DIRS: + copy(directory) def expand_settings(): From ca4f345b7ed245c4c027b188bdfd5e99106b5431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 00:52:41 +0300 Subject: [PATCH 14/32] ! implement func. interactive prints message deploy() --- dotman.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dotman.py b/dotman.py index 3cd0f73..a39185b 100755 --- a/dotman.py +++ b/dotman.py @@ -192,7 +192,7 @@ def backup(): # exec git commit -m "[message]" && git push -def deploy(): +def deploy(interactive=False): """ Kindly executes the steps to get a up-to-date local repository, deploy (copy) files and directories to the local config directory. @@ -200,12 +200,16 @@ def deploy(): if not os.path.exists(SETTINGS.DIR_REPO): r = SETTINGS.DIR_REPO r.removesuffix("/")[:r.removesuffix("/").rindex("/")] + if interactive: + print(f"Local repository at {SETTINGS['DIR_REPO']} wasn't found. Cloning at {r}") run(shlex.split(f"/usr/bin/git clone {SETTINGS[URL_REPO]}"), text=True, cwd=r) + if interactive: + print("Pulling changes") run(shlex.split("/usr/bin/git pull"), text=True, cwd=r) for file in DL_FILES: - copy(files) + copy(files, interactive=interactive) for directory in DL_DIRS: - copy(directory) + copy(directory, interactive=interactive) def expand_settings(): From 704a715cb1a9f20aa9871f1e21ff188a6ecdbd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 01:04:15 +0300 Subject: [PATCH 15/32] ! implement func. interactive mode for copy() --- dotman.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dotman.py b/dotman.py index a39185b..3043812 100755 --- a/dotman.py +++ b/dotman.py @@ -125,8 +125,11 @@ def grab_dotfiles(): return code == 0, code -def copy(source, dest): - proc(f'cp -av {source} {dest}') +def copy(source, dest, interactive=False): + if interactive: + run(shlex.split(f"cp -av {source} {dest}")) + return + run(shlex.split(f"cp -a {source} {dest}")) def special_copy(source, dest): From faae765c320d36aa4a0d9262ea4cb5404b1a31c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 01:08:42 +0300 Subject: [PATCH 16/32] - delete old logic from main and methods --- dotman.py | 188 ------------------------------------------------------ 1 file changed, 188 deletions(-) diff --git a/dotman.py b/dotman.py index 3043812..77d5179 100755 --- a/dotman.py +++ b/dotman.py @@ -42,21 +42,6 @@ DL_FILES = [] DL_DIRS = [] -def get_nth_key(n: int, d: dict[str, str]): - c = 0 - for k in d.keys(): - if n == c: - return k - c += 1 - - -def read_file(path: str): - with open(path, 'r') as f: - content = f.readlines() - f.close() - return content - - def read_deploy_list(): """ Reads file from SETTINGS.F_DEPLOY to get list of directories and files to deploy @@ -86,45 +71,6 @@ def create_deploy_list(): f.close() -def rrem(text: str, char: str): - """ - Remove characters from right until character supplied with char - :param text: Where to remove characters from - :param char: Which character to stop removing at - :return: Returns text with all characters until specified character removed - """ - iterator = len(text) - 1 - buffer = '' - while text[iterator] != char: - buffer += text[iterator] - iterator -= 1 - return text.removesuffix(buffer[::-1]) - - -def proc(command, cwd=''): - if 'cp -av' in command: - r = run(command, shell=True) - else: - if cwd == '': - r = run(command, shell=True, capture_output=True, text=True) - else: - r = run(command, shell=True, capture_output=True, text=True, cwd=cwd) - return r.returncode, str(r.stdout) + str(r.stderr) - - -def print_settings(): - count = 1 - for key, value in SETTINGS.items(): - print(f'{count}. {key}:{value}') - count += 1 - - -def grab_dotfiles(): - os.mkdir(rrem(SETTINGS['DOTFILES_REPOSITORY'], '/')) - code, output = proc(f"git clone {SETTINGS['REMOTE_REPOSITORY']}", SETTINGS['DOTFILES_REPOSITORY']) - return code == 0, code - - def copy(source, dest, interactive=False): if interactive: run(shlex.split(f"cp -av {source} {dest}")) @@ -132,52 +78,6 @@ def copy(source, dest, interactive=False): run(shlex.split(f"cp -a {source} {dest}")) -def special_copy(source, dest): - whitelist = [ - 'fish', - 'gtk-2.0', - 'gtk-3.0', - 'htop', - 'i3', - 'kitty', - 'neofetch', - 'nitrogen', - 'picom', - 'polybar', - 'rofi', - 'xfce4', - 'navi', - 'gtk-4.0', - 'flameshot' - ] - dirs = os.listdir(source) - selected_dirs = [] - for each_name in dirs: - if each_name in whitelist: - selected_dirs.append(f'{source}{each_name}' if source.endswith('/') else f'{source}/{each_name}') - for directory in selected_dirs: - copy(directory, dest) - - -def commit_then_push(): - # I forget checking out to main after testing on a seperate branch - # Line below checks out for me every time it's run - proc('/usr/bin/git checkout main', SETTINGS['DOTFILES_REPOSITORY']) - proc('/usr/bin/git fetch', SETTINGS['DOTFILES_REPOSITORY']) - proc('/usr/bin/git pull', SETTINGS['DOTFILES_REPOSITORY']) - proc('/usr/bin/git add .', SETTINGS['DOTFILES_REPOSITORY']) - date = dt.now().strftime('%d.%m.%Y %H.%M') - _, output = proc(f'/usr/bin/git commit -m "dotman {date}"', SETTINGS['DOTFILES_REPOSITORY']) - if 'nothing to commit' not in output: - code, output = proc('/usr/bin/git push', SETTINGS['DOTFILES_REPOSITORY']) - if code == 0: - _, output = proc('/usr/bin/git log', SETTINGS['DOTFILES_REPOSITORY']) - commit = output.split('\n')[0].replace('commit ', '') - return 3, commit - return 0, None if code == 0 else 2, None - return 1, None - - def backup(): """ Aggresively executes the steps to do checksum comparisons between local @@ -234,7 +134,6 @@ def main(): flag_interactive = False flag_backup = False flag_deploy = False - flag_setup = False flag_version = False flag_help = False sys.argv.remove(sys.argv[0]) @@ -245,7 +144,6 @@ def main(): flag_interactive = flag_interactive or key == '-i' or key == '--interactive' flag_backup = flag_backup or key == '-b' or key == '--backup' flag_deploy = flag_deploy or key == '-d' or key == '--deploy' - flag_setup = flag_setup or key == '-s' or key == '--setup-dotman' flag_version = flag_version or key == '-v' or key == '--version' flag_help = flag_help or key == '-h' or key == '--help' else: @@ -287,92 +185,6 @@ def main(): exit(0) # run deploy - # ^^^ new logic ^^^ - # - # vvv old logic vvv - return - - if flag_interactive: - print(f"dotman {VER} by ferityigitbalaban") - if not local_repo_exists: - print(colored('Important warning:', 'red'), 'dotfiles repository cannot be located at: ', - colored(SETTINGS['DOTFILES_REPOSITORY'], 'yellow')) - print('Edit DOTFILES_REPOSITORY variable in this script to specify its location') - print(f'To grab dotfiles from', colored(f'"{remote_shortname}"', 'yellow'), end='') - ans = input('type Y. (y/N): ') - if ans.lower() == 'y' or 'yes': - grab_successed, exit_code = grab_dotfiles() - if grab_successed: - print(f'Successfully grabbed dotfiles from', colored(f'"{remote_shortname}"', 'yellow')) - else: - print(f'git exited with result code:', colored(str(exit_code), 'red'), - '. An error may have occured.') - exit(128) - else: - cprint('There isn\'t anything left for dotman to do. Have a nice day!', 'green') - exit(0) - print('dotman is', colored('ready', 'green'), 'for your command. ') - print('You can either backup to remote, or copy local repo to local config (deploy)') - ans = input('(B)ackup or (D)eploy: ') - if ans.lower() == 'b' or ans.lower() == 'backup': - print(colored('Step 1: ', 'magenta'), 'Copy from local config', colored(f"\"{SETTINGS['LOCAL_CONFIG']}\"", 'yellow'), - 'to local repo', colored(f"\"{SETTINGS['DOTFILES_REPOSITORY']}\"", 'yellow')) - special_copy(SETTINGS['LOCAL_CONFIG'], SETTINGS['DOTFILES_REPOSITORY']) - print(colored('Step 2: ', 'magenta'), f'Create a commit and push to remote repo', - colored(f"\"{SETTINGS['REMOTE_REPOSITORY']}\"", 'yellow')) - stat, _ = commit_then_push() - if stat == 0: - cprint('Backup completed. Have a nice day!', 'green') - elif stat == 1: - cprint('There was nothing to commit, aborting.', 'red') - elif stat == 2: - cprint('Couldn\'t push local to remote, aborting.', 'red') - elif stat == 3: - url = f"{SETTINGS['REMOTE_REPOSITORY']}/commit/{_}" - cprint(f'Backup completed: {url}. Have a nice day!', 'green') - exit(stat) - elif ans.lower() == 'd' or ans.lower() == 'deploy': - print(colored('Step 1:', 'magenta'), ' Copy from local repo to local config') - special_copy(SETTINGS['DOTFILES_REPOSITORY'], SETTINGS['LOCAL_CONFIG']) - cprint('Deploy completed. Have a nice day!', 'green') - exit(0) - elif flag_backup and not flag_deploy: - if local_repo_exists: - special_copy(SETTINGS['LOCAL_CONFIG'], SETTINGS['DOTFILES_REPOSITORY']) - exit(commit_then_push()) - else: - print(colored('[CRITICAL]', 'red'), 'Local repository couldn\'t be located. Aborting...') - exit(128) - elif flag_deploy and not flag_backup: - if local_repo_exists: - special_copy(SETTINGS['DOTFILES_REPOSITORY'], SETTINGS['LOCAL_CONFIG']) - exit(0) - else: - print(colored('[CRITICAL]', 'red'), 'Local repository couldn\'t be located. Aborting...') - exit(128) - elif flag_setup: - print(f'dotman interactive setup wizard {WER}') - print_settings() - ans = input('Edit settings (y/N): ') - if ans.lower() == 'y' or ans.lower() == 'yes': - print('Type in number of setting you wish to modify, and "e" or "exit" when done') - while True: - num = input('Input: ') - if num.lower() == 'exit' or num.lower() == 'e': - break - elif num.isnumeric() and 1 <= int(num) <= len(SETTINGS): - key = get_nth_key(int(num) - 1, SETTINGS) - SETTINGS[key] = input(f'Enter new value for {key}: ').strip() - print('Saving changes to file') - write_setup() - - elif flag_version: - print(f'dotman version: {VER.removeprefix("v")}') - exit(0) - elif not flag_deploy and not flag_backup and not flag_interactive or flag_help: - print(help_message) - exit(0) - if __name__ == '__main__': main() From a7741e1defab56ae7606b7fab6c873d3f48466c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 01:12:31 +0300 Subject: [PATCH 17/32] ! validate new main logic --- dotman.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/dotman.py b/dotman.py index 77d5179..dfe6c70 100755 --- a/dotman.py +++ b/dotman.py @@ -125,8 +125,6 @@ def expand_settings(): def main(): - global WHEREAMI - WHEREAMI = rrem(sys.argv[0], '/') expand_settings() exists_dir_repo = os.path.exists(SETTINGS['DIR_REPO']) @@ -150,31 +148,23 @@ def main(): flag_interactive = True if exists_dir_repo: - # local repository directory exists. Backup or deploy is possible. - if flag_interactive: - # if interactive flag was fed, ignore backup and deploy key - # ask user for action (backup or deploy) + if flag_interactive: while True: ans = input('(B)ackup or (D)eploy is possible, select one: ').lower() if ans == 'b' or ans == 'd': break if ans = 'b': - # interactive backup + backup(flag_interactive) elif ans = 'd': - # interactive deploy - + deploy(flag_deploy) else: - # continue according to set flag, XOR if flag_backup and not flag_deploy: - # backup + backup(flag_interactive) elif flag_deploy and not flag_backup: - # deploy + deploy(flag_interactive) else: - # either both flags are set OR both are unset exit(0) else: - # local repository directory does not exist. Only deploy is possible. - # if interactive, ask for deploy, else if deploy flag is set, deploy, otherwise quit. if flag_interactive: print(f"local repository directory for {SETTINGS.SHN_REPO} does not exist") print("You can clone and deploy this repository to local config directory") @@ -183,7 +173,7 @@ def main(): exit(0) if not flag_interactive and not flag_deploy: exit(0) - # run deploy + deploy(flag_interactive) if __name__ == '__main__': From 3a07958db7ddad60bb10381b0f7b633ee5063052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Sat, 11 Feb 2023 01:50:18 +0300 Subject: [PATCH 18/32] - remove unused lines --- dotman.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dotman.py b/dotman.py index dfe6c70..83ebb20 100755 --- a/dotman.py +++ b/dotman.py @@ -6,8 +6,6 @@ import os import shlex from subprocess import run import sys -from datetime import datetime as dt -from termcolor import colored, cprint # Modify SETTINGS dictionary to set runtime variables # Access values in dictionary using pre-defined names @@ -19,9 +17,7 @@ SETTINGS = { 'F_DEPLOY': '$HOME/.config/dotman/deploy_list.json', # path to deploy_list.json file } -WHEREAMI = '$HOME/scripts' VER = 'v1.8' -WER = 'v1.1' help_message = f''' dotman {VER} dotfiles manager by ferityigitbalaban @@ -30,7 +26,6 @@ this have the same effect as calling dotman without any key. Keys: -i, --interactive Interactively backup or deploy dotfiles. Not supplying any key will result in interactive mode. --s, --setup-dotman Interactively set variables (DOTFILES_REPOSITORY, LOCAL_CONFIG, etc.) for your dotman setup. -b, --backup Backup your dotfiles. Doesn't require user assistance but errors may occur. -d, --deploy Deploy your dotfiles. Doesn't require user assistance but errors may occur. -v, --version Shows the version and quits From 0c24bc40be331643b1671729ae2fa297494a6f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Wed, 10 May 2023 15:08:51 +0300 Subject: [PATCH 19/32] tiny tiny changes --- fetchpy2 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fetchpy2 b/fetchpy2 index cc480ca..92443e0 100755 --- a/fetchpy2 +++ b/fetchpy2 @@ -7,7 +7,7 @@ import os from subprocess import run -IMG_LOC = '/home/ferit/sources/neco.png' +IMG_LOC = '/home/ferit/shoka/500-599 pictures/505 clipart/windowschan_s.png' def clr(text: str): @@ -27,9 +27,9 @@ def clr(text: str): '': info, '': info, '': info, - '': info, + '': info, '': info, - '': info, + '󰢮': info, '': info, '': info, 'ferit@navi': title, @@ -108,22 +108,23 @@ def main(): │  {distro_name}│ │  {kernel_version}│ │  {shell_name}│ -│  {package_count}│ +│  {package_count}│ ├──────── Hardware ────────┤ │  AMD Ryzen 7 5800H │ -│  NV GeForce RTX3050 Ti │ +│ 󰢮 NV GeForce RTX3050 Ti │ │  {memory_usage}│ │  {uptime}│ ╰──────────────────────────╯ ''' txt_padded = '' - img_width = 15 + img_width = 16 line_count = 0 for line in txt.splitlines(): txt_padded += ((' ' * img_width) + line + '\n') line_count += 1 - run(['/usr/bin/kitty', 'icat', '--align', 'left', IMG_LOC]) + print('') + run(['/usr/bin/kitty', 'icat', '--mirror', 'horizontal', '--align', 'left', IMG_LOC]) run(['printf', "\e[%sA\e[999999D", str(line_count)]) clr(txt_padded) From 3ffa96677bfa9d10af0bd6284d2fcee0af5f35e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:31:12 +0300 Subject: [PATCH 20/32] fix typo --- dotman.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotman.py b/dotman.py index 83ebb20..d09bd8d 100755 --- a/dotman.py +++ b/dotman.py @@ -148,9 +148,9 @@ def main(): ans = input('(B)ackup or (D)eploy is possible, select one: ').lower() if ans == 'b' or ans == 'd': break - if ans = 'b': + if ans == 'b': backup(flag_interactive) - elif ans = 'd': + elif ans == 'd': deploy(flag_deploy) else: if flag_backup and not flag_deploy: From 82d1c81b076a51a943cd0224b639791ae6a49df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:31:48 +0300 Subject: [PATCH 21/32] update repository location --- dotman.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotman.py b/dotman.py index d09bd8d..9760f3c 100755 --- a/dotman.py +++ b/dotman.py @@ -11,8 +11,8 @@ import sys # Access values in dictionary using pre-defined names SETTINGS = { 'URL_REPO': 'https://github.com/fybx/dotfiles', # remote repository URL - 'SHN_REPO': 'fybx/dotfiles' # remote shortname - 'DIR_REPO': '$HOME/repos/dotfiles', # local repository directory + 'SHN_REPO': 'fybx/dotfiles', # remote shortname + 'DIR_REPO': '$HOME/shoka/300-399 repos/dotfiles', # local repository directory 'DIR_CONF': '$HOME/.config', # local .config directory 'F_DEPLOY': '$HOME/.config/dotman/deploy_list.json', # path to deploy_list.json file } From bf9e1273451f9abe58aa3ac96df21a600ae48048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:32:32 +0300 Subject: [PATCH 22/32] hyprland workspace: show clipboard history --- hypr_clip | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 hypr_clip diff --git a/hypr_clip b/hypr_clip new file mode 100755 index 0000000..e92bb90 --- /dev/null +++ b/hypr_clip @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +cliphist list | wofi --show dmenu | cliphist decode | wl-copy From b8214d27c6aeb9612ff5aa879111e3784116ab71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:33:09 +0300 Subject: [PATCH 23/32] hyprland workspace: lock screen --- lock.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 lock.sh diff --git a/lock.sh b/lock.sh new file mode 100755 index 0000000..db3026b --- /dev/null +++ b/lock.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# +# Ferit Yiğit BALABAN , 2023 +# +playerctl pause +swaylock -efklu -i "mounts/31_shoka/pictures/landscape/024.jpg" From 7790da1e6bba5d2b89c85fbcc75f23545c01d31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:33:39 +0300 Subject: [PATCH 24/32] hyprland workspace: shutdown script --- poweroff.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 poweroff.sh diff --git a/poweroff.sh b/poweroff.sh new file mode 100755 index 0000000..f872759 --- /dev/null +++ b/poweroff.sh @@ -0,0 +1,6 @@ +#!/bin/bash +dt=$(date -Iseconds) +unison=$($HOME/scripts/unison_sync.sh) +rm "$HOME/.cache/cliphist/db" +echo "[$dt] INFO: navi, powering off" >> navi.log +poweroff From 473f4efd2d9178845d017fce23b700963b844c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:34:31 +0300 Subject: [PATCH 25/32] deprecate in favor of poweroff.sh --- shutdown.sh | 5 ----- 1 file changed, 5 deletions(-) delete mode 100755 shutdown.sh diff --git a/shutdown.sh b/shutdown.sh deleted file mode 100755 index ea552b1..0000000 --- a/shutdown.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -dt=$(date +'%d/%m/%y-%H.%M.%S') -echo "[$dt] navi shutting down..." >> navi.log -$HOME/scripts/modeset.py --shutdown -shutdown -h now From 7a9f503017b72242e4b5f1dbd031c3a99d627f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:36:03 +0300 Subject: [PATCH 26/32] hyprland workspace: ss and save --- wl_ss.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 wl_ss.sh diff --git a/wl_ss.sh b/wl_ss.sh new file mode 100644 index 0000000..87f7236 --- /dev/null +++ b/wl_ss.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Ferit Yiğit BALABAN, +# +# Select an area with slurp, ss with grim +# and copy to clipboard. +export GRIM_DEFAULT_DIR="$HOME/items/ss" +grim -g "$( slurp )" - | wl-copy --type image/png From 600f6e3a0889bd85fb59717f8e3a8521a0662080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:37:26 +0300 Subject: [PATCH 27/32] hyprland workspace: select rectangular, ss and save --- wl_sss.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 wl_sss.sh diff --git a/wl_sss.sh b/wl_sss.sh new file mode 100755 index 0000000..89c46c7 --- /dev/null +++ b/wl_sss.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Ferit Yiğit BALABAN, +# +# Select an area with slurp, ss with grim +# and copy to clipboard. +SS="$HOME/items/ss" +grim -g "$( slurp )" - | wl-copy --type image/png && wl-paste > "$SS"/$( date +'%Y-%m-%d-%H%M%S.png' ) From 5aa4ecffc951021322f7b25f24ddab84bc3b909f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:38:32 +0300 Subject: [PATCH 28/32] unused: unison synchronizer --- deprecated/unison_sync.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 deprecated/unison_sync.sh diff --git a/deprecated/unison_sync.sh b/deprecated/unison_sync.sh new file mode 100755 index 0000000..a72b3f5 --- /dev/null +++ b/deprecated/unison_sync.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Ferit Yiğit BALABAN , 2023 +# & ChatGPT +# + +LOCAL_DIR="$HOME/mounts/31_shoka" +REMOTE_DIR="ssh://fyb@192.168.0.3//mnt/shoka" +LOG_FILE="$HOME/navi.log" +UNISON="/usr/bin/unison" + +# Run Unison to synchronize the directories +$UNISON $LOCAL_DIR $REMOTE_DIR -batch -auto -confirmbigdel > /dev/null 2>&1 + +# Check the exit code of Unison +if [ $? -eq 0 ]; then + # Synchronization was successful, log the message and exit + echo "$(date -Iseconds) INFO: unison, sync successful" >> $LOG_FILE + exit 0 +else + # Synchronization failed, check if there were conflicts + CONFLICTS=`grep "Conflicting file" /var/log/unison.log | wc -l` + if [ $CONFLICTS -eq 0 ]; then + # There were no conflicts, log the message and exit + echo "$(date -Iseconds) INFO: unison, no diff" >> $LOG_FILE + exit 0 + else + # There were conflicts, log the message and exit with an error code + echo "$(date -Iseconds) ERROR: unison, sync conflict" >> $LOG_FILE + exit 1 + fi +fi From 30f42331e813c205ed8f011e11258e21dd24f4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:39:00 +0300 Subject: [PATCH 29/32] johnny.decimal special --- cdd.bash | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 cdd.bash diff --git a/cdd.bash b/cdd.bash new file mode 100755 index 0000000..7627138 --- /dev/null +++ b/cdd.bash @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# Ferit Yiğit BALABAN, +# +# cd on steroids for Johnny.Decimal directories + +# Define the cdd function +cdd() { + local input="$1" + local folder="$(basename "$PWD")" + + if [[ "$input" =~ ^[0-9]{3}\.[0-9]{2}$ ]]; then + cd "$HOME/shoka/*/*/$input *" + elif [[ "$input" =~ ^[0-9]{3}$ ]]; then + cd "$HOME/shoka/*/$input *" + elif [[ "$input" =~ ^[0-9]{2}$ && "$folder" =~ ^[0-9]{3} ]]; then + cd "$HOME/shoka/*/*/${folder:0:3}.$input *" + else + echo "Invalid input: $input" + fi +} + +# Use the cdd function with the input argument +cdd "$1" From 7cdcaf9bb7191bfcee7488edec6a2ac5c3797433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:39:36 +0300 Subject: [PATCH 30/32] chore: back up home directory --- backup_home.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 backup_home.sh diff --git a/backup_home.sh b/backup_home.sh new file mode 100755 index 0000000..0e62d40 --- /dev/null +++ b/backup_home.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# Ferit Yiğit BALABAN , 2022 +# +echo "Hello, $( whoami )" +echo "w/o Downloads: $( du -sh --exclude='Downloads' "$HOME" )" +echo "wth Downloads: $( du -sh "$HOME" )" +doas tar --exclude="$HOME/Downloads" --exclude="$HOME/.local/share/JetBrains" --exclude="$HOME/.cache/pip" --exclude="$HOME/.cache/yay" --exclude="$HOME/.cache/JetBrains" --exclude="$HOME/.nuget" --create --verbose --preserve-permissions --gzip --file "/home/ferit-$( date +'%y%m%d' ).tar.gz" /home/ferit From 6f77f389cdaa8a2ea48a9b3c079d861aff4712a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:40:09 +0300 Subject: [PATCH 31/32] fix keying error --- dotman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotman.py b/dotman.py index 9760f3c..f326563 100755 --- a/dotman.py +++ b/dotman.py @@ -161,7 +161,7 @@ def main(): exit(0) else: if flag_interactive: - print(f"local repository directory for {SETTINGS.SHN_REPO} does not exist") + print(f"local repository directory for {SETTINGS['SHN_REPO']} does not exist") print("You can clone and deploy this repository to local config directory") ans = input("Continue (y/N): ").lower() if ans == "n" and not ans == "y": From d1344be34eb422bda03c5754d38dd159d7387e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 07:40:45 +0300 Subject: [PATCH 32/32] update: use pamixer instead of pactl to control volume --- modeset.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modeset.py b/modeset.py index 7ab4211..5ca954f 100755 --- a/modeset.py +++ b/modeset.py @@ -11,7 +11,7 @@ # Dependencies: # # - brightnessctl -# - pactl +# - pamixer # - playerctl # - wal # - betterlockscreen @@ -64,7 +64,7 @@ def set_volume(value: int, save_state=False): value = int(f.read()) f.close() value = 100 if value > 100 else 0 if value < 0 else value - run_command(f'pactl set-sink-volume @DEFAULT_SINK@ {value}%') + run_command(f'pamixer --set-volume {value}') if save_state: with open(os.path.expandvars(PATH_RESC_VOLUME), 'w') as f: f.write(str(state)) @@ -109,10 +109,7 @@ def get_brightness(device: int): def get_volume(): - r = do_query("pactl list") - for x in r.split("Sink #0")[1].split("Base Volume:")[0].split(' '): - if '%' in x: - return int(x.replace('%', '')) + return int(do_query("pamixer --get-volume")) def log(message: str):