diff --git a/README.md b/README.md
index 1c70707..620a972 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ To install, simply move the generated executable to a directory that is in your
| u | Empty selection list |
| y | Copy files from selection list |
| v | Move files from selection list |
+| a | Rename Files in selection list |
| dD | Move files from selection list to trash |
| r | Reload |
| q | Quit |
@@ -55,8 +56,8 @@ a similar UI.
- [x] Show sorted directories before files
- [x] Fix the `G` keybinding
- [x] Add basic operations like deleting, copying etc.
-- [ ] Add rename functionality
-- [ ] Add option to show selected file
+- [x] Add rename functionality
+- [ ] Add option to show selection list
- [ ] Show current progress or status of copying files
- [ ] Show more info in the statusbar
- [ ] Add file previews
@@ -72,3 +73,4 @@ a similar UI.
- [x] Add open in terminal functionality
- [ ] Add color support
- [ ] Add config file for easy user customizability
+- [ ] Refactor Code
diff --git a/cf.c b/cf.c
index 4a3dccc..f217a3f 100644
--- a/cf.c
+++ b/cf.c
@@ -43,6 +43,11 @@ char cache_path[250];
*/
char clipboard_path[250];
+/*
+ stores the path for the temp clipboard file
+*/
+char temp_clipboard_path[250];
+
/*
stores the path for trash
*/
@@ -316,6 +321,65 @@ void copyFiles(char *present_dir)
fclose(f);
}
+
+/*
+ Rename files in clipboard
+*/
+void renameFiles()
+{
+ // For opening clipboard and temp_clipboard
+ FILE *f = fopen(clipboard_path, "r");
+ FILE *f2;
+
+ // For storing shell commands
+ char cmd[250];
+
+ // Buffers for reading clipboard and temp_clipboard
+ char buf[250];
+ char buf2[250];
+
+ // Counters used when reading clipboard and copylock_path
+ int count = 0;
+ int count2 = 0;
+
+ // Make `temp_clipboard`
+ sprintf(cmd,"cp %s %s",clipboard_path,temp_clipboard_path);
+ system(cmd);
+ // Exit curses mode and open temp_clipboard_path in vim
+ endwin();
+ sprintf(cmd,"vim %s",temp_clipboard_path);
+ system(cmd);
+
+ // Open clipboard and temp_clipboard and mv path from clipboard to adjacent entry in temp_clipboard
+ while(fgets(buf, 250, (FILE*) f))
+ {
+ count2=-1;
+ f2 = fopen(temp_clipboard_path,"r");
+ while(fgets(buf2, 250, (FILE*) f2))
+ {
+ count2++;
+ if(buf[strlen(buf)-1] == '\n')
+ buf[strlen(buf)-1] = '\0';
+ if(count2 == count)
+ {
+ if(buf2[strlen(buf2)-1] == '\n')
+ buf2[strlen(buf2)-1] = '\0';
+ sprintf(cmd,"mv \"%s\" \"%s\"",buf,buf2);
+ system(cmd);
+ }
+ }
+ count++;
+ fclose(f2);
+ }
+ fclose(f);
+ // Remove clipboard and temp_clipboard
+ sprintf(cmd,"rm %s %s",temp_clipboard_path,clipboard_path);
+ system(cmd);
+ // Start curses mode
+ refresh();
+}
+
+
/*
Move files in clipboard to `present_dir`
*/
@@ -369,6 +433,8 @@ int main(int argc, char* argv[])
}
// Set the path for the clipboard file
sprintf(clipboard_path,"%s/clipboard",cache_path);
+ // Set the path for the temp clipboard file
+ sprintf(temp_clipboard_path,"%s/clipboard.tmp",cache_path);
// Set the path for trash
sprintf(trash_path,"%s/.local/share/Trash/files",info->pw_dir);
@@ -738,6 +804,11 @@ int main(int argc, char* argv[])
refresh();
break;
+ // Bulk Rename
+ case 'a':
+ renameFiles();
+ break;
+
// Write to clipboard
case ' ':
strcpy(temp_dir,dir);