From b438ec41818b8c7be97c88126ea6782d2a6d3fd6 Mon Sep 17 00:00:00 2001 From: Jonathan Haylett Date: Thu, 14 Nov 2019 19:01:37 +0000 Subject: [PATCH] Revert "Ensure programs that modify their own cmdline have args split correctly" --- i3_resurrect/programs.py | 27 +++------------------------ tests/test_programs.py | 23 ----------------------- 2 files changed, 3 insertions(+), 47 deletions(-) diff --git a/i3_resurrect/programs.py b/i3_resurrect/programs.py index 0013b8d..cc453ec 100644 --- a/i3_resurrect/programs.py +++ b/i3_resurrect/programs.py @@ -51,8 +51,8 @@ def save(workspace, numeric, directory, profile): if command in ([], ''): continue - # Ensure args are split properly and remove empty args. - command = split_args(command) + # Remove empty string arguments from command. + command = [arg for arg in command if arg != ''] try: # Obtain working directory using psutil. @@ -110,11 +110,9 @@ def restore(workspace, directory, profile): # If cmdline is array, join it into one string for use with i3's exec # command. if isinstance(cmdline, list): - # Ensure args are split properly and remove empty args. - cmdline = split_args(cmdline) # Quote each argument of the command in case some of them contain # spaces. - cmdline = [f'"{arg}"' for arg in cmdline] + cmdline = [f'"{arg}"' for arg in cmdline if arg != ''] command = ' '.join(cmdline) else: command = cmdline @@ -124,25 +122,6 @@ def restore(workspace, directory, profile): i3.command(f'exec cd "{working_directory}" && {command}') -def split_args(cmdline): - """ - Function for making sure command line arguments are split properly and - removing empty arguments. - - Args: - cmdline: The cmdline to process. - """ - # Sometimes the process may modify its own cmdline which can result in the - # cmdline returned by psutil not being split correctly, so we must make - # sure every element is a single argument. - result = [] - for arg in cmdline: - result += shlex.split(arg) - # Empty string args cause problems with i3 exec so we filter them out. - result = [arg for arg in result if arg != ''] - return result - - def windows_in_workspace(workspace, numeric): """ Generator to iterate over windows in a workspace. diff --git a/tests/test_programs.py b/tests/test_programs.py index 6428e6c..9226743 100644 --- a/tests/test_programs.py +++ b/tests/test_programs.py @@ -2,29 +2,6 @@ from i3_resurrect import programs -def test_split_args(): - cmdline = [ - 'test --test "test1 test2 test3" -test -t -e -s -t test', - 'test', - '', - 'test4', - ] - expected_cmdline = [ - 'test', - '--test', - 'test1 test2 test3', - '-test', - '-t', - '-e', - '-s', - '-t', - 'test', - 'test', - 'test4', - ] - assert programs.split_args(cmdline) == expected_cmdline - - def test_get_window_command(monkeypatch): # Monkeypatch config. monkeypatch.setattr(