Skip to content

Commit

Permalink
Merge 7a44366 into c37bcf5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Haylett committed Nov 2, 2019
2 parents c37bcf5 + 7a44366 commit 7fdc09c
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions i3_resurrect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,27 @@ def restore_programs(workspace, directory):
commands_file = Path(directory) / f'workspace_{workspace}_programs.json'
commands = json.loads(commands_file.read_text())
for entry in commands:
command = entry['command']
cmdline = entry['command']
working_directory = entry['working_directory']

# If the working directory does not exist, set working directory to
# user's home directory.
if not Path(working_directory).exists():
working_directory = Path.home()

# If command has multiple arguments, split them into an array.
if isinstance(command, list):
cmdline = command
# If cmdline is array, join it into one string for use with i3's exec
# command.
if isinstance(cmdline, list):
# Quote each argument of the command in case some of them contain
# spaces.
for i in range(0, len(cmdline)):
cmdline[i] = f'"{cmdline[i]}"'
command = ' '.join(cmdline)
else:
cmdline = shlex.split(command)
command = cmdline

# Execute command as subprocess.
subprocess.Popen(
cmdline,
cwd=working_directory,
env={**os.environ, **{'PWD': working_directory}},
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)
i3.command(f'exec cd "{working_directory}" && {command}')


def restore_layout(workspace, directory):
Expand Down

0 comments on commit 7fdc09c

Please sign in to comment.