From 3d4651918280cd2d84a02b52b9ff7f8897694ff9 Mon Sep 17 00:00:00 2001 From: Miro Date: Thu, 21 May 2026 20:07:41 +0200 Subject: [PATCH] Fix invalid escape sequence warnings --- powerline_shell/__init__.py | 2 +- powerline_shell/segments/git.py | 7 ++++++- powerline_shell/segments/uptime.py | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/powerline_shell/__init__.py b/powerline_shell/__init__.py index ae62704c..75550b0b 100644 --- a/powerline_shell/__init__.py +++ b/powerline_shell/__init__.py @@ -15,7 +15,7 @@ def _current_dir(): in their shell (ie. without following symbolic links). With the introduction of Bash for Windows, we can't use the PWD environment - variable very easily. `os.sep` for windows is `\` but the PWD variable will + variable very easily. `os.sep` for windows is `\\` but the PWD variable will use `/`. So just always use the `os` functions for dealing with paths. This also is fine because the use of PWD below is done to avoid following symlinks, which Windows doesn't have. diff --git a/powerline_shell/segments/git.py b/powerline_shell/segments/git.py index de2b049e..2cccf200 100644 --- a/powerline_shell/segments/git.py +++ b/powerline_shell/segments/git.py @@ -4,7 +4,12 @@ def parse_git_branch_info(status): - info = re.search('^## (?P\S+?)''(\.{3}(?P\S+?)( \[(ahead (?P\d+)(, )?)?(behind (?P\d+))?\])?)?$', status[0]) + branch_status = ( + r'^## (?P\S+?)' + r'(\.{3}(?P\S+?)' + r'( \[(ahead (?P\d+)(, )?)?(behind (?P\d+))?\])?)?$' + ) + info = re.search(branch_status, status[0]) return info.groupdict() if info else None diff --git a/powerline_shell/segments/uptime.py b/powerline_shell/segments/uptime.py index 1c030611..1a771b8a 100644 --- a/powerline_shell/segments/uptime.py +++ b/powerline_shell/segments/uptime.py @@ -8,12 +8,12 @@ def add_to_powerline(self): powerline = self.powerline try: output = decode(subprocess.check_output(['uptime'], stderr=subprocess.STDOUT)) - raw_uptime = re.search('(?<=up).+(?=,\s+\d+\s+user)', output).group(0) - day_search = re.search('\d+(?=\s+day)', output) + raw_uptime = re.search(r'(?<=up).+(?=,\s+\d+\s+user)', output).group(0) + day_search = re.search(r'\d+(?=\s+day)', output) days = '' if not day_search else '%sd ' % day_search.group(0) - hour_search = re.search('\d{1,2}(?=\:)', raw_uptime) + hour_search = re.search(r'\d{1,2}(?=:)', raw_uptime) hours = '' if not hour_search else '%sh ' % hour_search.group(0) - minutes = re.search('(?<=\:)\d{1,2}|\d{1,2}(?=\s+min)', raw_uptime).group(0) + minutes = re.search(r'(?<=:)\d{1,2}|\d{1,2}(?=\s+min)', raw_uptime).group(0) uptime = u' %s%s%sm \u2191 ' % (days, hours, minutes) powerline.append(uptime, powerline.theme.CWD_FG, powerline.theme.PATH_BG) except OSError: