Skip to content

Commit

Permalink
Add command to remove saved layout/programs
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyHaystack committed Nov 7, 2019
1 parent a89767a commit d801b56
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions i3_resurrect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def main():
'[default: ~/.i3/i3-resurrect]'))
@click.option('--profile', '-p',
default=None,
help=('The profile to save the workspace to.\n'
'[default: default]'))
help=('The profile to save the workspace to.'))
@click.option('--swallow', '-s',
default='class,instance',
help=('The swallow criteria to use.\n'
Expand Down Expand Up @@ -159,8 +158,7 @@ def save_programs(workspace, directory, profile):
'[default: ~/.i3/i3-resurrect]'))
@click.option('--profile', '-p',
default=None,
help=('The profile to restore the workspace from.\n'
'[default: default]'))
help=('The profile to restore the workspace from.'))
@click.option('--layout-only', 'target',
flag_value='layout_only',
help='Only restore layout.')
Expand Down Expand Up @@ -368,5 +366,42 @@ def list_workspaces(directory, item):
print('No profiles found')


@main.command('rm')
@click.option('--workspace', '-w',
default=None,
help='The saved workspace to delete.')
@click.option('--directory', '-d',
type=click.Path(file_okay=False),
default=Path('~/.i3/i3-resurrect/').expanduser(),
help=('The directory to delete from.\n'
'[default: ~/.i3/i3-resurrect]'))
@click.option('--profile', '-p', default=None, help=('The profile to delete.'))
@click.option('--layout-only', 'target',
flag_value='layout_only',
help='Only delete saved layout.')
@click.option('--programs-only', 'target',
flag_value='programs_only',
help='Only delete saved programs.')
def remove(workspace, directory, profile, target):
"""
Remove saved layout or programs.
"""
programs_filename = f'workspace_{workspace}_programs.json'
layout_filename = f'workspace_{workspace}_layout.json'
if profile is not None:
programs_filename = f'{profile}_programs.json'
layout_filename = f'{profile}_layout.json'
programs_file = Path(directory) / programs_filename
layout_file = Path(directory) / layout_filename

if target != 'programs_only':
# Delete programs file.
programs_filename.unlink()

if target != 'layout_only':
# Delete layout file.
layout_file.unlink()


if __name__ == '__main__':
main()

0 comments on commit d801b56

Please sign in to comment.