Skip to content

Commit

Permalink
Revert "Ensure programs that modify their own cmdline have args split…
Browse files Browse the repository at this point in the history
… correctly"
  • Loading branch information
Jonathan Haylett committed Nov 14, 2019
1 parent e349241 commit b438ec4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 47 deletions.
27 changes: 3 additions & 24 deletions i3_resurrect/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
23 changes: 0 additions & 23 deletions tests/test_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b438ec4

Please sign in to comment.