Added unicode support, set cfiles to open in current directory

pull/19/head
mananapr 5 years ago
parent 7d7b9d36fe
commit 813dae2bed

@ -1,6 +1,6 @@
CC = gcc CC = gcc
CFLAGS = -I. -Wall CFLAGS = -I. -Wall
LIBS = -lncurses LIBS = -lncursesw
SRCS = cf.c SRCS = cf.c
OBJS = $(SRCS: .c = .o) OBJS = $(SRCS: .c = .o)
PROG = cfiles PROG = cfiles

@ -6,11 +6,10 @@ minimal.
![screenshot](cf.png) ![screenshot](cf.png)
## Dependencies ## Dependencies
- ncurses - `ncurses`
- `cp`and `mv` for copying and moving - `cp`and `mv` for copying and moving
- `fzf` for searching - `fzf` for searching
- `w3mimgdisplay` or `Überzug` for image previews - `w3mimgdisplay` or `Überzug` for image previews
- `xdg-open` for opening programs
- `mediainfo` for viewing media info and file sizes - `mediainfo` for viewing media info and file sizes
- `sed` for removing a particular selection - `sed` for removing a particular selection
- `atool` for archive previews - `atool` for archive previews
@ -70,6 +69,10 @@ or press `m` in `cfiles` to add new bookmarks.
If `$XDG_CACHE_HOME` is not set, then `$HOME/.cache` is used. If `$XDG_CACHE_HOME` is not set, then `$HOME/.cache` is used.
## Opening Files
You can set `FILE_OPENER` in `config.h` to specify your file opening program. It is set to use `xdg-open` by default but you can change it to anything like `thunar`. macOS users need to set it to `/usr/bin/open`.
Note that you have to specify the full path of the binary.
## Image Previews ## Image Previews
You can either go with `w3mimgdisplay` or `Überzug` ([link](https://github.com/seebye/ueberzug)) for image previews. You can either go with `w3mimgdisplay` or `Überzug` ([link](https://github.com/seebye/ueberzug)) for image previews.
Each method has it's own pros and cons. Each method has it's own pros and cons.

30
cf.c

@ -23,6 +23,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <pwd.h> #include <pwd.h>
#include <locale.h>
#include "config.h" #include "config.h"
@ -147,6 +148,9 @@ int startx, starty, maxx, maxy;
*/ */
void init() void init()
{ {
// Set Locale (For wide characters)
setlocale(LC_ALL, "");
// Get UID of user // Get UID of user
uid_t uid = getuid(); uid_t uid = getuid();
// Get home directory of user from UID // Get home directory of user from UID
@ -213,10 +217,19 @@ void init()
mkdir(scripts_path, 0751); mkdir(scripts_path, 0751);
} }
// Set dir as $HOME // Set dir as current directory
allocSize = snprintf(NULL,0,"%s",info->pw_dir); char cwd[PATH_MAX];
dir = malloc(allocSize+1); if (getcwd(cwd, sizeof(cwd)) != NULL)
snprintf(dir,allocSize+1,"%s",info->pw_dir); {
allocSize = snprintf(NULL,0,"%s",cwd);
dir = malloc(allocSize+1);
snprintf(dir,allocSize+1,"%s",cwd);
}
else
{
printf("Couldn't open current directory");
exit(1);
}
} }
@ -583,8 +596,6 @@ void emptyClipboard()
void getImgPreview(char *filepath, int maxy, int maxx) void getImgPreview(char *filepath, int maxy, int maxx)
{ {
pid_t pid; pid_t pid;
FILE *fp;
pid = fork(); pid = fork();
if (pid == 0) if (pid == 0)
@ -819,8 +830,6 @@ void copyFiles(char *present_dir)
{ {
FILE *f = fopen(clipboard_path, "r"); FILE *f = fopen(clipboard_path, "r");
char buf[PATH_MAX]; char buf[PATH_MAX];
pid_t pid;
int status;
if(f == NULL) if(f == NULL)
{ {
return; return;
@ -955,7 +964,6 @@ void moveFiles(char *present_dir)
{ {
FILE *f = fopen(clipboard_path, "r"); FILE *f = fopen(clipboard_path, "r");
char buf[PATH_MAX]; char buf[PATH_MAX];
int status;
if(f == NULL) if(f == NULL)
{ {
return; return;
@ -996,10 +1004,10 @@ void init_windows()
*/ */
void displayStatus() void displayStatus()
{ {
wmove(status_win,1,1); wmove(status_win,1,0);
wattron(status_win, COLOR_PAIR(2)); wattron(status_win, COLOR_PAIR(2));
wprintw(status_win, "(%d/%d)", selection+1, len); wprintw(status_win, "(%d/%d)", selection+1, len);
wprintw(status_win, "\t%s", dir); wprintw(status_win, " %s", dir);
wattroff(status_win, COLOR_PAIR(2)); wattroff(status_win, COLOR_PAIR(2));
wattron(status_win, COLOR_PAIR(3)); wattron(status_win, COLOR_PAIR(3));
wprintw(status_win, "/%s", selected_file); wprintw(status_win, "/%s", selected_file);

Loading…
Cancel
Save