qutebrowser profile manager

use profile dir as context object directly

+22 -29
+22 -29
qbpm/main.py
··· 25 @click.pass_context 26 def main(ctx, profile_dir: Path) -> None: 27 # TODO version 28 - ctx.ensure_object(dict) 29 - ctx.obj["PROFILE_DIR"] = profile_dir 30 31 32 @main.command() ··· 36 @click.option("--overwrite", is_flag=True) 37 @click.option("-l", "--launch", is_flag=True) 38 @click.option("-f", "--foreground", is_flag=True) 39 - @click.pass_context 40 - def new(ctx, profile_name: str, **kwargs): 41 """Create a new profile.""" 42 - profile = Profile(profile_name, ctx.obj["PROFILE_DIR"]) 43 then_launch(profiles.new_profile, profile, **kwargs) 44 45 ··· 50 @click.option("--overwrite", is_flag=True) 51 @click.option("-l", "--launch", is_flag=True) 52 @click.option("-f", "--foreground", is_flag=True) 53 - @click.pass_context 54 def from_session( 55 - ctx, 56 session: str, 57 profile_name: Optional[str], 58 **kwargs, ··· 61 SESSION may be the name of a session in the global qutebrowser profile 62 or a path to a session yaml file. 63 """ 64 - profile, session_path = session_info(session, profile_name, ctx.obj["PROFILE_DIR"]) 65 then_launch(operations.from_session, profile, session_path=session_path, **kwargs) 66 67 68 @main.command() 69 @click.argument("profile_name") 70 - @click.pass_context 71 def desktop( 72 - ctx, 73 profile_name: str, 74 ): 75 """Create a desktop file for an existing profile.""" 76 - profile = Profile(profile_name, ctx.obj["PROFILE_DIR"]) 77 exit_with(operations.desktop(profile)) 78 79 ··· 81 @click.argument("profile_name") 82 @click.option("-c", "--create", is_flag=True) 83 @click.option("-f", "--foreground", is_flag=True) 84 - @click.pass_context 85 - def launch(ctx, profile_name: str, **kwargs): 86 """Launch qutebrowser with a specific profile.""" 87 - profile = Profile(profile_name, ctx.obj["PROFILE_DIR"]) 88 # TODO qb args 89 exit_with(operations.launch(profile, qb_args=[], **kwargs)) 90 ··· 97 help=f"A dmenu-compatible command or one of the following supported menus: {', '.join(sorted(SUPPORTED_MENUS))}", 98 ) 99 @click.option("-f", "--foreground", is_flag=True) 100 - @click.pass_context 101 - def choose(ctx, **kwargs): 102 """Choose a profile to launch. 103 Support is built in for many X and Wayland launchers, as well as applescript dialogs. 104 """ 105 # TODO qb args 106 - exit_with( 107 - operations.choose(profile_dir=ctx.obj["PROFILE_DIR"], qb_args=[], **kwargs) 108 - ) 109 110 111 @main.command() 112 @click.argument("profile_name") 113 - @click.pass_context 114 - def edit(ctx, profile_name): 115 """Edit a profile's config.py.""" 116 - profile = Profile(profile_name, ctx.obj["PROFILE_DIR"]) 117 if not profile.exists(): 118 error(f"profile {profile.name} not found at {profile.root}") 119 exit(1) ··· 121 122 123 @main.command(name="list") 124 - @click.pass_context 125 - def list_(ctx): 126 """List existing profiles.""" 127 - for profile in sorted(ctx.obj["PROFILE_DIR"].iterdir()): 128 print(profile.name) 129 130 ··· 162 163 def exit_with(result: bool): 164 exit(0 if result else 1) 165 - 166 - 167 - if __name__ == "__main__": 168 - main(obj={})
··· 25 @click.pass_context 26 def main(ctx, profile_dir: Path) -> None: 27 # TODO version 28 + ctx.obj = profile_dir 29 30 31 @main.command() ··· 35 @click.option("--overwrite", is_flag=True) 36 @click.option("-l", "--launch", is_flag=True) 37 @click.option("-f", "--foreground", is_flag=True) 38 + @click.pass_obj 39 + def new(profile_dir: Path, profile_name: str, **kwargs): 40 """Create a new profile.""" 41 + profile = Profile(profile_name, profile_dir) 42 then_launch(profiles.new_profile, profile, **kwargs) 43 44 ··· 49 @click.option("--overwrite", is_flag=True) 50 @click.option("-l", "--launch", is_flag=True) 51 @click.option("-f", "--foreground", is_flag=True) 52 + @click.pass_obj 53 def from_session( 54 + profile_dir: Path, 55 session: str, 56 profile_name: Optional[str], 57 **kwargs, ··· 60 SESSION may be the name of a session in the global qutebrowser profile 61 or a path to a session yaml file. 62 """ 63 + profile, session_path = session_info(session, profile_name, profile_dir) 64 then_launch(operations.from_session, profile, session_path=session_path, **kwargs) 65 66 67 @main.command() 68 @click.argument("profile_name") 69 + @click.pass_obj 70 def desktop( 71 + profile_dir: Path, 72 profile_name: str, 73 ): 74 """Create a desktop file for an existing profile.""" 75 + profile = Profile(profile_name, profile_dir) 76 exit_with(operations.desktop(profile)) 77 78 ··· 80 @click.argument("profile_name") 81 @click.option("-c", "--create", is_flag=True) 82 @click.option("-f", "--foreground", is_flag=True) 83 + @click.pass_obj 84 + def launch(profile_dir: Path, profile_name: str, **kwargs): 85 """Launch qutebrowser with a specific profile.""" 86 + profile = Profile(profile_name, profile_dir) 87 # TODO qb args 88 exit_with(operations.launch(profile, qb_args=[], **kwargs)) 89 ··· 96 help=f"A dmenu-compatible command or one of the following supported menus: {', '.join(sorted(SUPPORTED_MENUS))}", 97 ) 98 @click.option("-f", "--foreground", is_flag=True) 99 + @click.pass_obj 100 + def choose(profile_dir: Path, **kwargs): 101 """Choose a profile to launch. 102 Support is built in for many X and Wayland launchers, as well as applescript dialogs. 103 """ 104 # TODO qb args 105 + exit_with(operations.choose(profile_dir=profile_dir, qb_args=[], **kwargs)) 106 107 108 @main.command() 109 @click.argument("profile_name") 110 + @click.pass_obj 111 + def edit(profile_dir: Path, profile_name): 112 """Edit a profile's config.py.""" 113 + profile = Profile(profile_name, profile_dir) 114 if not profile.exists(): 115 error(f"profile {profile.name} not found at {profile.root}") 116 exit(1) ··· 118 119 120 @main.command(name="list") 121 + @click.pass_obj 122 + def list_(profile_dir: Path): 123 """List existing profiles.""" 124 + for profile in sorted(profile_dir.iterdir()): 125 print(profile.name) 126 127 ··· 159 160 def exit_with(result: bool): 161 exit(0 if result else 1)