mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-01 19:23:04 +00:00
Implement r2pm -e to edit package scripts
This commit is contained in:
parent
5cbd085902
commit
0ae427cd26
@ -17,6 +17,7 @@ static const char *helpmsg = \
|
||||
" -ci <pkgname> clean + install\n"\
|
||||
" -cp clean the user's home plugin directory\n"\
|
||||
" -d,doc [pkgname] show documentation and source for given package\n"\
|
||||
" -e [pkgname] edit using $EDITOR the given package script\n"\
|
||||
" -f force operation (Use in combination of -U, -i, -u, ..)\n"\
|
||||
" -gi <pkg> global install (system-wide)\n"\
|
||||
" -h display this help message\n"\
|
||||
@ -43,6 +44,7 @@ typedef struct r_r2pm_t {
|
||||
bool list;
|
||||
bool add;
|
||||
bool init;
|
||||
bool edit;
|
||||
bool run;
|
||||
bool doc;
|
||||
bool search;
|
||||
@ -152,6 +154,17 @@ static void r2pm_unregister(const char *pkg) {
|
||||
}
|
||||
}
|
||||
|
||||
static char *r2pm_pkgpath(const char *file) {
|
||||
char *dbdir = r2pm_dbdir ();
|
||||
char *path = r_str_newf ("%s/%s", dbdir, file);
|
||||
free (dbdir);
|
||||
if (r_file_exists (path)) {
|
||||
return path;
|
||||
}
|
||||
free (path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *r2pm_get(const char *file, const char *token, R2pmTokenType type) {
|
||||
char *res = NULL;
|
||||
char *dbdir = r2pm_dbdir ();
|
||||
@ -563,6 +576,28 @@ static int r2pm_install(RList *targets, bool uninstall, bool clean, bool force,
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int r2pm_edit(RList *targets) {
|
||||
RListIter *iter;
|
||||
const char *t;
|
||||
int rc = 0;
|
||||
r_list_foreach (targets, iter, t) {
|
||||
char *pkgpath = r2pm_pkgpath (t);
|
||||
if (pkgpath) {
|
||||
char *res = r_cons_editor (pkgpath, NULL);
|
||||
if (res) {
|
||||
printf ("%s\n", res);
|
||||
free (res);
|
||||
} else {
|
||||
printf ("%s\n", pkgpath);
|
||||
}
|
||||
} else {
|
||||
R_LOG_ERROR ("Unknown package");
|
||||
}
|
||||
free (pkgpath);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int r2pm_doc(RList *targets) {
|
||||
RListIter *iter;
|
||||
const char *t;
|
||||
@ -748,7 +783,7 @@ R_API int r_main_r2pm(int argc, const char **argv) {
|
||||
}
|
||||
R2Pm r2pm = {0};
|
||||
RGetopt opt;
|
||||
r_getopt_init (&opt, argc, argv, "aqcdiIhH:flgrpsuUv");
|
||||
r_getopt_init (&opt, argc, argv, "aqecdiIhH:flgrpsuUv");
|
||||
if (opt.ind < argc) {
|
||||
// TODO: fully deprecate during the 5.9.x cycle
|
||||
r2pm_actionword (&r2pm, argv[opt.ind]);
|
||||
@ -781,6 +816,9 @@ R_API int r_main_r2pm(int argc, const char **argv) {
|
||||
case 'u':
|
||||
r2pm.uninstall = true;
|
||||
break;
|
||||
case 'e':
|
||||
r2pm.edit = true;
|
||||
break;
|
||||
case 'f':
|
||||
r2pm.force = true;
|
||||
break;
|
||||
@ -895,6 +933,8 @@ R_API int r_main_r2pm(int argc, const char **argv) {
|
||||
res = r2pm_info ();
|
||||
} else if (r2pm.doc) {
|
||||
res = r2pm_doc (targets);
|
||||
} else if (r2pm.edit) {
|
||||
res = r2pm_edit (targets);
|
||||
} else if (r2pm.install) {
|
||||
res = r2pm_install (targets, r2pm.uninstall, r2pm.clean, r2pm.force, r2pm.global);
|
||||
} else if (r2pm.uninstall) {
|
||||
|
@ -16,6 +16,8 @@ Adds an external r2pm repository, no arguments to -a will list all the registere
|
||||
Show information about repository and installed packages
|
||||
.It Fl i Ar pkgname
|
||||
Install a package
|
||||
.It Fl e Ar pkgname
|
||||
Open the package script with your favourite editor
|
||||
.It Fl d Ar pkgname
|
||||
Show source code of the r2pm package
|
||||
.It Fl gi Ar pkgname
|
||||
|
Loading…
x
Reference in New Issue
Block a user