<s> import i3ipc <EOL> from argparse import ArgumentParser <EOL> from subprocess import check_output , Popen <EOL> history = [ ] <EOL> parser = ArgumentParser ( prog = '<STR_LIT>' , <EOL> description = '''<STR_LIT>''' , <EOL> epilog = '''<STR_LIT>''' ) <EOL> try : <EOL> with open ( '<STR_LIT>' ) as f : <EOL> history = f . read ( ) . split ( '<STR_LIT:\n>' ) <EOL> except FileNotFoundError : <EOL> pass <EOL> i3 = i3ipc . Connection ( ) <EOL> ( args , menu_args ) = parser . parse_known_args ( ) <EOL> if len ( menu_args ) and menu_args [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> menu_args = menu_args [ <NUM_LIT:1> : ] <EOL> else : <EOL> menu_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> menu_cmd = [ '<STR_LIT>' ] + menu_args <EOL> cmd = check_output ( menu_cmd , input = bytes ( '<STR_LIT:\n>' . join ( history ) , '<STR_LIT>' ) ) <EOL> cmd = cmd . decode ( '<STR_LIT>' ) . strip ( ) <EOL> result = i3 . command ( cmd ) <EOL> cmd_success = True <EOL> for r in result : <EOL> if not r . success : <EOL> cmd_success = False <EOL> Popen ( [ '<STR_LIT>' , '<STR_LIT>' , r . error ] ) <EOL> if cmd_success : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> try : <EOL> history . remove ( cmd ) <EOL> except ValueError : <EOL> pass <EOL> history . insert ( <NUM_LIT:0> , cmd ) <EOL> f . write ( '<STR_LIT:\n>' . join ( history ) ) </s>
