From 298bbc0fe8064b1b5cc37a9d36907d9cf1ff7867 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Wed, 8 Sep 2021 06:51:37 -0500 Subject: [PATCH 1/2] Respect XDG base dir spec for config file --- bpytop.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bpytop.py b/bpytop.py index 55c99ad..9edc1a9 100755 --- a/bpytop.py +++ b/bpytop.py @@ -241,7 +241,13 @@ update_check=$update_check log_level=$log_level ''') -CONFIG_DIR: str = f'{os.path.expanduser("~")}/.config/bpytop' + +def get_config_dir(): + config_home = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")) + return os.path.join(config_home, 'bpytop') + + +CONFIG_DIR: str = get_config_dir() if not os.path.isdir(CONFIG_DIR): try: os.makedirs(CONFIG_DIR) From a7823dd9d6f3a609099ed9f11effd8e5af1798b5 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Wed, 8 Sep 2021 07:09:01 -0500 Subject: [PATCH 2/2] document XDG_CONFIG_HOME config directory change --- README.md | 8 ++++---- bpytop.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bc3635d..267546a 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ See [themes](https://github.com/aristocratos/bpytop/tree/master/themes) folder f The `make install` command places the default themes in `/usr/local/share/bpytop/themes`. If installed with `pip3` the themes will be located in a folder called `bpytop-themes` in the python3 site-packages folder. -User created themes should be placed in `$HOME/.config/bpytop/themes`. +User created themes should be placed in `${XDG_CONFIG_HOME:-$HOME/.config}/bpytop/themes`. Let me know if you want to contribute with new themes. @@ -361,7 +361,7 @@ sudo make uninstall ## Configurability All options changeable from within UI. -Config files stored in "$HOME/.config/bpytop" folder +Config files stored in "${XDG_CONFIG_HOME:-$HOME/.config}/bpytop" folder #### bpytop.cfg: (auto generated if not found) @@ -370,7 +370,7 @@ Config files stored in "$HOME/.config/bpytop" folder ```bash #? Config file for bpytop v. 1.0.64 -#* Color theme, looks for a .theme file in "/usr/[local/]share/bpytop/themes" and "~/.config/bpytop/themes", "Default" for builtin default theme. +#* Color theme, looks for a .theme file in "/usr/[local/]share/bpytop/themes" and "${XDG_CONFIG_HOME:-$HOME/.config}/bpytop/themes", "Default" for builtin default theme. #* Prefix name by a plus sign (+) for a theme located in user themes folder, i.e. color_theme="+monokai" color_theme="monokai" @@ -518,7 +518,7 @@ show_init=False #* Enable check for new version from github.com/aristocratos/bpytop at start. update_check=True -#* Set loglevel for "~/.config/bpytop/error.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". +#* Set loglevel for "${XDG_CONFIG_HOME:-$HOME/.config}/bpytop/error.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". #* The level set includes all lower levels, i.e. "DEBUG" will show all logging info. log_level=DEBUG diff --git a/bpytop.py b/bpytop.py index 9edc1a9..6f0903b 100755 --- a/bpytop.py +++ b/bpytop.py @@ -88,7 +88,7 @@ BANNER_SRC: List[Tuple[str, str, str]] = [ #*?This is the template used to create the config file DEFAULT_CONF: Template = Template(f'#? Config file for bpytop v. {VERSION}' + ''' -#* Color theme, looks for a .theme file in "/usr/[local/]share/bpytop/themes" and "~/.config/bpytop/themes", "Default" for builtin default theme. +#* Color theme, looks for a .theme file in "/usr/[local/]share/bpytop/themes" and "$${XDG_CONFIG_HOME:-$$HOME/.config}/bpytop/themes", "Default" for builtin default theme. #* Prefix name by a plus sign (+) for a theme located in user themes folder, i.e. color_theme="+monokai" color_theme="$color_theme" @@ -236,7 +236,7 @@ show_init=$show_init #* Enable check for new version from github.com/aristocratos/bpytop at start. update_check=$update_check -#* Set loglevel for "~/.config/bpytop/error.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". +#* Set loglevel for "$${XDG_CONFIG_HOME:-$$HOME/.config}/bpytop/error.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". #* The level set includes all lower levels, i.e. "DEBUG" will show all logging info. log_level=$log_level ''') @@ -4271,7 +4271,7 @@ class Menu: '', 'Choose from all theme files in', '"/usr/[local/]share/bpytop/themes" and', - '"~/.config/bpytop/themes".', + '"${XDG_CONFIG_HOME:-$HOME/.config}/bpytop/themes".', '', '"Default" for builtin default theme.', 'User themes are prefixed by a plus sign "+".',