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
CFLAGS = -I. -Wall
LIBS = -lncurses
LIBS = -lncursesw
SRCS = cf.c
OBJS = $(SRCS: .c = .o)
PROG = cfiles

@ -6,11 +6,10 @@ minimal.
![screenshot](cf.png)
## Dependencies
- ncurses
- `ncurses`
- `cp`and `mv` for copying and moving
- `fzf` for searching
- `w3mimgdisplay` or `Überzug` for image previews
- `xdg-open` for opening programs
- `mediainfo` for viewing media info and file sizes
- `sed` for removing a particular selection
- `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.
## 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
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.

30
cf.c

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

Loading…
Cancel
Save