mirror of
https://github.com/dvorka/hstr.git
synced 2024-11-10 09:03:06 +08:00
Adding .zsh_history to .zhistory fallback #367
This commit is contained in:
parent
0c17ce178b
commit
24eba28330
5 changed files with 20 additions and 7 deletions
|
@ -49,15 +49,16 @@ char* get_history_file_name(void)
|
||||||
{
|
{
|
||||||
char* historyFile = getenv(ENV_VAR_HISTFILE);
|
char* historyFile = getenv(ENV_VAR_HISTFILE);
|
||||||
if(!historyFile || strlen(historyFile)==0) {
|
if(!historyFile || strlen(historyFile)==0) {
|
||||||
char* home = getenv(ENV_VAR_HOME);
|
|
||||||
char* fileHistory;
|
|
||||||
if(isZshParentShell()) {
|
if(isZshParentShell()) {
|
||||||
fileHistory=FILE_ZSH_HISTORY;
|
historyFile = get_home_file_path(FILE_ZSH_HISTORY);
|
||||||
|
if(access(historyFile, F_OK) == -1) {
|
||||||
|
free(historyFile);
|
||||||
|
historyFile = get_home_file_path(FILE_ZSH_ZHISTORY);
|
||||||
|
// ... fallback if this file doesn't exist?
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fileHistory=FILE_DEFAULT_HISTORY;
|
historyFile = get_home_file_path(FILE_DEFAULT_HISTORY);
|
||||||
}
|
}
|
||||||
historyFile = malloc(strlen(home) + 1 + strlen(fileHistory) + 1);
|
|
||||||
strcat(strcat(strcpy(historyFile, home), "/"), fileHistory);
|
|
||||||
} else {
|
} else {
|
||||||
// allocate so that this function always returns string to be freed
|
// allocate so that this function always returns string to be freed
|
||||||
// (getenv() returns pointer (no need to free), home is allocated (must be freed)
|
// (getenv() returns pointer (no need to free), home is allocated (must be freed)
|
||||||
|
|
|
@ -164,6 +164,14 @@ void get_hostname(int bufferSize, char *buffer)
|
||||||
strcpy(buffer, "localhost");
|
strcpy(buffer, "localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* get_home_file_path(char* filename)
|
||||||
|
{
|
||||||
|
char* home = getenv(ENV_VAR_HOME);
|
||||||
|
char* path = malloc(strlen(home) + 1 + strlen(filename) + 1);
|
||||||
|
strcat(strcat(strcpy(path, home), "/"), filename);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
void toggle_case(char *str, bool lowercase) {
|
void toggle_case(char *str, bool lowercase) {
|
||||||
if(str && strlen(str)>0) {
|
if(str && strlen(str)>0) {
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "hashset.h"
|
#include "hashset.h"
|
||||||
|
|
||||||
#define ENV_VAR_USER "USER"
|
#define ENV_VAR_USER "USER"
|
||||||
#define ENV_VAR_HOME "HOME"
|
|
||||||
|
|
||||||
#define FILE_HSTR_FAVORITES ".hstr_favorites"
|
#define FILE_HSTR_FAVORITES ".hstr_favorites"
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
|
||||||
|
#include "hstr_utils.h"
|
||||||
#include "hstr_regexp.h"
|
#include "hstr_regexp.h"
|
||||||
#include "radixsort.h"
|
#include "radixsort.h"
|
||||||
#include "hstr_favorites.h"
|
#include "hstr_favorites.h"
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
|
|
||||||
#define FILE_DEFAULT_HISTORY ".bash_history"
|
#define FILE_DEFAULT_HISTORY ".bash_history"
|
||||||
#define FILE_ZSH_HISTORY ".zsh_history"
|
#define FILE_ZSH_HISTORY ".zsh_history"
|
||||||
|
#define FILE_ZSH_ZHISTORY ".zhistory"
|
||||||
|
|
||||||
#define ZSH_HISTORY_ITEM_OFFSET 15
|
#define ZSH_HISTORY_ITEM_OFFSET 15
|
||||||
#define BASH_HISTORY_ITEM_OFFSET 0
|
#define BASH_HISTORY_ITEM_OFFSET 0
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define ENV_VAR_HOME "HOME"
|
||||||
|
|
||||||
#define UNUSED_ARG(expr) do { (void)(expr); } while (0)
|
#define UNUSED_ARG(expr) do { (void)(expr); } while (0)
|
||||||
|
|
||||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||||
|
@ -43,6 +45,7 @@ void tiocsti();
|
||||||
void fill_terminal_input(char* cmd, bool padding);
|
void fill_terminal_input(char* cmd, bool padding);
|
||||||
void reverse_char_pointer_array(char** array, unsigned length);
|
void reverse_char_pointer_array(char** array, unsigned length);
|
||||||
void get_hostname(int bufferSize, char* buffer);
|
void get_hostname(int bufferSize, char* buffer);
|
||||||
|
char* get_home_file_path(char* filename);
|
||||||
void toggle_case(char* str, bool lowercase);
|
void toggle_case(char* str, bool lowercase);
|
||||||
bool isZshParentShell(void);
|
bool isZshParentShell(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue