History
Collection of functions for managing the shell’s command history.
- Author
pulgamecanica
Typedefs
-
typedef struct s_shell t_shell
Functions
-
void history_init(t_shell *shell)
Initialize the history subsystem.
Forward declaration to avoid circular dependency with 42sh.h
This sets up readline’s history handling and loads the history file if available.
-
char *history_file_path(void)
Determine the path to the history file based on environment variables.
Follows POSIX-compliant lookup order: first checks $HISTFILE, then falls back to $HOME/.sh_history. Returns a malloc’d string that the caller must free.
-
void history_load(const char *file_path)
Load the command history from a file into readline’s in-memory history list.
This function uses readline’s
read_history()to populate the history list. Iffile_pathis NULL, this function does nothing.
-
void history_save(const char *file_path)
Save the in-memory command history list to a file.
This function uses readline’s
write_history()to write the history list to disk. Iffile_pathis NULL, this function does nothing.