Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect XDG base dir spec for config file #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)

Expand All @@ -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"

Expand Down Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions bpytop.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#*?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"

Expand Down Expand Up @@ -236,12 +236,18 @@
#* 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
''')

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)
Expand Down Expand Up @@ -4265,7 +4271,7 @@ def options(cls):
'',
'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 "+".',
Expand Down