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

Check deprecate configuration variables #119

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

akinomyoga
Copy link
Contributor

@akinomyoga akinomyoga commented Jan 23, 2022

@brujoand Thank you for reviewing and merging #117 and #118! Based on these PRs, I here create a new PR that solves #100. In this PR, I add a framework to detect the uses of older variable names and then added a list of older variable names that I found in the git history. This framework can also be used for future changes.

When the uses of old variable names are detected, the values are reflected in corresponding new variables. With this change, the old configuration file for 2019-12 sbp can be loaded and works as expected, but produces the warning messages, which includes the information on how we can update the configuration file.

P.S. This PR also includes trivial fixes 91f0edf and 61d7f1f.

Example:

settings.conf

#!/usr/bin/env bash
settings_theme_color='default'
settings_theme_layout='powerline'

# Hooks will run once before every prompt
# Run 'sbp hooks' to list all available hooks
settings_hooks=('alert')

# Segments are generated before each prompt and can
# be added, removed and reordered
# Run 'sbp segments' to list all available segments
# Maybe you don't want to run all segments when in
# a multiplexer?
if [[ "$TERM" = "screen" || -n "$TMUX" ]]; then
  # We're inside tmux or screen
  settings_segments_left=('path' 'python_env' 'git' 'commend')
  settings_segments_right=('')
else
  settings_segments_left=('host' 'path' 'python_env' 'git' )
  settings_segments_right=('command' 'timestamp')
fi

# General settings, which might be overridden by themes
settings_git_icon=''
settings_git_incoming_icon=''
settings_git_outgoing_icon=''
settings_path_splitter_disable=0
settings_prompt_ready_vi_mode=0
settings_prompt_ready_icon=''
settings_prompt_ready_newline=1
settings_timestamp_format="%H:%M:%S"
settings_openshift_default_user="$USER"
settings_rescuetime_refresh_rate=600

colors.conf

#!/usr/bin/env bash

# Color configuration for the segments.
# Check the actualy colors ofr the current theme
# Using 'sbp colors'

settings_command_color_primary=$color04
settings_command_color_secondary=$color01
settings_command_color_primary_error=$color08
settings_command_color_secondary_error=$color04

settings_git_color_primary=$color0A
settings_git_color_secondary=$color01

settings_host_color_primary=$color02
settings_host_color_secondary=$color05
settings_host_root_color_primary=$color09
settings_host_root_color_secondary=$color00

settings_path_color_primary=$color0E
settings_path_color_secondary=$color07
settings_path_splitter_color=$color04

settings_path_readonly_color_secondary=$color0F
settings_path_readonly_color_primary=$color1

settings_prompt_ready_color_primary=''
settings_prompt_ready_color_secondary=$color04
settings_prompt_ready_vi_insert_color=$color04
settings_prompt_ready_vi_command_color=$color0E

settings_python_virtual_env_color_primary=$color09
settings_python_virtual_env_color_secondary=$color0F

settings_return_code_color_primary=$color1
settings_return_code_color_secondary=$color0F

settings_timestamp_color_primary=$color02
settings_timestamp_color_secondary=$color05

settings_aws_color_primary=$color08
settings_aws_color_secondary=$color09

settings_openshift_color_primary=$color08
settings_openshift_color_secondary=$color09

settings_rescuetime_color_primary=$color09
settings_rescuetime_color_secondary=$color0F
settings_rescuetime_splitter_color=$color07

Warning messages containing the instruction for updating configuration files

/home/murase/.config/sbp/settings.conf:2: 'settings_theme_color' is deprecated. Please use 'SBP_THEME_COLOR'.
/home/murase/.config/sbp/settings.conf:3: 'settings_theme_layout' is deprecated. Please use 'SBP_THEME_LAYOUT'.
/home/murase/.config/sbp/settings.conf:24: 'settings_git_icon' is deprecated. Please use 'SEGMENTS_GIT_ICON'.
/home/murase/.config/sbp/settings.conf:25: 'settings_git_incoming_icon' is deprecated. Please use 'SEGMENTS_GIT_INCOMING_ICON'.
/home/murase/.config/sbp/settings.conf:26: 'settings_git_outgoing_icon' is deprecated. Please use 'SEGMENTS_GIT_OUTGOING_ICON'.
/home/murase/.config/sbp/settings.conf:27: 'settings_path_splitter_disable' is deprecated. Please use 'SEGMENTS_PATH_SPLITTER_DISABLE'.
/home/murase/.config/sbp/settings.conf:28: 'settings_prompt_ready_vi_mode' is deprecated.
/home/murase/.config/sbp/settings.conf:29: 'settings_prompt_ready_icon' is deprecated. Please use 'SEGMENTS_PROMPT_READY_ICON'.
/home/murase/.config/sbp/settings.conf:30: 'settings_prompt_ready_newline' is deprecated.
/home/murase/.config/sbp/settings.conf:31: 'settings_timestamp_format' is deprecated. Please use 'SEGMENTS_TIMESTAMP_FORMAT'.
/home/murase/.config/sbp/settings.conf:32: 'settings_openshift_default_user' is deprecated. Please use 'SEGMENTS_K8S_DEFAULT_USER'.
/home/murase/.config/sbp/settings.conf:33: 'settings_rescuetime_refresh_rate' is deprecated. Please use 'SEGMENTS_RESCUETIME_REFRESH_RATE'.
/home/murase/.config/sbp/colors.conf:7: 'color04' is deprecated. Please use 'color4'.
/home/murase/.config/sbp/colors.conf:7: 'settings_command_color_primary' is deprecated. Please use 'SEGMENTS_COMMAND_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:8: 'color01' is deprecated. Please use 'color1'.
/home/murase/.config/sbp/colors.conf:8: 'settings_command_color_secondary' is deprecated. Please use 'SEGMENTS_COMMAND_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:9: 'color08' is deprecated. Please use 'color8'.
/home/murase/.config/sbp/colors.conf:9: 'settings_command_color_primary_error' is deprecated. Please use 'SEGMENTS_COMMAND_COLOR_PRIMARY_HIGHLIGHT'.
/home/murase/.config/sbp/colors.conf:10: 'color04' is deprecated. Please use 'color4'.
/home/murase/.config/sbp/colors.conf:10: 'settings_command_color_secondary_error' is deprecated. Please use 'SEGMENTS_COMMAND_COLOR_SECONDARY_HIGHLIGHT'.
/home/murase/.config/sbp/colors.conf:12: 'color0A' is deprecated. Please use 'color10'.
/home/murase/.config/sbp/colors.conf:12: 'settings_git_color_primary' is deprecated. Please use 'SEGMENTS_GIT_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:13: 'color01' is deprecated. Please use 'color1'.
/home/murase/.config/sbp/colors.conf:13: 'settings_git_color_secondary' is deprecated. Please use 'SEGMENTS_GIT_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:15: 'color02' is deprecated. Please use 'color2'.
/home/murase/.config/sbp/colors.conf:15: 'settings_host_color_primary' is deprecated. Please use 'SEGMENTS_HOST_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:16: 'color05' is deprecated. Please use 'color5'.
/home/murase/.config/sbp/colors.conf:16: 'settings_host_color_secondary' is deprecated. Please use 'SEGMENTS_HOST_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:17: 'color09' is deprecated. Please use 'color9'.
/home/murase/.config/sbp/colors.conf:17: 'settings_host_root_color_primary' is deprecated. Please use 'SEGMENTS_HOST_COLOR_PRIMARY_HIGHLIGHT'.
/home/murase/.config/sbp/colors.conf:18: 'color00' is deprecated. Please use 'color0'.
/home/murase/.config/sbp/colors.conf:18: 'settings_host_root_color_secondary' is deprecated. Please use 'SEGMENTS_HOST_COLOR_SECONDARY_HIGHLIGHT'.
/home/murase/.config/sbp/colors.conf:20: 'color0E' is deprecated. Please use 'color14'.
/home/murase/.config/sbp/colors.conf:20: 'settings_path_color_primary' is deprecated. Please use 'SEGMENTS_PATH_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:21: 'color07' is deprecated. Please use 'color7'.
/home/murase/.config/sbp/colors.conf:21: 'settings_path_color_secondary' is deprecated. Please use 'SEGMENTS_PATH_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:22: 'color04' is deprecated. Please use 'color4'.
/home/murase/.config/sbp/colors.conf:22: 'settings_path_splitter_color' is deprecated. Please use 'SEGMENTS_PATH_COLOR_SPLITTER'.
/home/murase/.config/sbp/colors.conf:24: 'color0F' is deprecated. Please use 'color15'.
/home/murase/.config/sbp/colors.conf:24: 'settings_path_readonly_color_secondary' is deprecated. Please use 'SEGMENTS_PATH_RO_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:25: 'settings_path_readonly_color_primary' is deprecated. Please use 'SEGMENTS_PATH_RO_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:27: 'settings_prompt_ready_color_primary' is deprecated. Please use 'SEGMENTS_PROMPT_READY_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:28: 'color04' is deprecated. Please use 'color4'.
/home/murase/.config/sbp/colors.conf:28: 'settings_prompt_ready_color_secondary' is deprecated. Please use 'SEGMENTS_PROMPT_READY_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:29: 'color04' is deprecated. Please use 'color4'.
/home/murase/.config/sbp/colors.conf:29: 'settings_prompt_ready_vi_insert_color' is deprecated.
/home/murase/.config/sbp/colors.conf:30: 'color0E' is deprecated. Please use 'color14'.
/home/murase/.config/sbp/colors.conf:30: 'settings_prompt_ready_vi_command_color' is deprecated.
/home/murase/.config/sbp/colors.conf:32: 'color09' is deprecated. Please use 'color9'.
/home/murase/.config/sbp/colors.conf:32: 'settings_python_virtual_env_color_primary' is deprecated. Please use 'SEGMENTS_PYTHON_ENV_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:33: 'color0F' is deprecated. Please use 'color15'.
/home/murase/.config/sbp/colors.conf:33: 'settings_python_virtual_env_color_secondary' is deprecated. Please use 'SEGMENTS_PYTHON_ENV_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:35: 'settings_return_code_color_primary' is deprecated. Please use 'SEGMENTS_RETURN_CODE_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:36: 'color0F' is deprecated. Please use 'color15'.
/home/murase/.config/sbp/colors.conf:36: 'settings_return_code_color_secondary' is deprecated. Please use 'SEGMENTS_RETURN_CODE_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:38: 'color02' is deprecated. Please use 'color2'.
/home/murase/.config/sbp/colors.conf:38: 'settings_timestamp_color_primary' is deprecated. Please use 'SEGMENTS_TIMESTAMP_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:39: 'color05' is deprecated. Please use 'color5'.
/home/murase/.config/sbp/colors.conf:39: 'settings_timestamp_color_secondary' is deprecated. Please use 'SEGMENTS_TIMESTAMP_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:41: 'color08' is deprecated. Please use 'color8'.
/home/murase/.config/sbp/colors.conf:41: 'settings_aws_color_primary' is deprecated. Please use 'SEGMENTS_AWS_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:42: 'color09' is deprecated. Please use 'color9'.
/home/murase/.config/sbp/colors.conf:42: 'settings_aws_color_secondary' is deprecated. Please use 'SEGMENTS_AWS_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:44: 'color08' is deprecated. Please use 'color8'.
/home/murase/.config/sbp/colors.conf:44: 'settings_openshift_color_primary' is deprecated. Please use 'SEGMENTS_K8S_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:45: 'color09' is deprecated. Please use 'color9'.
/home/murase/.config/sbp/colors.conf:45: 'settings_openshift_color_secondary' is deprecated. Please use 'SEGMENTS_K8S_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:47: 'color09' is deprecated. Please use 'color9'.
/home/murase/.config/sbp/colors.conf:47: 'settings_rescuetime_color_primary' is deprecated. Please use 'SEGMENTS_RESCUETIME_COLOR_PRIMARY'.
/home/murase/.config/sbp/colors.conf:48: 'color0F' is deprecated. Please use 'color15'.
/home/murase/.config/sbp/colors.conf:48: 'settings_rescuetime_color_secondary' is deprecated. Please use 'SEGMENTS_RESCUETIME_COLOR_SECONDARY'.
/home/murase/.config/sbp/colors.conf:49: 'color07' is deprecated. Please use 'color7'.
/home/murase/.config/sbp/colors.conf:49: 'settings_rescuetime_splitter_color' is deprecated. Please use 'SEGMENTS_RESCUETIME_SPLITTER_COLOR'.
/home/murase/.config/sbp/settings.conf: Array 'settings_hooks' is deprecated. Please assign to 'SBP_HOOKS'.
/home/murase/.config/sbp/settings.conf: Array 'settings_segments_left' is deprecated. Please assign to 'SBP_SEGMENTS_LEFT'.
/home/murase/.config/sbp/settings.conf: Array 'settings_segments_right' is deprecated. Please assign to 'RBP_SEGMENTS_RIGHT'.

