|
|
|
@ -193,16 +193,12 @@ int fileExists(char *file)
|
|
|
|
|
int compare (const void * a, const void * b )
|
|
|
|
|
{
|
|
|
|
|
// They store the full paths of the arguments
|
|
|
|
|
char temp_filepath1[250]="";
|
|
|
|
|
char temp_filepath2[250]="";
|
|
|
|
|
char temp_filepath1[250];
|
|
|
|
|
char temp_filepath2[250];
|
|
|
|
|
|
|
|
|
|
// Generate full paths
|
|
|
|
|
strcat(temp_filepath1,sort_dir);
|
|
|
|
|
strcat(temp_filepath1,"/");
|
|
|
|
|
strcat(temp_filepath1,*(char **)a);
|
|
|
|
|
strcat(temp_filepath2,sort_dir);
|
|
|
|
|
strcat(temp_filepath2,"/");
|
|
|
|
|
strcat(temp_filepath2,*(char **)b);
|
|
|
|
|
sprintf(temp_filepath1,"%s/%s", sort_dir, *(char **)a);
|
|
|
|
|
sprintf(temp_filepath2,"%s/%s", sort_dir, *(char **)b);
|
|
|
|
|
|
|
|
|
|
if(is_regular_file(temp_filepath1) == 0 && is_regular_file(temp_filepath2) == 1)
|
|
|
|
|
return -1;
|
|
|
|
@ -213,11 +209,41 @@ int compare (const void * a, const void * b )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Gets file MIME
|
|
|
|
|
*/
|
|
|
|
|
void getMIME(char *filepath, char mime[10])
|
|
|
|
|
{
|
|
|
|
|
char cmd[250];
|
|
|
|
|
char buf[20];
|
|
|
|
|
FILE *fp;
|
|
|
|
|
sprintf(cmd, "xdg-mime query filetype %s", filepath);
|
|
|
|
|
|
|
|
|
|
if((fp = popen(cmd,"r")) == NULL)
|
|
|
|
|
{
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(fgets(buf,250,fp) != NULL){}
|
|
|
|
|
strtok(buf,"/");
|
|
|
|
|
strcpy(mime,buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Opens a file using xdg-open
|
|
|
|
|
*/
|
|
|
|
|
void openFile(char *filepath)
|
|
|
|
|
{
|
|
|
|
|
char mime[10];
|
|
|
|
|
getMIME(filepath, mime);
|
|
|
|
|
if(strcmp(mime,"text") == 0)
|
|
|
|
|
{
|
|
|
|
|
char cmd[250];
|
|
|
|
|
sprintf(cmd,"vim %s",filepath);
|
|
|
|
|
endwin();
|
|
|
|
|
system(cmd);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pid_t pid;
|
|
|
|
|
pid = fork();
|
|
|
|
|
if (pid == 0)
|
|
|
|
@ -258,8 +284,6 @@ int checkClipboard(char *filepath)
|
|
|
|
|
*/
|
|
|
|
|
void writeClipboard(char *filepath)
|
|
|
|
|
{
|
|
|
|
|
if( checkClipboard(filepath) == 1 )
|
|
|
|
|
return;
|
|
|
|
|
FILE *f = fopen(clipboard_path,"a+");
|
|
|
|
|
if (f == NULL)
|
|
|
|
|
{
|
|
|
|
@ -272,6 +296,18 @@ void writeClipboard(char *filepath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Removes entry from clipboard
|
|
|
|
|
*/
|
|
|
|
|
void removeClipboard(char *filepath)
|
|
|
|
|
{
|
|
|
|
|
char cmd[250];
|
|
|
|
|
filepath[strlen(filepath)-1] = '\0';
|
|
|
|
|
sprintf(cmd,"sed -i '\\|^%s|d' %s", filepath, clipboard_path);
|
|
|
|
|
system(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Empties Clipboard
|
|
|
|
|
*/
|
|
|
|
@ -347,9 +383,11 @@ void getTextPreview(char *filepath, int maxy, int maxx)
|
|
|
|
|
// Don't Generate Preview if file size > 50MB
|
|
|
|
|
struct stat st;
|
|
|
|
|
stat(filepath, &st);
|
|
|
|
|
if(st.st_size > 50000000)
|
|
|
|
|
if(st.st_size > 10000000)
|
|
|
|
|
return;
|
|
|
|
|
FILE *fp = fopen(filepath,"r");
|
|
|
|
|
if(fp == NULL)
|
|
|
|
|
return;
|
|
|
|
|
char buf[250];
|
|
|
|
|
int t=0;
|
|
|
|
|
while(fgets(buf, 250, (FILE*) fp))
|
|
|
|
@ -471,6 +509,7 @@ int getNumberofFiles(char* directory)
|
|
|
|
|
len++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closedir (pDir);
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -478,7 +517,7 @@ int getNumberofFiles(char* directory)
|
|
|
|
|
/*
|
|
|
|
|
Stores all the file names in `char* directory` to `char *target[]`
|
|
|
|
|
*/
|
|
|
|
|
void getFiles(char* directory, char* target[])
|
|
|
|
|
int getFiles(char* directory, char* target[])
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
DIR *pDir;
|
|
|
|
@ -486,7 +525,7 @@ void getFiles(char* directory, char* target[])
|
|
|
|
|
|
|
|
|
|
pDir = opendir (directory);
|
|
|
|
|
if (pDir == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((pDirent = readdir(pDir)) != NULL) {
|
|
|
|
@ -501,6 +540,7 @@ void getFiles(char* directory, char* target[])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir (pDir);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -652,7 +692,7 @@ void init_windows()
|
|
|
|
|
void displayStatus()
|
|
|
|
|
{
|
|
|
|
|
wmove(status_win,1,1);
|
|
|
|
|
wprintw(status_win, "%s@%s\t%s", getenv("USER"), getenv("HOSTNAME"), dir);
|
|
|
|
|
wprintw(status_win, "(%d/%d)\t%s@%s\t%s", selection+1, len, getenv("USER"), getenv("HOSTNAME"), dir);
|
|
|
|
|
wrefresh(status_win);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -743,7 +783,8 @@ int main(int argc, char* argv[])
|
|
|
|
|
|
|
|
|
|
// Array of all the files in the current directory
|
|
|
|
|
char* directories[len];
|
|
|
|
|
getFiles(dir, directories);
|
|
|
|
|
int status;
|
|
|
|
|
status = getFiles(dir, directories);
|
|
|
|
|
// Sort files by name
|
|
|
|
|
strcpy(sort_dir,dir);
|
|
|
|
|
qsort(directories, len, sizeof (char*), compare);
|
|
|
|
@ -772,9 +813,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
int t = 0;
|
|
|
|
|
for( i=start; i<len; i++ )
|
|
|
|
|
{
|
|
|
|
|
strcpy(temp_dir,dir);
|
|
|
|
|
strcat(temp_dir,"/");
|
|
|
|
|
strcat(temp_dir,directories[i]);
|
|
|
|
|
sprintf(temp_dir,"%s/%s",dir,directories[i]);
|
|
|
|
|
if(i==selection)
|
|
|
|
|
wattron(current_win, A_STANDOUT);
|
|
|
|
|
else
|
|
|
|
@ -795,18 +834,16 @@ int main(int argc, char* argv[])
|
|
|
|
|
char prev_dir[250] = "";
|
|
|
|
|
|
|
|
|
|
// Get path of parent directory
|
|
|
|
|
strcat(prev_dir, dir);
|
|
|
|
|
sprintf(prev_dir,"%s",dir);
|
|
|
|
|
getParentPath(prev_dir);
|
|
|
|
|
|
|
|
|
|
// Get path of child directory
|
|
|
|
|
strcat(next_dir, dir);
|
|
|
|
|
strcat(next_dir, "/");
|
|
|
|
|
strcat(next_dir, directories[selection]);
|
|
|
|
|
sprintf(next_dir,"%s/%s", dir, directories[selection]);
|
|
|
|
|
// Stores number of files in the child directory
|
|
|
|
|
len_preview = getNumberofFiles(next_dir);
|
|
|
|
|
// Stores files in the child directory
|
|
|
|
|
char* next_directories[len_preview];
|
|
|
|
|
getFiles(next_dir, next_directories);
|
|
|
|
|
status = getFiles(next_dir, next_directories);
|
|
|
|
|
|
|
|
|
|
// Selection is a directory
|
|
|
|
|
strcpy(sort_dir,next_dir);
|
|
|
|
@ -1005,9 +1042,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
case KEY_RENAME:
|
|
|
|
|
if( access( clipboard_path, F_OK ) == -1 )
|
|
|
|
|
{
|
|
|
|
|
strcpy(temp_dir,dir);
|
|
|
|
|
strcat(temp_dir,"/");
|
|
|
|
|
strcat(temp_dir,directories[selection]);
|
|
|
|
|
sprintf(temp_dir, "%s/%s",dir,directories[selection]);
|
|
|
|
|
writeClipboard(temp_dir);
|
|
|
|
|
}
|
|
|
|
|
renameFiles();
|
|
|
|
@ -1015,9 +1050,10 @@ int main(int argc, char* argv[])
|
|
|
|
|
|
|
|
|
|
// Write to clipboard
|
|
|
|
|
case KEY_SEL:
|
|
|
|
|
strcpy(temp_dir,dir);
|
|
|
|
|
strcat(temp_dir,"/");
|
|
|
|
|
strcat(temp_dir,directories[selection]);
|
|
|
|
|
sprintf(temp_dir, "%s/%s", dir, directories[selection]);
|
|
|
|
|
if (checkClipboard(temp_dir) == 1)
|
|
|
|
|
removeClipboard(temp_dir);
|
|
|
|
|
else
|
|
|
|
|
writeClipboard(temp_dir);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|