mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
For links, set prefix instead of suffix
This commit is contained in:
parent
ca0a7b0558
commit
38414f4349
36
src/nnn.c
36
src/nnn.c
|
@ -452,7 +452,7 @@ static char * const utils[] = {
|
||||||
#define MSG_ARCHIVE_NAME 17
|
#define MSG_ARCHIVE_NAME 17
|
||||||
#define MSG_OPEN_WITH 18
|
#define MSG_OPEN_WITH 18
|
||||||
#define MSG_REL_PATH 19
|
#define MSG_REL_PATH 19
|
||||||
#define MSG_LINK_SUFFIX 20
|
#define MSG_LINK_PREFIX 20
|
||||||
#define MSG_COPY_NAME 21
|
#define MSG_COPY_NAME 21
|
||||||
#define MSG_CONTINUE 22
|
#define MSG_CONTINUE 22
|
||||||
#define MSG_SEL_MISSING 23
|
#define MSG_SEL_MISSING 23
|
||||||
|
@ -492,7 +492,7 @@ static const char * const messages[] = {
|
||||||
"archive name: ",
|
"archive name: ",
|
||||||
"open with: ",
|
"open with: ",
|
||||||
"relative path: ",
|
"relative path: ",
|
||||||
"link suffix [@ for none]: ",
|
"link prefix [@ for none]: ",
|
||||||
"copy name: ",
|
"copy name: ",
|
||||||
"\nPress Enter to continue",
|
"\nPress Enter to continue",
|
||||||
"open failed",
|
"open failed",
|
||||||
|
@ -2371,12 +2371,13 @@ static size_t mkpath(const char *dir, const char *name, char *out)
|
||||||
* Create symbolic/hard link(s) to file(s) in selection list
|
* Create symbolic/hard link(s) to file(s) in selection list
|
||||||
* Returns the number of links created, -1 on error
|
* Returns the number of links created, -1 on error
|
||||||
*/
|
*/
|
||||||
static int xlink(char *suffix, char *path, char *curfname, char *buf, int *presel, int type)
|
static int xlink(char *prefix, char *path, char *curfname, char *buf, int *presel, int type)
|
||||||
{
|
{
|
||||||
int count = 0, choice;
|
int count = 0, choice;
|
||||||
char *pbuf = pselbuf, *fname;
|
char *psel = pselbuf, *fname;
|
||||||
size_t pos = 0, len, r;
|
size_t pos = 0, len, r;
|
||||||
int (*link_fn)(const char *, const char *) = NULL;
|
int (*link_fn)(const char *, const char *) = NULL;
|
||||||
|
char lnpath[PATH_MAX];
|
||||||
|
|
||||||
choice = get_cur_or_sel();
|
choice = get_cur_or_sel();
|
||||||
if (!choice)
|
if (!choice)
|
||||||
|
@ -2388,11 +2389,10 @@ static int xlink(char *suffix, char *path, char *curfname, char *buf, int *prese
|
||||||
link_fn = &link;
|
link_fn = &link;
|
||||||
|
|
||||||
if (choice == 'c') {
|
if (choice == 'c') {
|
||||||
char lnpath[PATH_MAX];
|
r = xstrlcpy(buf, prefix, NAME_MAX + 1); /* Copy prefix */
|
||||||
|
xstrlcpy(buf + r - 1, curfname, NAME_MAX - r); /* Suffix target file name */
|
||||||
mkpath(path, curfname, buf);
|
mkpath(path, buf, lnpath); /* Generate link path */
|
||||||
r = mkpath(path, curfname, lnpath);
|
mkpath(path, curfname, buf); /* Generate target file path */
|
||||||
xstrlcpy(lnpath + r - 1, suffix, PATH_MAX - r - 1);
|
|
||||||
|
|
||||||
if (!link_fn(buf, lnpath))
|
if (!link_fn(buf, lnpath))
|
||||||
return 1; /* One link created */
|
return 1; /* One link created */
|
||||||
|
@ -2402,16 +2402,18 @@ static int xlink(char *suffix, char *path, char *curfname, char *buf, int *prese
|
||||||
}
|
}
|
||||||
|
|
||||||
while (pos < selbufpos) {
|
while (pos < selbufpos) {
|
||||||
len = strlen(pbuf);
|
len = strlen(psel);
|
||||||
fname = xbasename(pbuf);
|
fname = xbasename(psel);
|
||||||
r = mkpath(path, fname, buf);
|
|
||||||
xstrlcpy(buf + r - 1, suffix, PATH_MAX - r - 1);
|
|
||||||
|
|
||||||
if (!link_fn(pbuf, buf))
|
r = xstrlcpy(buf, prefix, NAME_MAX + 1); /* Copy prefix */
|
||||||
|
xstrlcpy(buf + r - 1, fname, NAME_MAX - r); /* Suffix target file name */
|
||||||
|
mkpath(path, buf, lnpath); /* Generate link path */
|
||||||
|
|
||||||
|
if (!link_fn(psel, lnpath))
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
pos += len + 1;
|
pos += len + 1;
|
||||||
pbuf += len + 1;
|
psel += len + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
@ -5173,7 +5175,7 @@ nochange:
|
||||||
if (r == 'f' || r == 'd')
|
if (r == 'f' || r == 'd')
|
||||||
tmp = xreadline(NULL, messages[MSG_REL_PATH]);
|
tmp = xreadline(NULL, messages[MSG_REL_PATH]);
|
||||||
else if (r == 's' || r == 'h')
|
else if (r == 's' || r == 'h')
|
||||||
tmp = xreadline(NULL, messages[MSG_LINK_SUFFIX]);
|
tmp = xreadline(NULL, messages[MSG_LINK_PREFIX]);
|
||||||
else
|
else
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -5281,7 +5283,7 @@ nochange:
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
xstrlcpy(lastname, tmp, NAME_MAX + 1);
|
||||||
} else {
|
} else { /* SEL_NEW */
|
||||||
close(fd); /* Use fd as tmp var */
|
close(fd); /* Use fd as tmp var */
|
||||||
presel = 0;
|
presel = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue