Skip to content

Commit

Permalink
Add default answer for files overwrite (mostly 'c' and 'm' commands)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Dec 22, 2024
1 parent 1b7d296 commit ee334ec
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion misc/clifmrc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
# confirmation prompts. Each field has two values separated by a colon (':').
# The left value indicates the command (for the time being only the following
# left values are supported):
# 'o': overwrite files (mostly 'c' and 'm' commands)
# 'r': remove ('r' command)
# 't': trash ('t' command)
# 'R': bulk rename ('br' command)
Expand All @@ -383,7 +384,7 @@
# 'y' or 'n'.
# If unset (or set to any other value), no default answer will be used.
# For example, to set 'n' as the default answer for the 'r' command and
# trash, and 'y' for everything else: "r:n,t:n,d:y".
# 'overwrite files', and 'y' for everything else: "r:n,o:n,d:y".
;DefaultAnswer=""

# How should the 'l' command create symbolic links. Possible values:
Expand Down
4 changes: 2 additions & 2 deletions src/bulk_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ rename_file(char *oldpath, char *newpath)
if (lstat(npath, &a) == 0) {
xerror("br: '%s': %s\n", newpath, strerror(EEXIST));
if (rl_get_y_or_n(_("Overwrite this file?"),
conf.default_answer.remove) == 0) {
conf.default_answer.overwrite) == 0) {
free(npath);
return EEXIST;
}
Expand Down Expand Up @@ -380,7 +380,7 @@ check_dups(FILE *fp)
free(fnames);

if (dups > 0 && rl_get_y_or_n(_("Continue?"),
conf.default_answer.remove) == 0) {
conf.default_answer.overwrite) == 0) {
return dups;
}

Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3019,6 +3019,7 @@ set_default_answer(const char *str)
switch (*str) {
case 'd': conf.default_answer.default_ = str[2]; break;
case 'D': conf.default_answer.default_all = str[2]; break;
case 'o': conf.default_answer.overwrite = str[2]; break;
case 'r': conf.default_answer.remove = str[2]; break;
case 'R': conf.default_answer.bulk_rename = str[2]; break;
case 't': conf.default_answer.trash = str[2]; break;
Expand Down
6 changes: 3 additions & 3 deletions src/file_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ symlink_file(char **args)
if (lstat(link_name, &a) != -1 && S_ISLNK(a.st_mode)) {
printf("link: '%s': %s\n", link_name, strerror(EEXIST));
if (rl_get_y_or_n(_("Overwrite this file?"),
conf.default_answer.remove) == 0) {
conf.default_answer.overwrite) == 0) {
return FUNC_SUCCESS;
}

Expand Down Expand Up @@ -1694,7 +1694,7 @@ check_overwrite(char **args, const int force, size_t *skipped)
if (p && lstat(p, &a) != -1) {
snprintf(msg, sizeof(msg), "%s: '%s': Overwrite this file?",
cmd_name, p);
if (rl_get_y_or_n(msg, conf.default_answer.remove) == 0) {
if (rl_get_y_or_n(msg, conf.default_answer.overwrite) == 0) {
free(p);
return 0;
}
Expand Down Expand Up @@ -1730,7 +1730,7 @@ check_overwrite(char **args, const int force, size_t *skipped)

snprintf(msg, sizeof(msg), "%s: '%s': Overwrite this file?",
cmd_name, buf);
if (rl_get_y_or_n(msg, conf.default_answer.remove) == 0) {
if (rl_get_y_or_n(msg, conf.default_answer.overwrite) == 0) {
/* Nullify this entry. It will be skipped later. */
*args[i] = '\0';
(*skipped)++;
Expand Down
3 changes: 2 additions & 1 deletion src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,10 @@ struct default_answer_t {
char remove;
char trash;
char bulk_rename;
char overwrite;
char default_;
char default_all;
char pad[3];
char pad[2];
};

/* User settings (mostly from the config file) */
Expand Down
1 change: 1 addition & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ init_conf_struct(void)
conf.default_answer.remove = DEF_ANSWER_REMOVE;
conf.default_answer.trash = DEF_ANSWER_TRASH;
conf.default_answer.bulk_rename = DEF_ANSWER_BULK_RENAME;
conf.default_answer.overwrite = DEF_ANSWER_OVERWRITE;
conf.default_answer.default_ = DEF_ANSWER_DEFAULT;
conf.default_answer.default_all = DEF_ANSWER_DEFAULT_ALL;
conf.desktop_notifications = UNSET;
Expand Down
7 changes: 4 additions & 3 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,10 @@ ws2=31:ws3=38;5;228:ws4=32:ws5=36:ws6=38;5;214:ws7=35:ws8=2;37:xf=1;31:xs=32:"

/* Default options */
/* Default answers for confirmation prompts: 0 (none), 'y', or 'n' */
#define DEF_ANSWER_REMOVE 0
#define DEF_ANSWER_TRASH 0
#define DEF_ANSWER_BULK_RENAME 0
#define DEF_ANSWER_REMOVE 0 /* 'r' command */
#define DEF_ANSWER_TRASH 0 /* 't' command */
#define DEF_ANSWER_BULK_RENAME 0 /* 'br' command */
#define DEF_ANSWER_OVERWRITE 0 /* 'c' and 'm' commands mostly */
#define DEF_ANSWER_DEFAULT 0 /* Remaining prompts */
#define DEF_ANSWER_DEFAULT_ALL 0 /* All prompts (overrides the above ones) */

Expand Down

0 comments on commit ee334ec

Please sign in to comment.