@brujoand
Copy link
Owner

I'm really sorry for having lost track of this one, it's bound to have taken a lot of time to write and would have been really useful right after the breaking change to configuration. Unfortunatly it's been a crazy year and I haven't had much time for side projects :/

@akinomyoga
Copy link
Contributor Author

akinomyoga commented Dec 23, 2022

@brujoand Thank you for your reply. Now, I'm actually not sure if this is worth merging because it has been a long time since the incompatible change to the configuration variables was made on 2020-07-07..2020-10-12 (3c9b999 3e2eba8 b3b3c0b f5d0b29). So, this PR can be regarded as a technical demonstration of how we can detect the old configurations, notify them to users, and reflect them into the new configurations.

Nevertheless, if you would like to still consider it, I am willing to adjust the code to the latest version for review. I made this PR the least invasive so that the change to the main code becomes just a few lines, so this doesn't affect the complexity of the codebase.

Edit: Maybe this framework will be useful when we change the configuration variables in the future. If you would like to change the configurations again, we can add the variable names in this framework and do not have to worry about errors and unexpected behaviors.

@brujoand
Copy link
Owner

Yeah I think the approach is super useful, and if there was to be some new overhaul of the settings it would be neat to reuse this to make the transition smooth. At that point though I think it would be best to refactor it into a standalone script, which can be announsed through a log message if settings name are rewritten. Let's keep it for later, these things tend to happen more often than expected 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants