diff --git a/app/flatpak-builtins-add-remote.c b/app/flatpak-builtins-add-remote.c index 4b41a3ee..4ad39ba3 100644 --- a/app/flatpak-builtins-add-remote.c +++ b/app/flatpak-builtins-add-remote.c @@ -202,7 +202,6 @@ flatpak_builtin_add_remote (int argc, char **argv, g_autofree char *remote_url = NULL; const char *remote_name; const char *url_or_path; - g_autofree char *prio_as_string = NULL; g_autoptr(GKeyFile) config = NULL; g_autoptr(GBytes) gpg_data = NULL; @@ -265,6 +264,32 @@ flatpak_builtin_add_remote (int argc, char **argv, return flatpak_dir_modify_remote (dir, remote_name, config, gpg_data, cancellable, error); } +gboolean +flatpak_complete_add_remote (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) dir = NULL; + + context = g_option_context_new (""); + g_option_context_add_main_entries (context, common_options, NULL); + if (!flatpak_option_context_parse (context, add_options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, common_options); + flatpak_complete_options (completion, add_options); + flatpak_complete_options (completion, user_entries); + + break; + } + + return TRUE; +} + gboolean flatpak_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable, GError **error) { @@ -300,3 +325,38 @@ flatpak_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable, return flatpak_dir_modify_remote (dir, remote_name, config, gpg_data, cancellable, error); } + +gboolean +flatpak_complete_modify_remote (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) dir = NULL; + int i; + + context = g_option_context_new (""); + g_option_context_add_main_entries (context, common_options, NULL); + if (!flatpak_option_context_parse (context, modify_options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* REMOTE */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, common_options); + flatpak_complete_options (completion, modify_options); + flatpak_complete_options (completion, user_entries); + + { + g_auto(GStrv) remotes = flatpak_dir_list_remotes (dir, NULL, NULL); + if (remotes == NULL) + return FALSE; + for (i = 0; remotes[i] != NULL; i++) + flatpak_complete_word (completion, "%s ", remotes[i]); + } + + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build-bundle.c b/app/flatpak-builtins-build-bundle.c index fd23c234..8fd8ef0c 100644 --- a/app/flatpak-builtins-build-bundle.c +++ b/app/flatpak-builtins-build-bundle.c @@ -945,3 +945,32 @@ flatpak_builtin_build_bundle (int argc, char **argv, GCancellable *cancellable, return TRUE; } + +gboolean +flatpak_complete_build_bundle (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* LOCATION */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + + case 2: /* FILENAME */ + flatpak_complete_file (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build-export.c b/app/flatpak-builtins-build-export.c index 47cac9f8..3f3093d2 100644 --- a/app/flatpak-builtins-build-export.c +++ b/app/flatpak-builtins-build-export.c @@ -462,3 +462,32 @@ out: return ret; } + +gboolean +flatpak_complete_build_export (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* LOCATION */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + + case 2: /* DIR */ + flatpak_complete_dir (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build-finish.c b/app/flatpak-builtins-build-finish.c index 9038d079..0ea40fa0 100644 --- a/app/flatpak-builtins-build-finish.c +++ b/app/flatpak-builtins-build-finish.c @@ -403,3 +403,33 @@ flatpak_builtin_build_finish (int argc, char **argv, GCancellable *cancellable, return TRUE; } + +gboolean +flatpak_complete_build_finish (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakContext) arg_context = NULL; + + context = g_option_context_new (""); + + arg_context = flatpak_context_new (); + g_option_context_add_group (context, flatpak_context_get_options (arg_context)); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* DIR */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + flatpak_context_complete (arg_context, completion); + + flatpak_complete_dir (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build-import-bundle.c b/app/flatpak-builtins-build-import-bundle.c index 8072f083..e682841e 100644 --- a/app/flatpak-builtins-build-import-bundle.c +++ b/app/flatpak-builtins-build-import-bundle.c @@ -314,3 +314,32 @@ if (opt_oci) return TRUE; } + +gboolean +flatpak_complete_build_import (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* LOCATION */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + + case 2: /* FILENAME */ + flatpak_complete_file (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build-init.c b/app/flatpak-builtins-build-init.c index ed34ba16..190394ec 100644 --- a/app/flatpak-builtins-build-init.c +++ b/app/flatpak-builtins-build-init.c @@ -266,3 +266,98 @@ flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GE return TRUE; } + +gboolean +flatpak_complete_build_init (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) user_dir = NULL; + g_autoptr(FlatpakDir) system_dir = NULL; + g_autoptr(GError) error = NULL; + int i; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* DIR */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + + case 2: /* APP */ + break; + + case 3: /* RUNTIME */ + case 4: /* SDK */ + user_dir = flatpak_dir_get_user (); + { + g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, NULL, NULL, opt_arch, + FALSE, TRUE, &error); + if (refs == NULL) + flatpak_completion_debug ("find local refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[1]); + } + } + + system_dir = flatpak_dir_get_system (); + { + g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, NULL, NULL, opt_arch, + FALSE, TRUE, &error); + if (refs == NULL) + flatpak_completion_debug ("find local refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[1]); + } + } + + break; + + case 5: /* BRANCH */ + user_dir = flatpak_dir_get_user (); + { + g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, completion->argv[3], NULL, opt_arch, + FALSE, TRUE, &error); + if (refs == NULL) + flatpak_completion_debug ("find local refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[3]); + } + } + + system_dir = flatpak_dir_get_system (); + { + g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, completion->argv[3], NULL, opt_arch, + FALSE, TRUE, &error); + if (refs == NULL) + flatpak_completion_debug ("find local refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[3]); + } + } + + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build-sign.c b/app/flatpak-builtins-build-sign.c index 702580f1..caf08cf4 100644 --- a/app/flatpak-builtins-build-sign.c +++ b/app/flatpak-builtins-build-sign.c @@ -115,3 +115,34 @@ flatpak_builtin_build_sign (int argc, char **argv, GCancellable *cancellable, GE return TRUE; } + +gboolean +flatpak_complete_build_sign (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* LOCATION */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + + case 2: /* ID */ + break; + + case 3: /* BRANCH */ + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-build.c b/app/flatpak-builtins-build.c index fef3a098..26e988e4 100644 --- a/app/flatpak-builtins-build.c +++ b/app/flatpak-builtins-build.c @@ -233,3 +233,28 @@ flatpak_builtin_build (int argc, char **argv, GCancellable *cancellable, GError /* Not actually reached... */ return TRUE; } + +gboolean +flatpak_complete_build (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* DIR */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-delete-remote.c b/app/flatpak-builtins-delete-remote.c index f03b892d..78dc34c8 100644 --- a/app/flatpak-builtins-delete-remote.c +++ b/app/flatpak-builtins-delete-remote.c @@ -63,3 +63,36 @@ flatpak_builtin_delete_remote (int argc, char **argv, GCancellable *cancellable, return TRUE; } + +gboolean +flatpak_complete_delete_remote (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) dir = NULL; + int i; + + context = g_option_context_new (""); + if (!flatpak_option_context_parse (context, delete_options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* REMOTE */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, delete_options); + flatpak_complete_options (completion, user_entries); + + { + g_auto(GStrv) remotes = flatpak_dir_list_remotes (dir, NULL, NULL); + if (remotes == NULL) + return FALSE; + for (i = 0; remotes[i] != NULL; i++) + flatpak_complete_word (completion, "%s ", remotes[i]); + } + + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-document.c b/app/flatpak-builtins-document.c index e636061f..3cee8c5e 100644 --- a/app/flatpak-builtins-document.c +++ b/app/flatpak-builtins-document.c @@ -184,3 +184,28 @@ flatpak_builtin_export_file (int argc, char **argv, return TRUE; } + +gboolean +flatpak_complete_export_file (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* FILE */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_file (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-info.c b/app/flatpak-builtins-info.c index 525227c7..2889aa9a 100644 --- a/app/flatpak-builtins-info.c +++ b/app/flatpak-builtins-info.c @@ -173,7 +173,6 @@ flatpak_complete_info (FlatpakCompletion *completion) g_autoptr(FlatpakDir) user_dir = NULL; g_autoptr(FlatpakDir) system_dir = NULL; g_autoptr(GError) error = NULL; - g_auto(GStrv) refs = NULL; int i; context = g_option_context_new (""); diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index 5b856985..3c12b478 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -204,9 +204,7 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro const char *name; const char *branch = NULL; g_autofree char *ref = NULL; - g_autofree char *installed_ref = NULL; gboolean is_app; - g_autoptr(GError) my_error = NULL; g_autoptr(GFile) deploy_base = NULL; context = g_option_context_new ("REPOSITORY NAME [BRANCH] - Install an application or runtime"); diff --git a/app/flatpak-builtins-list-remotes.c b/app/flatpak-builtins-list-remotes.c index 70c9afbb..c1cfeb50 100644 --- a/app/flatpak-builtins-list-remotes.c +++ b/app/flatpak-builtins-list-remotes.c @@ -147,3 +147,27 @@ flatpak_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable, return TRUE; } + +gboolean +flatpak_complete_list_remotes (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) dir = NULL; + + context = g_option_context_new (""); + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* REMOTE */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + flatpak_complete_options (completion, user_entries); + + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-ls-remote.c b/app/flatpak-builtins-ls-remote.c index ed1b62ae..d2f549be 100644 --- a/app/flatpak-builtins-ls-remote.c +++ b/app/flatpak-builtins-ls-remote.c @@ -145,3 +145,36 @@ flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr return TRUE; } + +gboolean +flatpak_complete_ls_remote (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) dir = NULL; + int i; + + context = g_option_context_new (""); + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* REMOTE */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + flatpak_complete_options (completion, user_entries); + + { + g_auto(GStrv) remotes = flatpak_dir_list_remotes (dir, NULL, NULL); + if (remotes == NULL) + return FALSE; + for (i = 0; remotes[i] != NULL; i++) + flatpak_complete_word (completion, "%s ", remotes[i]); + } + + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-make-current.c b/app/flatpak-builtins-make-current.c index be623f21..2baa7f83 100644 --- a/app/flatpak-builtins-make-current.c +++ b/app/flatpak-builtins-make-current.c @@ -85,3 +85,56 @@ flatpak_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab return TRUE; } + +gboolean +flatpak_complete_make_current_app (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) dir = NULL; + g_autoptr(GError) error = NULL; + g_auto(GStrv) refs = NULL; + int i; + + context = g_option_context_new (""); + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* NAME */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + flatpak_complete_options (completion, user_entries); + + refs = flatpak_dir_find_installed_refs (dir, NULL, NULL, opt_arch, + TRUE, FALSE, &error); + if (refs == NULL) + flatpak_completion_debug ("find installed refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[1]); + } + break; + + case 2: /* Branch */ + refs = flatpak_dir_find_installed_refs (dir, completion->argv[1], NULL, opt_arch, + TRUE, FALSE, &error); + if (refs == NULL) + flatpak_completion_debug ("find installed refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[3]); + } + break; + + default: + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-override.c b/app/flatpak-builtins-override.c index 5061179d..9a5ceaa3 100644 --- a/app/flatpak-builtins-override.c +++ b/app/flatpak-builtins-override.c @@ -92,3 +92,65 @@ flatpak_builtin_override (int argc, char **argv, GCancellable *cancellable, GErr return TRUE; } + +gboolean +flatpak_complete_override (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + g_autoptr(FlatpakDir) user_dir = NULL; + g_autoptr(FlatpakDir) system_dir = NULL; + g_autoptr(GError) error = NULL; + int i; + g_autoptr(FlatpakContext) arg_context = NULL; + + context = g_option_context_new (""); + + arg_context = flatpak_context_new (); + g_option_context_add_group (context, flatpak_context_get_options (arg_context)); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* NAME */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + flatpak_context_complete (arg_context, completion); + + user_dir = flatpak_dir_get_user (); + { + g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, NULL, NULL, NULL, + TRUE, FALSE, &error); + if (refs == NULL) + flatpak_completion_debug ("find local refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[1]); + } + } + + system_dir = flatpak_dir_get_system (); + { + g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, NULL, NULL, NULL, + TRUE, FALSE, &error); + if (refs == NULL) + flatpak_completion_debug ("find local refs error: %s", error->message); + for (i = 0; refs != NULL && refs[i] != NULL; i++) + { + g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); + if (parts) + flatpak_complete_word (completion, "%s ", parts[1]); + } + } + + break; + + } + + return TRUE; +} diff --git a/app/flatpak-builtins-repo-update.c b/app/flatpak-builtins-repo-update.c index 9efad5a8..0c170e56 100644 --- a/app/flatpak-builtins-repo-update.c +++ b/app/flatpak-builtins-repo-update.c @@ -214,3 +214,29 @@ flatpak_builtin_build_update_repo (int argc, char **argv, return TRUE; } + + +gboolean +flatpak_complete_build_update_repo (FlatpakCompletion *completion) +{ + g_autoptr(GOptionContext) context = NULL; + + context = g_option_context_new (""); + + if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, + FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL)) + return FALSE; + + switch (completion->argc) + { + case 0: + case 1: /* LOCATION */ + flatpak_complete_options (completion, global_entries); + flatpak_complete_options (completion, options); + + flatpak_complete_dir (completion); + break; + } + + return TRUE; +} diff --git a/app/flatpak-builtins-uninstall.c b/app/flatpak-builtins-uninstall.c index 071a65d8..636f1175 100644 --- a/app/flatpak-builtins-uninstall.c +++ b/app/flatpak-builtins-uninstall.c @@ -122,7 +122,7 @@ flatpak_complete_uninstall (FlatpakCompletion *completion) refs = flatpak_dir_find_installed_refs (dir, NULL, NULL, opt_arch, opt_app, opt_runtime, &error); if (refs == NULL) - flatpak_completion_debug ("find local refs error: %s", error->message); + flatpak_completion_debug ("find installed refs error: %s", error->message); for (i = 0; refs != NULL && refs[i] != NULL; i++) { g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); @@ -135,7 +135,7 @@ flatpak_complete_uninstall (FlatpakCompletion *completion) refs = flatpak_dir_find_installed_refs (dir, completion->argv[1], NULL, opt_arch, opt_app, opt_runtime, &error); if (refs == NULL) - flatpak_completion_debug ("find remote refs error: %s", error->message); + flatpak_completion_debug ("find installed refs error: %s", error->message); for (i = 0; refs != NULL && refs[i] != NULL; i++) { g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL); diff --git a/app/flatpak-main.c b/app/flatpak-main.c index d5423aac..0bf627c8 100644 --- a/app/flatpak-main.c +++ b/app/flatpak-main.c @@ -60,27 +60,27 @@ static FlatpakCommand commands[] = { { "\n Running applications" }, { "run", "Run an application", flatpak_builtin_run, flatpak_complete_run }, - { "override", "Override permissions for an application", flatpak_builtin_override }, - { "export-file", "Grant an application access to a specific file", flatpak_builtin_export_file}, - { "make-current", "Specify default version to run", flatpak_builtin_make_current_app}, + { "override", "Override permissions for an application", flatpak_builtin_override, flatpak_complete_override}, + { "export-file", "Grant an application access to a specific file", flatpak_builtin_export_file, flatpak_complete_export_file}, + { "make-current", "Specify default version to run", flatpak_builtin_make_current_app, flatpak_complete_make_current_app}, { "enter", "Enter the namespace of a running application", flatpak_builtin_enter }, { "\n Manage remote repositories" }, - { "remote-add", "Add a new remote repository (by URL)", flatpak_builtin_add_remote }, - { "remote-modify", "Modify properties of a configured remote", flatpak_builtin_modify_remote}, - { "remote-delete", "Delete a configured remote", flatpak_builtin_delete_remote}, - { "remote-list", "List all configured remotes", flatpak_builtin_list_remotes}, - { "remote-ls", "List contents of a configured remote", flatpak_builtin_ls_remote }, + { "remote-add", "Add a new remote repository (by URL)", flatpak_builtin_add_remote, flatpak_complete_add_remote }, + { "remote-modify", "Modify properties of a configured remote", flatpak_builtin_modify_remote, flatpak_complete_modify_remote }, + { "remote-delete", "Delete a configured remote", flatpak_builtin_delete_remote, flatpak_complete_delete_remote }, + { "remote-list", "List all configured remotes", flatpak_builtin_list_remotes, flatpak_complete_list_remotes }, + { "remote-ls", "List contents of a configured remote", flatpak_builtin_ls_remote, flatpak_complete_ls_remote }, { "\n Build applications" }, - { "build-init", "Initialize a directory for building", flatpak_builtin_build_init }, - { "build", "Run a build command inside the build dir", flatpak_builtin_build }, - { "build-finish", "Finish a build dir for export", flatpak_builtin_build_finish }, - { "build-export", "Export a build dir to a repository", flatpak_builtin_build_export }, - { "build-bundle", "Create a bundle file from a build directory", flatpak_builtin_build_bundle }, - { "build-import-bundle", "Import a bundle file", flatpak_builtin_build_import }, - { "build-sign", "Sign an application or runtime", flatpak_builtin_build_sign }, - { "build-update-repo", "Update the summary file in a repository", flatpak_builtin_build_update_repo }, + { "build-init", "Initialize a directory for building", flatpak_builtin_build_init, flatpak_complete_build_init }, + { "build", "Run a build command inside the build dir", flatpak_builtin_build, flatpak_complete_build }, + { "build-finish", "Finish a build dir for export", flatpak_builtin_build_finish, flatpak_complete_build_finish }, + { "build-export", "Export a build dir to a repository", flatpak_builtin_build_export, flatpak_complete_build_export }, + { "build-bundle", "Create a bundle file from a build directory", flatpak_builtin_build_bundle, flatpak_complete_build_bundle }, + { "build-import-bundle", "Import a bundle file", flatpak_builtin_build_import, flatpak_complete_build_import }, + { "build-sign", "Sign an application or runtime", flatpak_builtin_build_sign, flatpak_complete_build_sign }, + { "build-update-repo", "Update the summary file in a repository", flatpak_builtin_build_update_repo, flatpak_complete_build_update_repo }, { NULL } }; @@ -354,7 +354,6 @@ complete (int argc, char **argv) { FlatpakCommand *command; - g_autofree char *initial_completion_line = NULL; FlatpakCompletion *completion; const char *command_name = NULL; diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 99a85f6e..b3b46874 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -3987,9 +3987,7 @@ flatpak_dir_find_remote_refs (FlatpakDir *self, GError **error) { g_autofree char *refspec_prefix = NULL; - g_autofree char *remote_ref = NULL; g_autoptr(GHashTable) remote_refs = NULL; - g_autoptr(GError) my_error = NULL; GPtrArray *matched_refs; if (!flatpak_dir_ensure_repo (self, NULL, error)) @@ -4111,9 +4109,7 @@ flatpak_dir_find_installed_refs (FlatpakDir *self, gboolean runtime, GError **error) { - g_autofree char *local_ref = NULL; g_autoptr(GHashTable) local_refs = NULL; - g_autoptr(GError) my_error = NULL; GPtrArray *matched_refs; local_refs = flatpak_dir_get_all_installed_refs (self, app, runtime, error); diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index 6d7c7be0..8dd7c090 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -3080,6 +3080,20 @@ is_word_separator (char c) return g_ascii_isspace (c); } +void +flatpak_complete_file (FlatpakCompletion *completion) +{ + flatpak_completion_debug ("completing FILE"); + g_print ("%s\n", "__FLATPAK_FILE"); +} + +void +flatpak_complete_dir (FlatpakCompletion *completion) +{ + flatpak_completion_debug ("completing DIR"); + g_print ("%s\n", "__FLATPAK_DIR"); +} + void flatpak_complete_word (FlatpakCompletion *completion, char *format, ...) @@ -3144,6 +3158,10 @@ flatpak_complete_options (FlatpakCompletion *completion, for (i = 0; flatpak_context_sockets[i] != NULL; i++) flatpak_complete_word (completion, "%s%s ", prefix, flatpak_context_sockets[i]); } + else if (strcmp (e->arg_description, "FILE") == 0) + { + flatpak_complete_file (completion); + } else flatpak_complete_word (completion, "%s", prefix); } diff --git a/common/flatpak-utils.h b/common/flatpak-utils.h index bf40fd92..c45b49f5 100644 --- a/common/flatpak-utils.h +++ b/common/flatpak-utils.h @@ -374,6 +374,8 @@ FlatpakCompletion *flatpak_completion_new (const char *arg_line, void flatpak_complete_word (FlatpakCompletion *completion, char *format, ...); +void flatpak_complete_file (FlatpakCompletion *completion); +void flatpak_complete_dir (FlatpakCompletion *completion); void flatpak_complete_options (FlatpakCompletion *completion, GOptionEntry *entries); void flatpak_completion_free (FlatpakCompletion *completion); diff --git a/completion/flatpak b/completion/flatpak index 10cbdd89..ee4605ec 100755 --- a/completion/flatpak +++ b/completion/flatpak @@ -6,7 +6,28 @@ __flatpak() { local IFS=$'\n' local cur=`_get_cword :` - COMPREPLY=($(flatpak complete "${COMP_LINE}" "${COMP_POINT}" "${cur}")) + RES=($(flatpak complete "${COMP_LINE}" "${COMP_POINT}" "${cur}")) + + COMPREPLY=() + for i in "${!RES[@]}"; do + if [[ "${RES[$i]}" = "__FLATPAK_FILE" ]]; then + if [[ "${cur}" = "=" ]]; then + CUR="" + else + CUR="${cur}" + fi + COMPREPLY=("${COMPREPLY[@]}" $(compgen -f -- "${CUR}") ) + elif [[ "${RES[$i]}" = "__FLATPAK_DIR" ]]; then + if [[ "${cur}" = "=" ]]; then + CUR="" + else + CUR="${cur}" + fi + COMPREPLY=("${COMPREPLY[@]}" $(compgen -d -- "${CUR}") ) + else + COMPREPLY=("${COMPREPLY[@]}" "${RES[$i]}") + fi + done } ####################################################################################################