Revert "write last directory to a file configured in config.h"

This reverts commit a2321d5488.
This commit is contained in:
Night Kaly 2024-03-19 21:58:17 +00:00
parent a2321d5488
commit 1d702cd386
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE
3 changed files with 6 additions and 61 deletions

View file

@ -14,7 +14,7 @@ MANDIR = $(PREFIX)/share/man/man1
LDFLAGS = $(shell pkg-config --libs ncurses)
CFLAGS = -march=native -mtune=native -O3 -pipe -s -std=c99 -pedantic $(shell pkg-config --cflags ncurses) -Wall # -Wextra -Werror
SRC = ccc.c util.c file.c
SRC = ccc.c util.c file.c $(CONF)
$(TARGET): $(SRC)
$(CC) $(CFLAGS) $(LDFLAGS) $(SRC) -o $@

61
ccc.c
View file

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <linux/limits.h>
#include <dirent.h> /* directories etc. */
#include <sys/stat.h>
#include <errno.h>
@ -24,7 +25,6 @@ long add_file_stat(char *filepath, int ftype);
void highlight_current_line();
void show_file_content();
void edit_file();
int write_last_d();
void wpprintw(const char *line);
void init_windows();
void draw_border_title(WINDOW *window, bool active);
@ -101,10 +101,6 @@ int main(int argc, char** argv)
switch (ch) {
/* quit */
case 'q':
if (write_last_d() == -1) {
/* prompt user so error message can be shown to user */
getch();
}
endwin();
return 0;
@ -298,11 +294,7 @@ int main(int argc, char** argv)
delwin(preview_content);
delwin(panel);
endwin();
half_width = COLS / 2;
init_windows();
refresh();
populate_files(cwd, 0);
highlight_current_line();
break;
default:
break;
@ -328,13 +320,14 @@ void change_dir(const char *buf, int selection)
/*
* Recursively create directory by creating each subdirectory
* like mkdir -p
*/
int mkdir_p(const char *destdir)
{
char *path = memalloc(PATH_MAX * sizeof(char));
char *token = strtok(path, "/");
char dir_path[PATH_MAX] = "";
strcpy(path, destdir);
if (destdir[0] == '~') {
char *home = getenv("HOME");
if (home == NULL) {
@ -342,20 +335,16 @@ int mkdir_p(const char *destdir)
return -1;
}
/* replace ~ with home */
snprintf(path, PATH_MAX, "%s%s", home, destdir + 1);
} else {
strcpy(path, destdir);
memmove(path + strlen(home), path + 1, strlen(path));
memcpy(path, home, strlen(home));
}
/* fix first / not appearing in the string */
if (path[0] == '/')
strcat(dir_path, "/");
char *token = strtok(path, "/");
while (token != NULL) {
strcat(dir_path, token);
strcat(dir_path, "/");
if (mkdir(dir_path, 0755) == -1) {
struct stat st;
@ -686,46 +675,6 @@ void edit_file()
}
}
int write_last_d() {
#ifdef LAST_D
char *last_d = memalloc(PATH_MAX * sizeof(char));
strcpy(last_d, LAST_D);
#else
char *last_d = getenv("CCC_LAST_D");
#endif
if (last_d == NULL) {
wpprintw("Cannot get CCC_LAST_D variable, is it defined?");
return -1;
} else {
char *last_ddup = memalloc(PATH_MAX * sizeof(char));
char *home = getenv("HOME");
if (home == NULL) {
wpprintw("$HOME is not defined");
return -1;
}
/* replace ~ with home */
snprintf(last_ddup, PATH_MAX, "%s%s", home, last_d + 1);
char *last_d_dir = strrchr(last_d, '/');
if (last_d_dir != NULL) {
*last_d_dir = '\0'; /* truncate string */
}
mkdir_p(last_d);
char a[100];
sprintf(a, "notify-send 'aaa %s'", last_ddup);
system(a);
FILE *last_d_file = fopen(last_ddup, "w");
if (last_d_file == NULL) {
wpprintw("Cannot open last directory file");
return -1;
}
fwrite(cwd, strlen(cwd), sizeof(char), last_d_file);
fclose(last_d_file);
}
return 0;
}
/*
* Print line to the panel
*/

View file

@ -1,7 +1,6 @@
/* Settings */
#define PH 1 /* panel height */
#define JUMP_NUM 14 /* how long ctrl + u/d jump are */
#define PATH_MAX 4096
/* Calculate directories' sizes RECURSIVELY upon entering? */
#define DIRS_SIZE false
@ -26,9 +25,6 @@ In COLS:
/* Default text editor */
#define EDITOR "nvim"
/* File location to write last directory */
#define LAST_D "~/.cache/ccc/.ccc_d"
/* Keybindings */
#define CTRLD 0x04
#define ENTER 0xA