sbp icon indicating copy to clipboard operation
sbp copied to clipboard

Check deprecate configuration variables

Open akinomyoga opened this issue 2 years ago • 3 comments

@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 91f0edf79ef53cf81a860227286db303d9c3fb1a and 61d7f1fdfc81e91a4cdcbf7f58f99b5b2b06bc58.

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'.

akinomyoga avatar Jan 23 '22 08:01 akinomyoga

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 :/

brujoand avatar Dec 23 '22 08:12 brujoand

@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 (https://github.com/brujoand/sbp/commit/3c9b999f24445441fa828627c6b269e8c322704b 3e2eba8f62098fb07be071445482494c4b36c03f b3b3c0ba039036ef7eeccddfa3e9fda26eda1642 f5d0b29e2647ce644ea01be469da10a3cbb4939d). 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.

akinomyoga avatar Dec 23 '22 11:12 akinomyoga

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 👍

brujoand avatar Dec 24 '22 09:12 brujoand