removing ai generated documentation. it served it's purpose to get the project up and running fast, but is not descriptive enough. focus going forwards is going to be on adding documentation

This commit is contained in:
2025-10-24 19:43:40 +02:00
parent 1d1606580f
commit cb0c4aea06
43 changed files with 1 additions and 1823 deletions

View File

@@ -1,7 +1,3 @@
/**
* builtins.h
* Declarations for all built-in shell commands
*/
#ifndef BUILTINS_H
#define BUILTINS_H
@@ -90,13 +86,6 @@ int lsh_num_builtins(void);
extern char *builtin_str[];
extern int (*builtin_func[])(char **);
/**
* Extract a string value from a JSON object
*
* @param json The JSON string to parse
* @param key The key to find
* @return Allocated string containing the value (caller must free)
*/
char *extract_json_string(const char *json, const char *key);
#endif // BUILTINS_H

View File

@@ -1,7 +1,3 @@
/**
* common.h
* Common includes, defines and macros used throughout the shell
*/
#ifndef COMMON_H
#define COMMON_H

View File

@@ -1,7 +1,3 @@
/**
* aliases.h
* Definitions for shell alias functionality
*/
#ifndef ALIASES_H
#define ALIASES_H

View File

@@ -1,7 +1,3 @@
/**
* bookmarks.h
* Functions for managing directory bookmarks
*/
#ifndef BOOKMARKS_H
#define BOOKMARKS_H

View File

@@ -1,7 +1,3 @@
/**
* favorite_cities.h
* Functions for managing favorite cities for weather lookups
*/
#ifndef FAVORITE_CITIES_H
#define FAVORITE_CITIES_H

View File

@@ -1,7 +1,3 @@
/**
* structured_data.h
* Definitions for structured data representation and manipulation
*/
#ifndef STRUCTURED_DATA_H
#define STRUCTURED_DATA_H

View File

@@ -1,26 +1,11 @@
/**
* git_integration.h
* Functions for Git repository detection and information
*/
#ifndef GIT_INTEGRATION_H
#define GIT_INTEGRATION_H
#include "common.h"
/**
* Initialize Git integration
*/
void init_git_integration(void);
/**
* Check if the current directory is in a Git repository and get branch info
*
* @param branch_name Buffer to store branch name if found
* @param buffer_size Size of the branch_name buffer
* @param is_dirty Pointer to store dirty status flag (1 if repo has changes)
* @return 1 if in a Git repo, 0 otherwise
*/
int get_git_branch(char *branch_name, size_t buffer_size, int *is_dirty);
int get_last_commit(char *title, size_t title_size, char *hash,
@@ -30,30 +15,10 @@ int get_recent_commit(char commits[][256], int count);
int get_repo_url(char *url, size_t url_size);
/**
* Get the name of the Git repository
*
* @param repo_name Buffer to store repo name if found
* @param buffer_size Size of the repo_name buffer
* @return 1 if name was retrieved, 0 otherwise
*/
int get_git_repo_name(char *repo_name, size_t buffer_size);
/**
* Get Git status for the current repository
*
* @return A string with the Git status or NULL if not in a repo
* (caller must free the returned string)
*/
char *get_git_status(void);
/**
* Check if the current branch has diverged from its remote tracking branch
*
* @param commits_ahead Pointer to store number of commits ahead of remote
* @param commits_behind Pointer to store number of commits behind remote
* @return 1 if diverged (both ahead and behind > 0), 0 otherwise
*/
int check_branch_divergence(int *commits_ahead, int *commits_behind);
int create_git_stash(void);
@@ -62,58 +27,16 @@ int create_git_stash_with_name(const char *stash_name);
int get_git_stashes(char stashed[][512], int max_stashes);
/**
* Apply a git stash by index (keeps stash in list)
*
* @param stash_index Index of stash to apply (0 = most recent)
* @return 1 if stash was applied successfully, 0 otherwise
*/
int apply_git_stash(int stash_index);
/**
* Pop a git stash by index (applies and removes stash from list)
*
* @param stash_index Index of stash to pop (0 = most recent)
* @return 1 if stash was popped successfully, 0 otherwise
*/
int pop_git_stash(int stash_index);
/**
* Drop a git stash by index (removes stash without applying)
*
* @param stash_index Index of stash to drop (0 = most recent)
* @return 1 if stash was dropped successfully, 0 otherwise
*/
int drop_git_stash(int stash_index);
/**
* Get detailed commit information including diff
*
* @param commit_hash The commit hash to get info for
* @param commit_info Buffer to store formatted commit info
* @param info_size Size of commit_info buffer
* @return 1 if successful, 0 otherwise
*/
int get_commit_details(const char *commit_hash, char *commit_info, size_t info_size);
/**
* Get stash diff information
*
* @param stash_index Index of stash to get diff for
* @param stash_diff Buffer to store formatted stash diff
* @param diff_size Size of stash_diff buffer
* @return 1 if successful, 0 otherwise
*/
int get_stash_diff(int stash_index, char *stash_diff, size_t diff_size);
/**
* Get commit history for a specific branch
*
* @param branch_name The branch name to get commits for
* @param commits Array to store commit information
* @param max_commits Maximum number of commits to retrieve
* @return Number of commits retrieved
*/
int get_branch_commits(const char *branch_name, char commits[][2048], int max_commits);
#endif // GIT_INTEGRATION_H

View File

@@ -1,7 +1,3 @@
/**
* persistent_history.h
* Functions for persistent command history and frequency tracking
*/
#ifndef PERSISTENT_HISTORY_H
#define PERSISTENT_HISTORY_H

View File

@@ -1,7 +1,3 @@
/**
* autocorrect.h
* Header for command auto-correction functionality
*/
#ifndef AUTOCORRECT_H
#define AUTOCORRECT_H
@@ -10,41 +6,16 @@
#include "line_reader.h"
#include <limits.h>
/**
* Calculate Levenshtein distance between two strings
*
* @param s1 First string
* @param s2 Second string
* @return Edit distance between the strings
*/
int levenshtein_distance(const char *s1, const char *s2);
/**
* Helper function to find minimum of three integers
*/
int min3(int a, int b, int c);
/**
* Initialize the autocorrect system
*/
void init_autocorrect(void);
/**
* Shutdown the autocorrect system
*/
void shutdown_autocorrect(void);
/**
* Check a command for possible corrections
*
* @param args Command arguments
* @return Corrected arguments array (must be freed by caller) or NULL if no correction
*/
char **check_for_corrections(char **args);
/**
* Count the number of arguments in a NULL-terminated array
*/
int count_args(char **args);
#endif // AUTOCORRECT_H

View File

@@ -1,59 +1,21 @@
/**
* line_reader.h
* Functions for reading and parsing command lines
*/
#ifndef LINE_READER_H
#define LINE_READER_H
#include "common.h"
/**
* Check if a command is valid
*
* @param cmd The command to check
* @return 1 if valid, 0 if not
*/
int is_valid_command(const char *cmd);
/**
* Read a key from the terminal
*
* Handles special keys and escape sequences
*/
int read_key(void);
/**
* Read a line of input from the user with tab completion
*
* @return The line read from stdin (must be freed by caller)
*/
char *lsh_read_line(void);
void generate_enhanced_prompt(char *prompt_buffer, size_t buffer_size);
/**
* Split a line into tokens
*
* @param line The line to split
* @return An array of tokens (must be freed by caller)
*/
char **lsh_split_line(char *line);
/**
* Parse a token from a string, handling quoted strings
*
* @param str_ptr Pointer to the string to parse, will be updated
* @return The parsed token, or NULL if no more tokens
*/
char *parse_token(char **str_ptr);
/**
* Split a line with pipes into separate command arrays
*
* @param line The line to split
* @return NULL-terminated array of NULL-terminated token arrays
*/
char ***lsh_split_piped_line(char *line);
#endif // LINE_READER_H

View File

@@ -1,16 +1,9 @@
/**
* tab_complete.h
* Functions for tab completion and path suggestions
*/
#ifndef TAB_COMPLETE_H
#define TAB_COMPLETE_H
#include "common.h"
/**
* Command context structure
*/
typedef struct {
int is_after_pipe; // Flag if cursor is right after a pipe
int is_filter_command; // Flag if current command is a filter command
@@ -38,9 +31,6 @@ typedef enum {
ARG_TYPE_COMMAND,
} ArgumentType;
/**
* Structure for command argument type information
*/
typedef struct {
char *command; // Command name
ArgumentType arg_type; // Expected argument type
@@ -50,9 +40,6 @@ typedef struct {
// other matches
} CommandArgInfo;
/**
* Structure for returning multiple suggestions
*/
typedef struct {
char **items; // Array of suggestion strings
int count; // Number of suggestions

View File

@@ -1,7 +1,3 @@
/**
* filters.h
* Declarations for filter commands (where, sort-by, etc.)
*/
// this is a test
#ifndef FILTERS_H
@@ -9,54 +5,16 @@
#include "structured_data.h"
/**
* Filter a table based on a condition (e.g., where size > 10kb)
*
* @param input The input table
* @param args Command arguments
* @return Filtered table or NULL on error
*/
TableData *lsh_where(TableData *input, char **args);
/**
* Sort a table based on a column (e.g., sort-by size desc)
*
* @param input The input table
* @param args Command arguments
* @return Sorted table or NULL on error
*/
TableData *lsh_sort_by(TableData *input, char **args);
/**
* Select specific columns from a table
*
* @param input The input table
* @param args Command arguments
* @return Table with selected columns or NULL on error
*/
TableData *lsh_select(TableData *input, char **args);
/**
* Filter rows where a column contains a substring
*
* @param input The input table
* @param args Command arguments
* @return Filtered table or NULL on error
*/
TableData *lsh_contains(TableData *input, char **args);
/**
* Limit the number of rows displayed
*
* @param input The input table
* @param args Command arguments
* @return Limited table or NULL on error
*/
TableData *lsh_limit(TableData *input, char **args);
/**
* Case-insensitive substring search (strcasestr equivalent for Windows)
*/
char *my_strcasestr(const char *haystack, const char *needle);
// Export the filter arrays for the shell

View File

@@ -1,7 +1,3 @@
/**
* fzf_native.h
* Header for native fzf command-line fuzzy finder wrapper
*/
#ifndef FZF_NATIVE_H
#define FZF_NATIVE_H
@@ -9,49 +5,16 @@
#include "builtins.h"
#include "common.h"
/**
* Check if native fzf is installed on the system
*
* @return 1 if installed, 0 if not
*/
int is_fzf_installed(void);
/**
* Display instructions for installing fzf
*/
void show_fzf_install_instructions(void);
/**
* Run fzf with files from the current directory
*
* @param preview Enable preview window if 1
* @param args Additional arguments for fzf
* @return Selected filename or NULL if canceled
*/
char *run_native_fzf_files(int preview, char **args);
/**
* Run fzf with all files and directories from the current directory
*
* @param recursive Search recursively if 1
* @param args Additional arguments for fzf
* @return Selected path or NULL if canceled
*/
char *run_native_fzf_all(int recursive, char **args);
/**
* Run fzf with command history
*
* @return Selected command or NULL if canceled
*/
char *run_native_fzf_history(void);
/**
* Command handler for the fzf command
*
* @param args Command arguments
* @return 1 to continue shell execution, 0 to exit shell
*/
int lsh_fzf_native(char **args);
#endif // FZF_NATIVE_H

View File

@@ -1,39 +1,11 @@
/**
* grep.h
* Header for fast text searching in files with fuzzy matching capabilities
*/
#ifndef GREP_H
#define GREP_H
#include "common.h"
/**
* Run grep with interactive interface
*
* Shows a split view with files on left, matches on right, and
* updates search results with each keystroke
*/
void run_interactive_grep_session(void);
/**
* Command handler for the "grep" command
*
* Usage: grep [options] pattern [file/directory]
* Options:
* -n, --line-numbers Show line numbers
* -i, --ignore-case Ignore case distinctions
* -r, --recursive Search directories recursively
* -f, --fuzzy Use fuzzy matching instead of exact
* --file Specify files/directories to search (otherwise searches
* current dir)
*
* If called without arguments, opens an interactive grep UI with a split view
* that updates as you type.
*
* @param args Command arguments
* @return 1 to continue shell execution, 0 to exit shell
*/
int lsh_grep(char **args);
#endif // GREP_H

View File

@@ -1,7 +1,3 @@
/**
* shell.h
* Core shell functionality
*/
#ifndef SHELL_H
#define SHELL_H
@@ -9,133 +5,39 @@
#include "common.h"
#include "structured_data.h"
/**
* Display a welcome banner with BBQ sauce invention time
*/
void display_welcome_banner(void);
/**
* Execute a command
*
* @param args Null-terminated array of command arguments
* @return 1 to continue the shell, 0 to exit
*/
int lsh_execute(char **args);
/**
* Execute a pipeline of commands
*
* @param commands Null-terminated array of command arrays
* @return 1 to continue the shell, 0 to exit
*/
int lsh_execute_piped(char ***commands);
/**
* Create a TableData structure from an ls command
*
* @param args Command arguments
* @return TableData pointer (must be freed by caller) or NULL on error
*/
TableData* create_ls_table(char **args);
/**
* Parse input line into an array of commands (for pipelines)
*
* @param line Input command line
* @return Null-terminated array of command arrays
*/
char*** lsh_split_commands(char *line);
/**
* Launch an external program
*
* @param args Null-terminated array of command arguments
* @return Always returns 1 (continue the shell)
*/
int lsh_launch(char **args);
/**
* Main shell loop
*/
void lsh_loop(void);
/**
* Free memory for a command array from lsh_split_commands
*/
void free_commands(char ***commands);
/**
* Initialize the status bar at the bottom of the screen
*
* @param fd File descriptor for terminal (STDOUT_FILENO)
* @return 1 if successful, 0 on failure
*/
int init_status_bar(int fd);
/**
* Temporarily hide the status bar before command execution
*
* @param fd File descriptor for terminal (STDOUT_FILENO)
*/
void hide_status_bar(int fd);
/**
* Ensures there's space for the status bar by scrolling if needed
*
* @param fd File descriptor for terminal (STDOUT_FILENO)
*/
void ensure_status_bar_space(int fd);
/**
* Check for terminal window resize and update status bar position
*
* @param fd File descriptor for terminal (STDOUT_FILENO)
*/
void check_console_resize(int fd);
/**
* Update the status bar with Git information
*
* @param fd File descriptor for terminal (STDOUT_FILENO)
* @param git_info The Git information to display in the status bar
*/
void update_status_bar(int fd, const char *git_info);
/**
* Get the name of the parent and current directories from a path
*
* @param cwd The current working directory path
* @param parent_dir_name Buffer to store the parent directory name
* @param current_dir_name Buffer to store the current directory name
* @param buf_size Size of the buffers
*/
void get_path_display(const char *cwd, char *parent_dir_name,
char *current_dir_name, size_t buf_size);
/**
* Initialize the terminal for raw mode
*
* @param orig_termios Original terminal settings to restore later
* @return File descriptor for terminal
*/
int init_terminal(struct termios *orig_termios);
/**
* Restore terminal to original settings
*
* @param fd File descriptor for terminal
* @param orig_termios Original terminal settings
*/
void restore_terminal(int fd, struct termios *orig_termios);
/**
* Get console dimensions
*
* @param fd File descriptor for terminal
* @param width Pointer to store width
* @param height Pointer to store height
* @return 1 on success, 0 on failure
*/
int get_console_dimensions(int fd, int *width, int *height);
#endif // SHELL_H

View File

@@ -1,7 +1,3 @@
/**
* diff_viewer.h
* Interactive diff viewer for git changes
*/
#ifndef DIFF_VIEWER_H
#define DIFF_VIEWER_H
@@ -43,64 +39,28 @@ typedef struct {
ViewMode current_mode;
} DiffViewer;
/**
* Initialize the diff viewer
*/
int init_diff_viewer(DiffViewer *viewer);
/**
* Get list of changed files from git
*/
int get_changed_files(DiffViewer *viewer);
/**
* Check if a file is a new untracked file
*/
int is_new_file(const char *filename);
/**
* Load content of a new file and show all lines as additions
*/
int load_new_file_content(DiffViewer *viewer, const char *filename);
/**
* Load diff for a specific file
*/
int load_file_diff(DiffViewer *viewer, const char *filename);
/**
* Render the diff viewer interface
*/
void render_diff_viewer(DiffViewer *viewer);
/**
* Handle keyboard input for navigation
*/
int handle_diff_input(DiffViewer *viewer, char key);
/**
* Run the interactive diff viewer
*/
int run_diff_viewer(void);
/**
* Clean up diff viewer resources
*/
void cleanup_diff_viewer(DiffViewer *viewer);
/**
* Get terminal size
*/
void get_terminal_size(int *width, int *height);
/**
* Set terminal to raw mode for interactive input
*/
void set_raw_mode(struct termios *orig_termios);
/**
* Restore terminal to original mode
*/
void restore_terminal_mode(struct termios *orig_termios);
#endif // DIFF_VIEWER_H

View File

@@ -1,7 +1,3 @@
/**
* ncurses_diff_viewer.h
* NCurses-based interactive diff viewer for git changes
*/
#ifndef NCURSES_DIFF_VIEWER_H
#define NCURSES_DIFF_VIEWER_H
@@ -212,113 +208,50 @@ typedef struct {
} NCursesDiffViewer;
/**
* Initialize the ncurses diff viewer
*/
int init_ncurses_diff_viewer(NCursesDiffViewer *viewer);
/**
* Get list of changed files from git
*/
int get_ncurses_changed_files(NCursesDiffViewer *viewer);
/**
* Load full file content with diff highlighting
*/
int load_full_file_with_diff(NCursesDiffViewer *viewer, const char *filename);
/**
* Render the file list window
*/
void render_file_list_window(NCursesDiffViewer *viewer);
/**
* Render the file content window
*/
void render_file_content_window(NCursesDiffViewer *viewer);
/**
* Handle keyboard input for navigation
*/
int handle_ncurses_diff_input(NCursesDiffViewer *viewer, int key);
/**
* Run the ncurses diff viewer
*/
int run_ncurses_diff_viewer(void);
/**
* Clean up ncurses diff viewer resources
*/
void cleanup_ncurses_diff_viewer(NCursesDiffViewer *viewer);
/**
* Create temporary file with current working version
*/
int create_temp_file_with_changes(const char *filename, char *temp_path);
/**
* Create temporary file with git HEAD version
*/
int create_temp_file_git_version(const char *filename, char *temp_path);
/**
* Get commit history
*/
int get_commit_history(NCursesDiffViewer *viewer);
/**
* Toggle file marking for commit
*/
void toggle_file_mark(NCursesDiffViewer *viewer, int file_index);
/**
* Mark all files for commit
*/
void mark_all_files(NCursesDiffViewer *viewer);
/**
* Commit marked files with title and message
*/
int commit_marked_files(NCursesDiffViewer *viewer, const char *commit_title,
const char *commit_message);
/**
* Push specific commit
*/
int push_commit(NCursesDiffViewer *viewer, int commit_index);
/**
* Pull commits from remote
*/
int pull_commits(NCursesDiffViewer *viewer);
/**
* Render the commit list window
*/
void render_commit_list_window(NCursesDiffViewer *viewer);
/**
* Get commit title and message input from user
*/
int get_commit_title_input(char *title, int max_len, char *message,
int max_message_len);
/**
* Draw a box with rounded corners
*/
void draw_rounded_box(WINDOW *win);
/**
* Render the status bar
*/
void render_status_bar(NCursesDiffViewer *viewer);
void render_branch_list_window(NCursesDiffViewer *viewer);
/**
* Update sync status and check for new files
*/
void update_sync_status(NCursesDiffViewer *viewer);
int get_ncurses_git_stashes(NCursesDiffViewer *viewer);
@@ -362,76 +295,34 @@ int get_stash_name_input(char *stash_name, int max_len);
void render_stash_list_window(NCursesDiffViewer *viewer);
/**
* Load commit details for viewing
*/
int load_commit_for_viewing(NCursesDiffViewer *viewer, const char *commit_hash);
/**
* Load stash details for viewing
*/
int load_stash_for_viewing(NCursesDiffViewer *viewer, int stash_index);
/**
* Load commits for a specific branch for the hover preview
*/
int load_branch_commits(NCursesDiffViewer *viewer, const char *branch_name);
/**
* Parse branch commits into navigable lines for branch view mode
*/
int parse_branch_commits_to_lines(NCursesDiffViewer *viewer);
/**
* Start background fetch process
*/
void start_background_fetch(NCursesDiffViewer *viewer);
/**
* Check if background fetch is complete and update UI accordingly
*/
void check_background_fetch(NCursesDiffViewer *viewer);
/**
* Move cursor up/down while skipping empty lines
*/
void move_cursor_smart(NCursesDiffViewer *viewer, int direction);
/**
* Move cursor up/down in unstaged pane with proper scrolling
*/
void move_cursor_smart_unstaged(NCursesDiffViewer *viewer, int direction);
/**
* Move cursor up/down in staged pane with proper scrolling
*/
void move_cursor_smart_staged(NCursesDiffViewer *viewer, int direction);
/**
* Helper function to wrap a long line into multiple display lines
*/
int wrap_line_to_width(const char *input_line, char wrapped_lines[][1024],
int max_lines, int width);
/**
* Render a single line with proper wrapping and coloring
*/
int render_wrapped_line(WINDOW *win, const char *line, int start_y, int start_x,
int width, int max_rows, int color_pair, int reverse);
/**
* Calculate how many display lines a wrapped line will take
*/
int calculate_wrapped_line_height(const char *line, int width);
/**
* Load file preview showing the top of the file content
*/
int load_file_preview(NCursesDiffViewer *viewer, const char *filename);
/**
* Update preview based on current mode and selection
*/
void update_preview_for_current_selection(NCursesDiffViewer *viewer);
int get_single_input(const char *title, const char *prompt, char *input,
@@ -462,109 +353,46 @@ int commit_staged_changes_only(NCursesDiffViewer *viewer,
void rebuild_staged_view_from_git(NCursesDiffViewer *viewer);
/**
* Initialize fuzzy search state
*/
void init_fuzzy_search(NCursesDiffViewer *viewer);
/**
* Cleanup fuzzy search windows
*/
void cleanup_fuzzy_search(NCursesDiffViewer *viewer);
/**
* Enter fuzzy search mode
*/
void enter_fuzzy_search_mode(NCursesDiffViewer *viewer);
/**
* Exit fuzzy search mode
*/
void exit_fuzzy_search_mode(NCursesDiffViewer *viewer);
/**
* Update fuzzy search filter based on current query
*/
void update_fuzzy_filter(NCursesDiffViewer *viewer);
/**
* Render fuzzy search UI
*/
void render_fuzzy_search(NCursesDiffViewer *viewer);
/**
* Render fuzzy search input field only
*/
void render_fuzzy_input(NCursesDiffViewer *viewer);
/**
* Render fuzzy search file list content only
*/
void render_fuzzy_list_content(NCursesDiffViewer *viewer);
/**
* Create fuzzy search windows with borders (one-time setup)
*/
void create_fuzzy_windows_with_borders(NCursesDiffViewer *viewer);
/**
* Handle fuzzy search input
*/
int handle_fuzzy_search_input(NCursesDiffViewer *viewer, int key);
/**
* Select file from fuzzy search results
*/
void select_fuzzy_file(NCursesDiffViewer *viewer);
/**
* Initialize grep search state
*/
void init_grep_search(NCursesDiffViewer *viewer);
/**
* Cleanup grep search windows
*/
void cleanup_grep_search(NCursesDiffViewer *viewer);
/**
* Enter grep search mode for current view mode
*/
void enter_grep_search_mode(NCursesDiffViewer *viewer);
/**
* Exit grep search mode
*/
void exit_grep_search_mode(NCursesDiffViewer *viewer);
/**
* Update grep search filter based on current query and mode
*/
void update_grep_filter(NCursesDiffViewer *viewer);
/**
* Render grep search UI
*/
void render_grep_search(NCursesDiffViewer *viewer);
/**
* Handle grep search input
*/
int handle_grep_search_input(NCursesDiffViewer *viewer, int key);
/**
* Select item from grep search results
*/
void select_grep_item(NCursesDiffViewer *viewer);
/**
* Calculate grep match score for text content
*/
int calculate_grep_score(const char *pattern, const char *text);
/**
* Extract branch name from stash info
*/
void extract_branch_from_stash(const char *stash_info, char *branch_name,
int max_len);

View File

@@ -1,57 +1,21 @@
/**
* countdown_timer.h
* Header for focus timer functionality
*/
#ifndef COUNTDOWN_TIMER_H
#define COUNTDOWN_TIMER_H
#include "common.h"
/**
* Start a new countdown timer
*
* @param seconds Total duration in seconds
* @param name Optional name for the timer session
* @return 1 if successful, 0 on failure
*/
int start_countdown_timer(int seconds, const char *name);
/**
* Stop the current countdown timer
*/
void stop_countdown_timer();
/**
* Check if a timer is currently active
*
* @return TRUE if timer is active, FALSE otherwise
*/
BOOL is_timer_active();
/**
* Get the current timer display text
*
* @return Pointer to the display text string
*/
const char *get_timer_display();
/**
* Temporarily hide the timer display (used when running external programs)
*/
void hide_timer_display(void);
/**
* Restore the timer display after it was hidden
*/
void show_timer_display(void);
/**
* Command handler for the "timer" command
*
* @param args Command arguments
* @return 1 to continue shell, 0 to exit
*/
int lsh_focus_timer(char **args);
#endif // COUNTDOWN_TIMER_H

View File

@@ -1,38 +1,13 @@
/**
* timer.h
* Header for command execution timer functionality
*/
#ifndef TIMER_H
#define TIMER_H
#include "common.h"
/**
* Format a time interval in milliseconds to a readable string
*
* @param ms Time in milliseconds
* @param buffer Buffer to store formatted time
* @param buffer_size Size of the buffer
*/
void format_time(double ms, char *buffer, size_t buffer_size);
/**
* Implementation of the timer command
* Usage: timer COMMAND [ARGS...]
*
* @param args Command arguments
* @return 1 to continue, 0 to exit
*/
int lsh_timer(char **args);
/**
* Implementation of the time command (alias for timer)
* Usage: time COMMAND [ARGS...]
*
* @param args Command arguments
* @return 1 to continue, 0 to exit
*/
int lsh_time(char **args);
#endif // TIMER_H

BIN
shell

Binary file not shown.

View File

@@ -1,7 +1,3 @@
/**
* builtins.c
* Implementation of all built-in shell commands
*/
#include "builtins.h"
#include "common.h"
@@ -59,9 +55,6 @@ int (*builtin_func[])(char **) = {
&lsh_stats, &builtin_monitor,
};
/**
* Set the console text color
*/
void set_color(int color) {
switch (color) {
case 0:
@@ -93,19 +86,10 @@ void set_color(int color) {
}
}
/**
* Reset console color to default
*/
void reset_color() { printf(ANSI_COLOR_RESET); }
/**
* Get the number of built-in commands
*/
int lsh_num_builtins() { return sizeof(builtin_str) / sizeof(char *); }
/**
* Add a command to the history
*/
void lsh_add_to_history(const char *command) {
// Don't add empty commands or duplicates of the last command
if (!command || *command == '\0' ||
@@ -129,10 +113,6 @@ void lsh_add_to_history(const char *command) {
history_index = (history_index + 1) % HISTORY_SIZE;
}
/**
* Built-in command: cd
* Changes the current directory
*/
int lsh_cd(char **args) {
if (args[1] == NULL) {
// No argument provided, change to home directory
@@ -152,10 +132,6 @@ int lsh_cd(char **args) {
return 1;
}
/**
* Built-in command: help
* Displays help information
*/
int lsh_help(char **args) {
if (args[1] != NULL) {
// Command-specific help
@@ -380,16 +356,8 @@ int lsh_help(char **args) {
return 1;
}
/**
* Built-in command: exit
* Exits the shell
*/
int lsh_exit(char **args) { return 0; }
/**
* Built-in command: dir
* Lists files in the current directory
*/
int lsh_dir(char **args) {
DIR *dir;
struct dirent *entry;
@@ -517,20 +485,12 @@ int lsh_dir(char **args) {
return 1;
}
/**
* Built-in command: clear
* Clears the screen
*/
int lsh_clear(char **args) {
printf(ANSI_CLEAR_SCREEN);
printf(ANSI_CURSOR_HOME);
return 1;
}
/**
* Built-in command: mkdir
* Creates a new directory
*/
int lsh_mkdir(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lsh: expected argument to \"mkdir\"\n");
@@ -542,10 +502,6 @@ int lsh_mkdir(char **args) {
return 1;
}
/**
* Built-in command: rmdir
* Removes a directory
*/
int lsh_rmdir(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lsh: expected argument to \"rmdir\"\n");
@@ -557,10 +513,6 @@ int lsh_rmdir(char **args) {
return 1;
}
/**
* Built-in command: del
* Deletes a file
*/
int lsh_del(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lsh: expected argument to \"del\"\n");
@@ -572,10 +524,6 @@ int lsh_del(char **args) {
return 1;
}
/**
* Built-in command: touch
* Creates a new file or updates timestamp of existing file
*/
int lsh_touch(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lsh: expected argument to \"touch\"\n");
@@ -590,10 +538,6 @@ int lsh_touch(char **args) {
return 1;
}
/**
* Built-in command: pwd
* Prints the current working directory
*/
int lsh_pwd(char **args) {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
@@ -604,10 +548,6 @@ int lsh_pwd(char **args) {
return 1;
}
/**
* Built-in command: cat
* Displays the contents of a file
*/
int lsh_cat(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lsh: expected argument to \"cat\"\n");
@@ -629,10 +569,6 @@ int lsh_cat(char **args) {
return 1;
}
/**
* Built-in command: history
* Displays command history
*/
int lsh_history(char **args) {
char time_str[20];
struct tm *tm_info;
@@ -651,10 +587,6 @@ int lsh_history(char **args) {
return 1;
}
/**
* Built-in command: copy
* Copies a file
*/
int lsh_copy(char **args) {
if (args[1] == NULL || args[2] == NULL) {
fprintf(stderr,
@@ -687,10 +619,6 @@ int lsh_copy(char **args) {
return 1;
}
/**
* Built-in command: move
* Moves a file
*/
int lsh_move(char **args) {
if (args[1] == NULL || args[2] == NULL) {
fprintf(stderr,
@@ -707,19 +635,11 @@ int lsh_move(char **args) {
return 1;
}
/**
* Built-in command: paste
* Placeholder for paste functionality
*/
int lsh_paste(char **args) {
printf("Paste functionality not implemented yet\n");
return 1;
}
/**
* Built-in command: ps
* Lists running processes
*/
int lsh_ps(char **args) {
FILE *fp = popen("ps -ef", "r");
if (fp == NULL) {
@@ -782,10 +702,6 @@ char *unescape_json_string(const char *str) {
return result;
}
/**
* Built-in command: news
* Displays information about the last push to the shelltest GitHub repository
*/
int lsh_news(char **args) {
printf("Fetching latest updates from shelltestLinux repository...\n\n");
@@ -958,19 +874,11 @@ int lsh_news(char **args) {
return 1;
}
/**
* Built-in command: clip
* Placeholder for clipboard functionality
*/
int lsh_clip(char **args) {
printf("Clipboard functionality not implemented yet\n");
return 1;
}
/**
* Built-in command: echo
* Echoes arguments to stdout
*/
int lsh_echo(char **args) {
if (args[1] == NULL) {
printf("\n");
@@ -987,10 +895,6 @@ int lsh_echo(char **args) {
return 1;
}
/**
* Built-in command: loc
* Counts lines of code
*/
int lsh_loc(char **args) {
if (args[1] == NULL) {
fprintf(stderr, "lsh: expected file or directory argument to \"loc\"\n");
@@ -1058,9 +962,6 @@ int lsh_loc(char **args) {
return 1;
}
/**
* Helper function to extract a string value from a JSON response
*/
char *extract_json_string(const char *json, const char *key) {
char search_key[100];
sprintf(search_key, "\"%s\":", key);
@@ -1105,10 +1006,6 @@ char *extract_json_string(const char *json, const char *key) {
return result;
}
/**
* Built-in command: git_status
* Displays the Git status of the current repo
*/
int lsh_git_status(char **args) {
// Show current Git status
char *git_status = get_git_status();
@@ -1121,10 +1018,6 @@ int lsh_git_status(char **args) {
return 1;
}
/**
* Built-in command: gg
* Quick access to Git commands
*/
int lsh_gg(char **args) {
if (args[1] == NULL) {
printf("Usage: gg <command>\n");

View File

@@ -1,7 +1,3 @@
/**
* aliases.c
* Implementation of shell alias functionality this is a test..
*/
#include "aliases.h"
#include "builtins.h"
@@ -17,9 +13,6 @@ int loading_aliases = 0; // Flag to prevent saving during loading
// Path to the aliases file
char aliases_file_path[PATH_MAX];
/**
* Initialize the alias system
*/
void init_aliases(void) {
// Set initial capacity
alias_capacity = 10;
@@ -43,9 +36,6 @@ void init_aliases(void) {
load_aliases();
}
/**
* Clean up the alias system
*/
void cleanup_aliases(void) {
if (!aliases)
return;
@@ -63,17 +53,11 @@ void cleanup_aliases(void) {
alias_capacity = 0;
}
/**
* Shutdown the alias system
*/
void shutdown_aliases(void) {
// Clean up (don't save here since we save immediately on changes)
cleanup_aliases();
}
/**
* Load aliases from file
*/
int load_aliases(void) {
FILE *fp = fopen(aliases_file_path, "r");
if (!fp) {
@@ -125,9 +109,6 @@ int load_aliases(void) {
return 1;
}
/**
* Save aliases to file
*/
int save_aliases(void) {
FILE *fp = fopen(aliases_file_path, "w");
if (!fp) {
@@ -152,9 +133,6 @@ int save_aliases(void) {
return 1;
}
/**
* Add a new alias
*/
int add_alias(const char *name, const char *command) {
if (!name || !command) {
return 0;
@@ -199,9 +177,6 @@ int add_alias(const char *name, const char *command) {
return 1;
}
/**
* Remove an alias
*/
int remove_alias(const char *name) {
if (!name) {
return 0;
@@ -230,9 +205,6 @@ int remove_alias(const char *name) {
return 0; // Alias not found
}
/**
* Find an alias by name
*/
AliasEntry *find_alias(const char *name) {
for (int i = 0; i < alias_count; i++) {
if (strcmp(aliases[i].name, name) == 0) {
@@ -242,9 +214,6 @@ AliasEntry *find_alias(const char *name) {
return NULL;
}
/**
* Expand a command line by replacing aliases
*/
char *expand_aliases(const char *command) {
if (!command) {
return NULL;
@@ -293,9 +262,6 @@ char *expand_aliases(const char *command) {
return result;
}
/**
* Command handler for the "alias" command
*/
int lsh_alias(char **args) {
// No arguments - list all aliases
if (args[1] == NULL) {
@@ -396,9 +362,6 @@ int lsh_alias(char **args) {
return 1;
}
/**
* Command handler for the "unalias" command
*/
int lsh_unalias(char **args) {
if (args[1] == NULL) {
printf("unalias: missing argument\n");
@@ -414,9 +377,6 @@ int lsh_unalias(char **args) {
return 1;
}
/**
* Command handler to show all aliases
*/
int lsh_aliases(char **args) {
for (int i = 0; i < alias_count; i++) {
printf("alias %s='%s'\n", aliases[i].name, aliases[i].command);
@@ -424,9 +384,6 @@ int lsh_aliases(char **args) {
return 1;
}
/**
* Get alias names for tab completion
*/
char **get_alias_names(int *count) {
if (alias_count == 0 || !count) {
*count = 0;
@@ -447,9 +404,6 @@ char **get_alias_names(int *count) {
return names;
}
/**
* Expand alias in args array
*/
char **expand_alias(char **args) {
if (!args || !args[0]) {
return NULL;

View File

@@ -1,8 +1,3 @@
/**
* this is a test
* bookmarks.c
* Implementation of directory bookmarks functionality
*/
#include "bookmarks.h"
#include <fcntl.h>
@@ -16,9 +11,6 @@ int bookmark_capacity = 0;
// Path to the bookmarks file
char bookmarks_file_path[PATH_MAX];
/**
* Initialize the bookmark system
*/
void init_bookmarks(void) {
// Set initial capacity
bookmark_capacity = 10;
@@ -43,9 +35,6 @@ void init_bookmarks(void) {
load_bookmarks();
}
/**
* Clean up the bookmark system
*/
void cleanup_bookmarks(void) {
if (!bookmarks)
return;
@@ -63,9 +52,6 @@ void cleanup_bookmarks(void) {
bookmark_capacity = 0;
}
/**
* Shutdown the bookmark system
*/
void shutdown_bookmarks(void) {
// Save bookmarks to file
save_bookmarks();
@@ -74,9 +60,6 @@ void shutdown_bookmarks(void) {
cleanup_bookmarks();
}
/**
* Load bookmarks from file
*/
int load_bookmarks(void) {
FILE *fp = fopen(bookmarks_file_path, "r");
if (!fp) {
@@ -122,9 +105,6 @@ int load_bookmarks(void) {
return 1;
}
/**
* Save bookmarks to file
*/
int save_bookmarks(void) {
FILE *fp = fopen(bookmarks_file_path, "w");
if (!fp) {
@@ -149,9 +129,6 @@ int save_bookmarks(void) {
return 1;
}
/**
* Add a new bookmark
*/
int add_bookmark(const char *name, const char *path) {
if (!name || !path) {
return 0;
@@ -187,9 +164,6 @@ int add_bookmark(const char *name, const char *path) {
return 1;
}
/**
* Remove a bookmark
*/
int remove_bookmark(const char *name) {
if (!name) {
return 0;
@@ -214,9 +188,6 @@ int remove_bookmark(const char *name) {
return 0; // Bookmark not found
}
/**
* Find a bookmark by name
*/
BookmarkEntry *find_bookmark(const char *name) {
for (int i = 0; i < bookmark_count; i++) {
if (strcmp(bookmarks[i].name, name) == 0) {
@@ -226,9 +197,6 @@ BookmarkEntry *find_bookmark(const char *name) {
return NULL;
}
/**
* Command handler for the "bookmark" command
*/
int lsh_bookmark(char **args) {
char cwd[PATH_MAX];
@@ -258,9 +226,6 @@ int lsh_bookmark(char **args) {
return 1;
}
/**
* Command handler for the "bookmarks" command
*/
int lsh_bookmarks(char **args) {
if (bookmark_count == 0) {
printf("No bookmarks defined.\n");
@@ -323,9 +288,6 @@ int lsh_bookmarks(char **args) {
return 1;
}
/**
* Command handler for the "goto" command
*/
int lsh_goto(char **args) {
if (args[1] == NULL) {
printf("Usage: goto <bookmark_name>\n");
@@ -346,9 +308,6 @@ int lsh_goto(char **args) {
return 1;
}
/**
* Command handler for the "unbookmark" command
*/
int lsh_unbookmark(char **args) {
if (args[1] == NULL) {
printf("Usage: unbookmark <bookmark_name>\n");
@@ -365,9 +324,6 @@ int lsh_unbookmark(char **args) {
return 1;
}
/**
* Get bookmark names for tab completion
*/
char **get_bookmark_names(int *count) {
if (bookmark_count == 0 || !count) {
*count = 0;
@@ -388,9 +344,6 @@ char **get_bookmark_names(int *count) {
return names;
}
/**
* Find a matching bookmark by partial name
*/
char *find_matching_bookmark(const char *partial_name) {
if (!partial_name || strlen(partial_name) == 0) {
return NULL;

View File

@@ -1,7 +1,3 @@
/**
* favorite_cities.c
* Implementation of favorite cities management for weather lookup
*/
#include "favorite_cities.h"
#include "builtins.h"
@@ -15,9 +11,6 @@ int favorite_city_capacity = 0;
// Path to the favorite cities file
char favorite_cities_file_path[PATH_MAX];
/**
* Initialize the favorite cities system
*/
void init_favorite_cities(void) {
// Set initial capacity
favorite_city_capacity = 10;
@@ -53,9 +46,6 @@ void init_favorite_cities(void) {
}
}
/**
* Clean up the favorite cities system
*/
void cleanup_favorite_cities(void) {
if (!favorite_cities)
return;
@@ -66,9 +56,6 @@ void cleanup_favorite_cities(void) {
favorite_city_capacity = 0;
}
/**
* Shutdown favorite cities system - save and cleanup
*/
void shutdown_favorite_cities(void) {
// Save to file first
save_favorite_cities();
@@ -77,9 +64,6 @@ void shutdown_favorite_cities(void) {
cleanup_favorite_cities();
}
/**
* Load favorite cities from file
*/
int load_favorite_cities(void) {
FILE *file = fopen(favorite_cities_file_path, "r");
if (!file) {
@@ -115,9 +99,6 @@ int load_favorite_cities(void) {
return 1;
}
/**
* Save favorite cities to file
*/
int save_favorite_cities(void) {
FILE *file = fopen(favorite_cities_file_path, "w");
if (!file) {
@@ -140,9 +121,6 @@ int save_favorite_cities(void) {
return 1;
}
/**
* Add a new favorite city
*/
int add_favorite_city(const char *name) {
if (!name)
return 0;
@@ -177,9 +155,6 @@ int add_favorite_city(const char *name) {
return 1;
}
/**
* Remove a favorite city
*/
int remove_favorite_city(const char *name) {
if (!name)
return 0;
@@ -199,9 +174,6 @@ int remove_favorite_city(const char *name) {
return 0; // City not found
}
/**
* Find a favorite city by name
*/
CityEntry *find_favorite_city(const char *name) {
if (!name)
return NULL;
@@ -215,9 +187,6 @@ CityEntry *find_favorite_city(const char *name) {
return NULL;
}
/**
* Get favorite city names for tab completion
*/
char **get_favorite_city_names(int *count) {
if (favorite_city_count == 0) {
*count = 0;
@@ -238,13 +207,6 @@ char **get_favorite_city_names(int *count) {
return names;
}
/**
* Command handler for the "cities" command
* Usage:
* cities add <city>
* cities remove <city>
* cities list
*/
int lsh_cities(char **args) {
if (args[1] == NULL) {
// No subcommand - show usage

View File

@@ -1,16 +1,8 @@
/**
* structured_data.c
* Implementation of structured data operations
* this is a comment
*/
#include "structured_data.h"
#include "builtins.h" // For set_color and reset_color functions
#include <strings.h>
/**
* Create a new table with the given headers
*/
TableData *create_table(char **headers, int header_count) {
TableData *table = (TableData *)malloc(sizeof(TableData));
if (!table) {
@@ -49,9 +41,6 @@ TableData *create_table(char **headers, int header_count) {
return table;
}
/**
* Add a row to a table
*/
void add_table_row(TableData *table, DataValue *row) {
if (!table || !row)
return;
@@ -72,9 +61,6 @@ void add_table_row(TableData *table, DataValue *row) {
table->row_count++;
}
/**
* Free all memory associated with a table
*/
void free_table(TableData *table) {
if (!table)
return;
@@ -98,9 +84,6 @@ void free_table(TableData *table) {
free(table);
}
/**
* Create a copy of a DataValue
*/
DataValue copy_data_value(const DataValue *src) {
DataValue dest;
dest.type = src->type;
@@ -123,9 +106,6 @@ DataValue copy_data_value(const DataValue *src) {
return dest;
}
/**
* Free a DataValue
*/
void free_data_value(DataValue *value) {
if (!value)
return;
@@ -137,9 +117,6 @@ void free_data_value(DataValue *value) {
}
}
/**
* Parse human-readable sizes (e.g., "10kb", "2.5MB") into bytes
*/
long parse_size(const char *size_str) {
char *unit;
double size = strtod(size_str, &unit);
@@ -180,9 +157,6 @@ long parse_size(const char *size_str) {
return (long)size; // Default to just the number if no unit matches
}
/**
* Extract size in bytes from a formatted size string (e.g., "10.5 KB")
*/
long extract_size_bytes(const char *size_str) {
double size_val = 0;
char unit[8] = "";
@@ -204,9 +178,6 @@ long extract_size_bytes(const char *size_str) {
return parse_size(size_str);
}
/**
* Filter a table based on a condition
*/
TableData *filter_table(TableData *input, char *field, char *op, char *value) {
if (!input || !field || !op || !value) {
return NULL;
@@ -332,10 +303,6 @@ TableData *filter_table(TableData *input, char *field, char *op, char *value) {
return result;
}
/**
* Print a table to the console with nice formatting using Unicode box
* characters Linux version using ANSI escape sequences for colors
*/
void print_table(TableData *table) {
if (!table || table->row_count == 0) {
printf("(empty table)\n");

View File

@@ -1,7 +1,3 @@
/**
* git_integration.c
* Implementation of Git repository detection and information
*/
#include "git_integration.h"
#include <stdio.h>
@@ -9,16 +5,10 @@
#include <sys/stat.h>
#include <unistd.h>
/**
* Initialize Git integration
*/
void init_git_integration(void) {
// No initialization needed for Linux
}
/**
* Check if the current directory is in a Git repository and get branch info
*/
int get_git_branch(char *branch_name, size_t buffer_size, int *is_dirty) {
char git_dir[PATH_MAX] = "";
char cmd[PATH_MAX] = "";
@@ -75,9 +65,6 @@ int get_git_branch(char *branch_name, size_t buffer_size, int *is_dirty) {
return status;
}
/**
* Get the name of the Git repository
*/
int get_git_repo_name(char *repo_name, size_t buffer_size) {
if (!repo_name || buffer_size == 0) {
return 0;
@@ -115,9 +102,6 @@ int get_git_repo_name(char *repo_name, size_t buffer_size) {
return 0;
}
/**
* Get Git status for the current repository
*/
char *get_git_status(void) {
char branch_name[100] = "";
int is_dirty = 0;
@@ -249,9 +233,6 @@ int get_repo_url(char *url, size_t url_size) {
return 0;
}
/**
* Check if the current branch has diverged from its remote tracking branch
*/
int check_branch_divergence(int *commits_ahead, int *commits_behind) {
if (!commits_ahead || !commits_behind) {
return 0;
@@ -394,9 +375,6 @@ int get_git_stashes(char stashes[][512], int max_stashes) {
return count;
}
/**
* Apply a git stash by index (keeps stash in list)
*/
int apply_git_stash(int stash_index) {
if (stash_index < 0) {
return 0;
@@ -410,9 +388,6 @@ int apply_git_stash(int stash_index) {
return (result == 0) ? 1 : 0;
}
/**
* Pop a git stash by index (applies and removes stash from list)
*/
int pop_git_stash(int stash_index) {
if (stash_index < 0) {
return 0;
@@ -426,9 +401,6 @@ int pop_git_stash(int stash_index) {
return (result == 0) ? 1 : 0;
}
/**
* Drop a git stash by index (removes stash without applying)
*/
int drop_git_stash(int stash_index) {
if (stash_index < 0) {
return 0;
@@ -442,9 +414,6 @@ int drop_git_stash(int stash_index) {
return (result == 0) ? 1 : 0;
}
/**
* Get detailed commit information including diff
*/
int get_commit_details(const char *commit_hash, char *commit_info,
size_t info_size) {
if (!commit_hash || !commit_info || info_size == 0) {
@@ -513,9 +482,6 @@ int get_commit_details(const char *commit_hash, char *commit_info,
return 1;
}
/**
* Get stash diff information
*/
int get_stash_diff(int stash_index, char *stash_diff, size_t diff_size) {
if (stash_index < 0 || !stash_diff || diff_size == 0) {
return 0;

View File

@@ -1,7 +1,3 @@
/**
* persistent_history.c
* Implementation of persistent command history and frequency tracking
*/
#include "persistent_history.h"
#include <ctype.h>
@@ -29,9 +25,6 @@ static int frequency_capacity = 0;
static char history_file_path[PATH_MAX];
static char frequency_file_path[PATH_MAX];
/**
* Initialize the persistent history system
*/
void init_persistent_history(void) {
// Allocate initial history capacity
history_capacity = PERSISTENT_HISTORY_SIZE;
@@ -85,10 +78,6 @@ void init_persistent_history(void) {
load_frequencies_from_file();
}
/**
* Get the most recent command that starts with the given prefix
* returns NULL if no match found
*/
char *get_most_recent_history_match(const char *prefix) {
if (!prefix || !history_entries || strlen(prefix) == 0) {
return NULL;
@@ -122,9 +111,6 @@ char *get_most_recent_history_match(const char *prefix) {
return NULL;
}
/**
* Clean up persistent history resources
*/
void cleanup_persistent_history(void) {
if (history_entries) {
for (int i = 0; i < history_size; i++) {
@@ -148,18 +134,12 @@ void cleanup_persistent_history(void) {
frequency_capacity = 0;
}
/**
* Shutdown persistent history
*/
void shutdown_persistent_history(void) {
save_history_to_file();
save_frequencies_to_file();
cleanup_persistent_history();
}
/**
* Add a command to the persistent history
*/
void add_to_history(const char *command) {
if (!command || !*command || !history_entries) {
return; // Skip empty commands
@@ -192,9 +172,6 @@ void add_to_history(const char *command) {
history_position = -1;
}
/**
* Update command frequency statistics
*/
void update_command_frequency(const char *command) {
if (!command || !*command || !command_frequencies) {
return;
@@ -228,9 +205,6 @@ void update_command_frequency(const char *command) {
frequency_count++;
}
/**
* Save history to file
*/
void save_history_to_file(void) {
if (!history_entries || history_size == 0) {
return;
@@ -257,9 +231,6 @@ void save_history_to_file(void) {
fclose(fp);
}
/**
* Load history from file
*/
void load_history_from_file(void) {
FILE *fp = fopen(history_file_path, "r");
if (!fp) {
@@ -296,9 +267,6 @@ void load_history_from_file(void) {
fclose(fp);
}
/**
* Save command frequencies to file
*/
void save_frequencies_to_file(void) {
if (!command_frequencies || frequency_count == 0) {
return;
@@ -325,9 +293,6 @@ void save_frequencies_to_file(void) {
fclose(fp);
}
/**
* Load command frequencies from file
*/
void load_frequencies_from_file(void) {
FILE *fp = fopen(frequency_file_path, "r");
if (!fp) {
@@ -364,9 +329,6 @@ void load_frequencies_from_file(void) {
fclose(fp);
}
/**
* Get the history entry at the specified index
*/
PersistentHistoryEntry *get_history_entry(int index) {
if (index < 0 || index >= history_size) {
return NULL;
@@ -374,14 +336,8 @@ PersistentHistoryEntry *get_history_entry(int index) {
return &history_entries[index];
}
/**
* Get the total number of history entries
*/
int get_history_count(void) { return history_size; }
/**
* Find the best matching command based on frequency
*/
char *find_best_frequency_match(const char *prefix) {
if (!prefix || !*prefix || !command_frequencies) {
return NULL;
@@ -408,9 +364,6 @@ char *find_best_frequency_match(const char *prefix) {
return NULL;
}
/**
* Debug function to print frequency data
*/
void debug_print_frequencies(void) {
printf("Command Frequencies:\n");
for (int i = 0; i < frequency_count; i++) {
@@ -419,9 +372,6 @@ void debug_print_frequencies(void) {
}
}
/**
* Case-insensitive substring search
*/
char *_stristr(const char *haystack, const char *needle) {
if (!haystack || !needle)
return NULL;
@@ -456,9 +406,6 @@ char *_stristr(const char *haystack, const char *needle) {
return original;
}
/**
* Get previous history entry for up-arrow key navigation
*/
char *get_previous_history_entry(int *position) {
if (!history_entries || history_size == 0) {
return NULL;
@@ -478,9 +425,6 @@ char *get_previous_history_entry(int *position) {
return history_entries[*position].command;
}
/**
* Get next history entry for down-arrow key navigation
*/
char *get_next_history_entry(int *position) {
if (!history_entries || history_size == 0 || *position < 0) {
return NULL;
@@ -498,9 +442,6 @@ char *get_next_history_entry(int *position) {
}
}
/**
* Get matching history entries for tab completion
*/
char **get_matching_history_entries(const char *prefix) {
if (!prefix || !history_entries) {
return NULL;
@@ -536,9 +477,6 @@ char **get_matching_history_entries(const char *prefix) {
return result;
}
/**
* Free matching entries array
*/
void free_matching_entries(char **entries) {
if (!entries) {
return;

View File

@@ -1,17 +1,7 @@
/**
* testing
* autocorrect.c
* Implementation of command auto-correction functionality
*/
#include "autocorrect.h"
#include "builtins.h"
/**
* Calculate Levenshtein distance between two strings
* Used to determine similarity between mistyped command and potential
* corrections
*/
int levenshtein_distance(const char *s1, const char *s2) {
int len1 = strlen(s1);
int len2 = strlen(s2);
@@ -61,9 +51,6 @@ int levenshtein_distance(const char *s1, const char *s2) {
return result;
}
/**
* Helper function to find minimum of three integers
*/
int min3(int a, int b, int c) {
int min = a;
if (b < min)
@@ -73,31 +60,16 @@ int min3(int a, int b, int c) {
return min;
}
/**
* Initialize the autocorrect system
*/
void init_autocorrect(void) {
// No initialization required currently
}
/**
* Shutdown the autocorrect system
*/
void shutdown_autocorrect(void) {
// No cleanup required currently
}
/**
* Check a command for possible corrections and suggest alternative
*/
/**
* Check a command for possible corrections and suggest alternative
*/
/**
* Check a command for possible corrections and suggest alternative
*/
char **check_for_corrections(char **args) {
if (!args || !args[0]) {
return NULL;
@@ -160,9 +132,6 @@ char **check_for_corrections(char **args) {
return NULL;
}
/**
* Count the number of arguments in a NULL-terminated array
*/
int count_args(char **args) {
int count = 0;
while (args[count] != NULL) {

View File

@@ -1,7 +1,3 @@
/**
* line_reader.c
* Implementation of line reading and parsing with context-aware suggestions
*/
#include "line_reader.h"
#include "aliases.h"
@@ -49,12 +45,6 @@ static int has_history_suggestion = 0;
#define NORMAL_COLOR "\033[0;36m" // Normal color for menu items
#define RESET_COLOR "\033[0m"
/**
* Check if a command is valid
*
* @param cmd The command to check
* @return 1 if valid, 0 if not
*/
int is_valid_command(const char *cmd) {
if (!cmd || cmd[0] == '\0') {
return 0; // Empty command is not valid
@@ -177,11 +167,6 @@ int is_valid_command(const char *cmd) {
return 0; // Command not found
}
/**
* Read a key from the terminal
*
* Handles special keys and escape sequences
*/
int read_key(void) {
unsigned char c;
int nread;
@@ -261,9 +246,6 @@ int read_key(void) {
return c;
}
/**
* Update suggestions based on current input
*/
void update_suggestions(const char *buffer, int position) {
// Free previous suggestions if any
if (suggestions) {
@@ -372,9 +354,6 @@ void update_suggestions(const char *buffer, int position) {
}
}
/**
* Display a single inline suggestion (when not in menu mode)
*/
void display_inline_suggestion(const char *prompt_buffer, const char *buffer,
int position) {
// Prioritize history suggestions when available, tab suggestions as fallback
@@ -482,9 +461,6 @@ void display_inline_suggestion(const char *prompt_buffer, const char *buffer,
}
}
/**
* Function to clear the menu
*/
void clear_menu() {
if (max_menu_lines > 0) {
// Save current cursor position
@@ -514,9 +490,6 @@ void clear_menu() {
}
// this is a test
/**
* Function to display menu of suggestions
*/
void display_menu(const char *prompt_buffer, const char *buffer, int position) {
if (!has_suggestion || suggestion_count == 0) {
@@ -612,9 +585,6 @@ void display_menu(const char *prompt_buffer, const char *buffer, int position) {
fflush(stdout);
}
/**
* Function to refresh the display - based on menu mode
*/
void refresh_display(const char *prompt_buffer, const char *buffer,
int position) {
@@ -630,11 +600,6 @@ void refresh_display(const char *prompt_buffer, const char *buffer,
}
}
/**
* Read a line of input from the user
*
* @return The line read from stdin
*/
char *lsh_read_line(void) {
int bufsize = LSH_RL_BUFSIZE;
int position = 0;
@@ -1369,12 +1334,6 @@ char *lsh_read_line(void) {
return buffer;
}
/**
* Split a line into tokens
*
* @param line The line to split
* @return NULL-terminated array of tokens
*/
char **lsh_split_line(char *line) {
int bufsize = LSH_TOK_BUFSIZE;
int position = 0;
@@ -1406,12 +1365,6 @@ char **lsh_split_line(char *line) {
return tokens;
}
/**
* Parse a token from a string, handling quoted strings
*
* @param str_ptr Pointer to the string to parse, will be updated
* @return The parsed token, or NULL if no more tokens
*/
char *parse_token(char **str_ptr) {
char *str = *str_ptr;
char *token_start;
@@ -1460,12 +1413,6 @@ char *parse_token(char **str_ptr) {
return strdup(token_start);
}
/**
* Split a line with pipes into separate command arrays
*
* @param line The line to split
* @return NULL-terminated array of NULL-terminated token arrays
*/
char ***lsh_split_piped_line(char *line) {
int cmd_bufsize = LSH_TOK_BUFSIZE;
int cmd_position = 0;

View File

@@ -1,7 +1,3 @@
/**
* tab_complete.c
* Linux implementation of tab completion
*/
#include "tab_complete.h"
#include "aliases.h"
@@ -95,25 +91,15 @@ static CommandArgInfo command_arg_info[] = {
// Global state
static CommandContext current_context;
/**
* Initialize tab completion system
*/
void init_tab_completion(void) {
// Initialize context to defaults
memset(&current_context, 0, sizeof(CommandContext));
}
/**
* Shutdown tab completion system
*/
void shutdown_tab_completion(void) {
// Nothing to clean up for now
}
/**
* Get the type of argument expected for a command and if strict matching is
* required
*/
static ArgumentType get_argument_type(const char *cmd, int *strict_match) {
if (!cmd || !*cmd) {
if (strict_match)
@@ -134,9 +120,6 @@ static ArgumentType get_argument_type(const char *cmd, int *strict_match) {
return ARG_TYPE_ANY;
}
/**
* Parse the command line to determine context
*/
static void parse_command_context(const char *buffer) {
// Reset the context
memset(&current_context, 0, sizeof(CommandContext));
@@ -189,9 +172,6 @@ static void parse_command_context(const char *buffer) {
}
}
/**
* Find all files/directories that match the beginning of path
*/
static char *find_path_completions(const char *path) {
if (!path || !*path)
return NULL;
@@ -294,9 +274,6 @@ static char *find_path_completions(const char *path) {
return completion;
}
/**
* Get the completion for a command
*/
static char *complete_command(const char *prefix) {
if (!prefix || !*prefix)
return NULL;
@@ -374,10 +351,6 @@ static char *complete_command(const char *prefix) {
return result;
}
/**
* Get all available suggestions for a specific argument type
* Returns a SuggestionList or NULL if no matches found
*/
static SuggestionList *get_suggestions_by_type(ArgumentType arg_type,
const char *token) {
if (!token)
@@ -855,10 +828,6 @@ case_label_file_dir:
return suggestions;
}
/**
* Try to complete the token as a specific argument type
* Returns the first match or NULL if no matches found
*/
static char *complete_argument_by_type(ArgumentType arg_type,
const char *token) {
if (!token)
@@ -880,9 +849,6 @@ static char *complete_argument_by_type(ArgumentType arg_type,
return NULL;
}
/**
* Free a suggestion list and all its items
*/
void free_suggestion_list(SuggestionList *list) {
if (!list)
return;
@@ -899,9 +865,6 @@ void free_suggestion_list(SuggestionList *list) {
free(list);
}
/**
* Get a list of suggestions for the current context
*/
SuggestionList *get_suggestion_list(const char *buffer, const char *prefix) {
if (!buffer)
return NULL;
@@ -994,9 +957,6 @@ SuggestionList *get_suggestion_list(const char *buffer, const char *prefix) {
return suggestions;
}
/**
* Get completion for the current context
*/
char *get_tab_completion(const char *buffer) {
if (!buffer)
return NULL;

View File

@@ -1,26 +1,10 @@
/**
* main.c
* Entry point for the LSH shell program
*/
#include "common.h"
#include "shell.h"
#include <locale.h>
/**
* Main entry point
*/
int main(int argc, char **argv) {
// Set locale to support UTF-8
setlocale(LC_ALL, "en_US.UTF-8");
// Setup terminal for proper UTF-8 handling
// This is Linux equivalent of SetConsoleOutputCP(65001)
printf("\033%%G"); // Tell terminal to use UTF-8
// Start the shell loop
printf("\033%%G");
lsh_loop();
return EXIT_SUCCESS;
}

View File

@@ -1,16 +1,9 @@
// this is another test
/**
* filters.c
* Implementation of filter commands (where, sort-by, etc.)
*/
#include "filters.h"
#include <string.h>
#include <strings.h> // For strcasecmp and strncasecmp
/**
* Filter a table based on a condition (e.g., where size > 10kb)
*/
TableData *lsh_where(TableData *input, char **args) {
if (!input || !args || !args[0]) {
fprintf(stderr, "lsh: where: missing arguments\n");
@@ -64,9 +57,6 @@ TableData *lsh_where(TableData *input, char **args) {
return filter_table(input, field, op, value);
}
/**
* Sort a table based on a column (e.g., sort-by size desc)
*/
TableData *lsh_sort_by(TableData *input, char **args) {
if (!input || !args || !args[0]) {
fprintf(stderr, "lsh: sort-by: missing arguments\n");
@@ -179,10 +169,6 @@ TableData *lsh_sort_by(TableData *input, char **args) {
return result;
}
/**
* Select specific columns from a table
* Supports both space-separated and comma-separated field names
*/
TableData *lsh_select(TableData *input, char **args) {
if (!input || !args || !args[0]) {
fprintf(stderr, "lsh: select: missing arguments\n");
@@ -355,9 +341,6 @@ TableData *lsh_select(TableData *input, char **args) {
return result;
}
/**
* Case-insensitive substring search (strcasestr equivalent for Windows)
*/
char *my_strcasestr(const char *haystack, const char *needle) {
if (!haystack || !needle)
return NULL;
@@ -379,9 +362,6 @@ char *my_strcasestr(const char *haystack, const char *needle) {
return NULL;
}
/**
* Filter rows where a column contains a substring
*/
TableData *lsh_contains(TableData *input, char **args) {
if (!input || !args || !args[0] || !args[1]) {
fprintf(stderr, "lsh: contains: missing arguments\n");
@@ -454,9 +434,6 @@ TableData *lsh_contains(TableData *input, char **args) {
return result;
}
/**
* Limit the number of rows displayed
*/
TableData *lsh_limit(TableData *input, char **args) {
if (!input || !args || !args[0]) {
fprintf(stderr, "lsh: limit: missing arguments\n");

View File

@@ -1,7 +1,3 @@
/**
* fzf_native halla
* Wrapper for the native fzf command-line fuzzy finder
*/
// this is an addition
#include "fzf_native.h"
@@ -13,11 +9,6 @@
#include <string.h>
#include <sys/stat.h> // For stat
/**
* Check if native fzf is installed on the system
*
* @return 1 if installed, 0 if not
*/
int is_fzf_installed(void) {
// Try to run fzf --version to check if it's installed
FILE *fp = popen("fzf --version 2>/dev/null", "r");
@@ -35,9 +26,6 @@ int is_fzf_installed(void) {
return has_output;
}
/**
* Display instructions for installing fzf
*/
void show_fzf_install_instructions(void) {
printf("\nfzf is not installed on this system. To use this feature, install "
"fzf:\n\n");
@@ -54,13 +42,6 @@ void show_fzf_install_instructions(void) {
printf("After installation, restart your shell.\n");
}
/**
* Run fzf with files from the current directory
*
* @param preview Enable preview window if 1
* @param args Additional arguments for fzf
* @return Selected filename or NULL if canceled
*/
char *run_native_fzf_files(int preview, char **args) {
// Check if fzf is installed
if (!is_fzf_installed()) {
@@ -151,13 +132,6 @@ char *run_native_fzf_files(int preview, char **args) {
return selected;
}
/**
* Run fzf with all files and directories from the current directory
*
* @param recursive Search recursively if 1
* @param args Additional arguments for fzf
* @return Selected path or NULL if canceled
*/
char *run_native_fzf_all(int recursive, char **args) {
// Check if fzf is installed
if (!is_fzf_installed()) {
@@ -254,11 +228,6 @@ char *run_native_fzf_all(int recursive, char **args) {
return selected;
}
/**
* Run fzf with command history
*
* @return Selected command or NULL if canceled
*/
char *run_native_fzf_history(void) {
// Check if fzf is installed
if (!is_fzf_installed()) {
@@ -355,25 +324,12 @@ char *run_native_fzf_history(void) {
return selected;
}
/**
* Check if a specific editor is available
*
* @param editor Name of the editor executable
* @return 1 if available, 0 if not
*/
int is_editor_available(const char *editor) {
char command[256];
snprintf(command, sizeof(command), "%s --version >/dev/null 2>&1", editor);
return (system(command) == 0);
}
/**
* Open a file in the best available editor in the current terminal
*
* @param file_path Path to the file to open
* @param line_number Optional line number to jump to (0 to ignore)
* @return 1 if successful, 0 if failed
*/
int open_in_best_editor(const char *file_path, int line_number) {
char command[2048] = {0};
int success = 0;
@@ -432,12 +388,6 @@ int open_in_best_editor(const char *file_path, int line_number) {
}
}
/**
* Command handler for the fzf command
*
* @param args Command arguments
* @return 1 to continue shell execution, 0 to exit shell
*/
int lsh_fzf_native(char **args) {
// Check if fzf is installed
if (!is_fzf_installed()) {

View File

@@ -1,7 +1,3 @@
/**
* grep.c
* Custom implementation of text searching for Linux using Boyer-Moore algorithm
*/
#include "grep.h"
#include "builtins.h"
@@ -327,9 +323,6 @@ int search_directory(const char *dir_path, const char *pattern, bool show_line_n
return total_matches;
}
/**
* Custom grep implementation using Boyer-Moore algorithm
*/
int lsh_actual_grep(char **args) {
if (args[1] == NULL) {
printf("Usage: grep [options] pattern [file/directory]\n");
@@ -441,12 +434,6 @@ int lsh_actual_grep(char **args) {
return 1;
}
/**
* Run grep with interactive interface
*
* Shows a split view with files on left, matches on right, and
* updates search results with each keystroke
*/
void run_interactive_grep_session(void) {
// Save original terminal settings to restore later
struct termios old_tio, new_tio;
@@ -1127,9 +1114,6 @@ void run_interactive_grep_session(void) {
printf(ANSI_CLEAR_SCREEN ANSI_CURSOR_HOME);
}
/**
* Wrapper for grep
*/
int lsh_grep(char **args) {
// If no arguments provided, run interactive grep
if (args[1] == NULL) {

View File

@@ -1,7 +1,3 @@
/**
* ripgrep.c
* Interactive wrapper for the ripgrep (rg) command-line search tool
*/
#include "ripgrep.h"
#include "common.h"
@@ -15,11 +11,6 @@
#include <unistd.h> // For access function
#include <termios.h> // For terminal control
/**
* Check if ripgrep (rg) is installed on the system
*
* @return 1 if installed, 0 if not
*/
int is_rg_installed(void) {
// Try to run rg --version to check if it's installed
FILE *fp = popen("rg --version 2>/dev/null", "r");
@@ -37,9 +28,6 @@ int is_rg_installed(void) {
return has_output;
}
/**
* Display instructions for installing ripgrep
*/
void show_rg_install_instructions(void) {
printf("\nripgrep (rg) is not installed on this system. To use this feature, "
"install ripgrep:\n\n");
@@ -55,25 +43,12 @@ void show_rg_install_instructions(void) {
printf("After installation, restart your shell.\n");
}
/**
* Check if a specific editor is available
*
* @param editor Name of the editor executable
* @return 1 if available, 0 if not
*/
int is_editor_available_for_rg(const char *editor) {
char command[256];
snprintf(command, sizeof(command), "%s --version >/dev/null 2>&1", editor);
return (system(command) == 0);
}
/**
* Open a file at a specific line in the best available editor
*
* @param file_path Path to the file to open
* @param line_number Line number to position cursor at
* @return 1 if successful, 0 if failed
*/
int rg_open_in_editor(const char *file_path, int line_number) {
char command[2048] = {0};
int success = 0;
@@ -122,16 +97,6 @@ int rg_open_in_editor(const char *file_path, int line_number) {
}
}
/**
* Parse a ripgrep result line to extract file path and line number
*
* @param result_line The result line from ripgrep (format:
* file:line:column:text)
* @param file_path Buffer to store extracted file path
* @param file_path_size Size of file_path buffer
* @param line_number Pointer to store extracted line number
* @return 1 if parsing successful, 0 if failed
*/
static int parse_rg_result(const char *result_line, char *file_path,
size_t file_path_size, int *line_number) {
// Ripgrep output format is: file:line:column:text
@@ -162,12 +127,6 @@ static int parse_rg_result(const char *result_line, char *file_path,
return 1;
}
/**
* Run ripgrep with interactive filtering
*
* @param args Command arguments or NULL for interactive mode
* @return Selected filename/line or NULL if canceled
*/
char *run_interactive_ripgrep(char **args) {
// Check if ripgrep is installed
if (!is_rg_installed()) {
@@ -268,10 +227,6 @@ char *run_interactive_ripgrep(char **args) {
return selected;
}
/**
* Run ripgrep with interactive editing capabilities for a custom Neovim-like
* experience
*/
void run_ripgrep_interactive_session(void) {
// Check if ripgrep and fzf are installed
if (!is_rg_installed()) {
@@ -505,12 +460,6 @@ void run_ripgrep_interactive_session(void) {
system("clear");
}
/**
* Command handler for the ripgrep command
*
* @param args Command arguments
* @return 1 to continue shell execution, 0 to exit shell
*/
int lsh_ripgrep(char **args) {
// Check if ripgrep is installed
if (!is_rg_installed()) {

View File

@@ -1,7 +1,3 @@
/**
* shell.c
* Implementation of core shell functionality
*/
#include "shell.h"
#include "aliases.h" // Added for alias support
@@ -33,9 +29,6 @@ static int g_status_attributes = 12; // Red
static int g_status_bar_enabled = 0; // Flag to track if status bar is enabled
static struct termios g_orig_termios; // Original terminal settings
/**
* Initialize terminal for raw mode
*/
int init_terminal(struct termios *orig_termios) {
int fd = STDIN_FILENO;
@@ -70,9 +63,6 @@ int init_terminal(struct termios *orig_termios) {
return fd;
}
/**
* Restore terminal to original settings
*/
void restore_terminal(int fd, struct termios *orig_termios) {
// Restore cursor and terminal settings
printf("\033[?25h"); // Ensure cursor is visible
@@ -83,9 +73,6 @@ void restore_terminal(int fd, struct termios *orig_termios) {
}
}
/**
* Get console dimensions
*/
int get_console_dimensions(int fd, int *width, int *height) {
struct winsize ws;
@@ -100,9 +87,6 @@ int get_console_dimensions(int fd, int *width, int *height) {
return 1;
}
/**
* Temporarily hide the status bar before command execution
*/
void hide_status_bar(int fd) {
// Skip if status bar is not enabled
if (!g_status_bar_enabled)
@@ -125,10 +109,6 @@ void hide_status_bar(int fd) {
fflush(stdout);
}
/**
* This function scrolls the console buffer up one line to make room for the
* status bar when we're at the bottom of the screen.
*/
void ensure_status_bar_space(int fd) {
int width, height;
if (!get_console_dimensions(fd, &width, &height)) {
@@ -151,9 +131,6 @@ void ensure_status_bar_space(int fd) {
fflush(stdout);
}
/**
* Initialize the status bar at the bottom of the screen
*/
int init_status_bar(int fd) {
int width, height;
if (!get_console_dimensions(fd, &width, &height)) {
@@ -174,9 +151,6 @@ int init_status_bar(int fd) {
return 1;
}
/**
* Check for console window resize and update status bar position
*/
void check_console_resize(int fd) {
if (!g_status_bar_enabled)
return;
@@ -196,9 +170,6 @@ void check_console_resize(int fd) {
}
}
/**
* Update the status bar with Git information
*/
void update_status_bar(int fd, const char *git_info) {
if (!g_status_bar_enabled)
return;
@@ -264,9 +235,6 @@ void update_status_bar(int fd, const char *git_info) {
fflush(stdout);
}
/**
* Get the name of the parent and current directories from a path
*/
void get_path_display(const char *cwd, char *parent_dir_name,
char *current_dir_name, size_t buf_size) {
@@ -330,9 +298,6 @@ void get_path_display(const char *cwd, char *parent_dir_name,
}
}
/**
* Create a TableData structure from an ls command
*/
TableData* create_ls_table(char **args) {
DIR *dir;
struct dirent *entry;
@@ -444,9 +409,6 @@ TableData* create_ls_table(char **args) {
return table;
}
/**
* Parse input line into an array of commands (for pipelines)
*/
char*** lsh_split_commands(char *line) {
char **cmd_groups = NULL;
char *cmd_group, *saveptr0;
@@ -644,9 +606,6 @@ char*** lsh_split_commands(char *line) {
return commands;
}
/**
* Launch an external program
*/
int lsh_launch(char **args) {
pid_t pid, wpid;
int status;
@@ -673,9 +632,6 @@ int lsh_launch(char **args) {
return 1;
}
/**
* Execute a command
*/
int lsh_execute(char **args) {
if (args[0] == NULL) {
// An empty command was entered
@@ -704,9 +660,6 @@ int lsh_execute(char **args) {
return lsh_launch(args);
}
/**
* Execute a pipeline of commands
*/
int lsh_execute_piped(char ***commands) {
// Count the number of commands in the pipeline
int cmd_count = 0;
@@ -833,9 +786,6 @@ int lsh_execute_piped(char ***commands) {
return 1;
}
/**
* Free memory for a command array from lsh_split_commands
*/
void free_commands(char ***commands) {
for (int i = 0; commands[i] != NULL; i++) {
for (int j = 0; commands[i][j] != NULL; j++) {
@@ -846,9 +796,6 @@ void free_commands(char ***commands) {
free(commands);
}
/**
* Display a welcome banner
*/
void display_welcome_banner(void) {
printf(ANSI_COLOR_CYAN);
printf("╔════════════════════════════════════════════════════════════╗\n");
@@ -859,9 +806,6 @@ void display_welcome_banner(void) {
printf(ANSI_COLOR_RESET);
}
/**
* Main shell loop
*/
void lsh_loop(void) {
char *line;
char **args;

View File

@@ -1,8 +1,3 @@
/**
* ps_command.c
* Implementation of the 'ps' command for listing running processes
* Simple implementation for Linux
*/
#include "builtins.h"
#include "common.h"
@@ -11,13 +6,6 @@
#include <stdlib.h>
#include <string.h>
/**
* Function to generate structured data for running processes
* This enables piping and filtering of process information
*
* @param args Command arguments
* @return TableData structure with process information
*/
TableData* lsh_ps_structured(char **args) {
// Define our table headers
char *headers[] = {"PID", "Name", "Memory", "Threads"};
@@ -93,10 +81,6 @@ TableData* lsh_ps_structured(char **args) {
return table;
}
/**
* Implementation of the ps command to display process information
* Uses structured data to show processes in a formatted table
*/
int lsh_ps_fancy(char **args) {
// Create structured data table for processes
TableData *table = lsh_ps_structured(args);

View File

@@ -1,7 +1,3 @@
/**
* diff_viewer.c
* Interactive diff viewer implementation
*/
// thisis a test
#include "diff_viewer.h"
@@ -13,9 +9,6 @@
#include <termios.h>
#include <unistd.h>
/**
* Initialize the diff viewer
*/
int init_diff_viewer(DiffViewer *viewer) {
if (!viewer)
return 0;
@@ -32,9 +25,6 @@ int init_diff_viewer(DiffViewer *viewer) {
return 1;
}
/**
* Get terminal size
*/
void get_terminal_size(int *width, int *height) {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
@@ -42,9 +32,6 @@ void get_terminal_size(int *width, int *height) {
*height = w.ws_row;
}
/**
* Get list of changed files from git
*/
int get_changed_files(DiffViewer *viewer) {
if (!viewer)
return 0;
@@ -87,9 +74,6 @@ int get_changed_files(DiffViewer *viewer) {
return viewer->file_count;
}
/**
* Check if a file is a new untracked file
*/
int is_new_file(const char *filename) {
char cmd[1024];
snprintf(cmd, sizeof(cmd), "git ls-files --error-unmatch \"%s\" 2>/dev/null",
@@ -106,9 +90,6 @@ int is_new_file(const char *filename) {
return !is_tracked; // Return 1 if not tracked (new file)
}
/**
* Load content of a new file and show all lines as additions
*/
int load_new_file_content(DiffViewer *viewer, const char *filename) {
if (!viewer || !filename)
return 0;
@@ -152,9 +133,6 @@ int load_new_file_content(DiffViewer *viewer, const char *filename) {
return viewer->diff_line_count;
}
/**
* Load diff for a specific file
*/
int load_file_diff(DiffViewer *viewer, const char *filename) {
if (!viewer || !filename)
return 0;
@@ -238,9 +216,6 @@ int load_file_diff(DiffViewer *viewer, const char *filename) {
return viewer->diff_line_count;
}
/**
* Render the diff viewer interface
*/
void render_diff_viewer(DiffViewer *viewer) {
if (!viewer)
return;
@@ -373,9 +348,6 @@ void render_diff_viewer(DiffViewer *viewer) {
fflush(stdout);
}
/**
* Handle keyboard input for navigation
*/
int handle_diff_input(DiffViewer *viewer, char key) {
if (!viewer)
return 0;
@@ -441,9 +413,6 @@ int handle_diff_input(DiffViewer *viewer, char key) {
return 1; // Continue
}
/**
* Set terminal to raw mode for interactive input
*/
void set_raw_mode(struct termios *orig_termios) {
tcgetattr(STDIN_FILENO, orig_termios);
@@ -455,16 +424,10 @@ void set_raw_mode(struct termios *orig_termios) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}
/**
* Restore terminal to original mode
*/
void restore_terminal_mode(struct termios *orig_termios) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, orig_termios);
}
/**
* Run the interactive diff viewer
*/
int run_diff_viewer(void) {
DiffViewer viewer;
struct termios orig_termios;
@@ -511,9 +474,6 @@ int run_diff_viewer(void) {
return 0;
}
/**
* Clean up diff viewer resources
*/
void cleanup_diff_viewer(DiffViewer *viewer) {
// Nothing to clean up for now, but good to have for future expansion
(void)viewer;

View File

@@ -1,7 +1,3 @@
/**
* ncurses_diff_viewer.c
* NCurses-based interactive diff viewer implementation
*/
// this is a change
// this is another change
@@ -26,9 +22,6 @@ void handle_sigwinch(int sig) {
terminal_resized = 1;
}
/**
* Handle terminal resize by recreating all windows
*/
void handle_terminal_resize(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -98,9 +91,6 @@ void handle_terminal_resize(NCursesDiffViewer *viewer) {
terminal_resized = 0;
}
/**
* Initialize the ncurses diff viewer
*/
int init_ncurses_diff_viewer(NCursesDiffViewer *viewer) {
if (!viewer)
return 0;
@@ -240,9 +230,6 @@ int init_ncurses_diff_viewer(NCursesDiffViewer *viewer) {
return 1;
}
/**
* Get list of changed files from git
*/
int get_ncurses_changed_files(NCursesDiffViewer *viewer) {
if (!viewer)
return 0;
@@ -285,9 +272,6 @@ int get_ncurses_changed_files(NCursesDiffViewer *viewer) {
return viewer->file_count;
}
/**
* Create temporary file with current working version
*/
int create_temp_file_with_changes(const char *filename, char *temp_path) {
snprintf(temp_path, 256, "/tmp/shell_diff_current_%d", getpid());
@@ -298,9 +282,6 @@ int create_temp_file_with_changes(const char *filename, char *temp_path) {
return (system(cmd) == 0);
}
/**
* Create temporary file with git HEAD version
*/
int create_temp_file_git_version(const char *filename, char *temp_path) {
snprintf(temp_path, 256, "/tmp/shell_diff_git_%d", getpid());
@@ -311,9 +292,6 @@ int create_temp_file_git_version(const char *filename, char *temp_path) {
return (system(cmd) == 0);
}
/**
* Check if a file is a new untracked file
*/
int is_ncurses_new_file(const char *filename) {
char cmd[1024];
snprintf(cmd, sizeof(cmd), "git ls-files --error-unmatch \"%s\" 2>/dev/null",
@@ -330,9 +308,6 @@ int is_ncurses_new_file(const char *filename) {
return !is_tracked; // Return 1 if not tracked (new file)
}
/**
* Load file with staging information
*/
int load_file_with_staging_info(NCursesDiffViewer *viewer,
const char *filename) {
@@ -484,9 +459,6 @@ int load_file_with_staging_info(NCursesDiffViewer *viewer,
return viewer->file_line_count;
}
/**
* Stage/unstage a single line by line index
*/
// this is a change
// this is another change
@@ -547,9 +519,6 @@ int stage_hunk_by_line(NCursesDiffViewer *viewer, int line_index) {
return 1;
}
/**
* Rebuild staged view with proper git patch format for individual lines
*/
void rebuild_staged_view(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -682,9 +651,6 @@ void rebuild_staged_view(NCursesDiffViewer *viewer) {
}
}
/**
* Rebuild staged view from what's actually staged in git
*/
void rebuild_staged_view_from_git(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -794,9 +760,6 @@ void rebuild_staged_view_from_git(NCursesDiffViewer *viewer) {
pclose(diff_fp);
}
/**
* Apply staged changes using git
*/
int apply_staged_changes(NCursesDiffViewer *viewer) {
if (!viewer || viewer->staged_line_count == 0)
@@ -844,9 +807,6 @@ int apply_staged_changes(NCursesDiffViewer *viewer) {
return (result == 0);
}
/**
* Unstage a specific line from the staged pane
*/
int unstage_line_from_git(NCursesDiffViewer *viewer, int staged_line_index) {
if (!viewer || staged_line_index < 0 ||
@@ -884,9 +844,6 @@ int unstage_line_from_git(NCursesDiffViewer *viewer, int staged_line_index) {
return 0;
}
/**
* Reset staged changes
*/
int reset_staged_changes(NCursesDiffViewer *viewer) {
if (!viewer)
@@ -902,9 +859,6 @@ int reset_staged_changes(NCursesDiffViewer *viewer) {
return 1;
}
/**
* Draw a box with rounded corners
*/
void draw_rounded_box(WINDOW *win) {
if (!win)
return;
@@ -931,9 +885,6 @@ void draw_rounded_box(WINDOW *win) {
mvwaddch(win, height - 1, width - 1, ACS_LRCORNER);
}
/**
* Get commit history
*/
int get_commit_history(NCursesDiffViewer *viewer) {
if (!viewer)
return 0;
@@ -1056,9 +1007,6 @@ int get_commit_history(NCursesDiffViewer *viewer) {
return viewer->commit_count;
}
/**
* Toggle file marking for commit
*/
void toggle_file_mark(NCursesDiffViewer *viewer, int file_index) {
if (!viewer || file_index < 0 || file_index >= viewer->file_count)
return;
@@ -1067,9 +1015,6 @@ void toggle_file_mark(NCursesDiffViewer *viewer, int file_index) {
!viewer->files[file_index].marked_for_commit;
}
/**
* Mark all files for commit (or unmark if all are already marked)
*/
void mark_all_files(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -1089,10 +1034,6 @@ void mark_all_files(NCursesDiffViewer *viewer) {
}
}
/**
* Show confirmation dialog for diverged branch
* Returns 1 for force push, 0 for cancel
*/
int show_diverged_branch_dialog(int commits_ahead, int commits_behind) {
// Save current screen
WINDOW *saved_screen = dupwin(stdscr);
@@ -1157,10 +1098,6 @@ int show_diverged_branch_dialog(int commits_ahead, int commits_behind) {
return result;
}
/**
* Show confirmation dialog requiring user to type "yes"
* Returns 1 if confirmed, 0 if cancelled
*/
int show_reset_confirmation_dialog(void) {
// Save current screen
WINDOW *saved_screen = dupwin(stdscr);
@@ -1253,9 +1190,6 @@ int show_reset_confirmation_dialog(void) {
return 0;
}
/**
* Get commit title and message input from user
*/
int get_commit_title_input(char *title, int max_len, char *message,
int max_message_len) {
@@ -1560,9 +1494,6 @@ int get_commit_title_input(char *title, int max_len, char *message,
return strlen(title) > 0 ? 1 : 0;
}
/**
* Commit marked files with title and message
*/
int commit_marked_files(NCursesDiffViewer *viewer, const char *commit_title,
const char *commit_message) {
if (!viewer || !commit_title || strlen(commit_title) == 0)
@@ -1634,9 +1565,6 @@ int commit_marked_files(NCursesDiffViewer *viewer, const char *commit_title,
return 0;
}
/**
* Reset commit (soft) - undo commit but keep changes
*/
int reset_commit_soft(NCursesDiffViewer *viewer, int commit_index) {
if (!viewer || commit_index < 0 || commit_index >= viewer->commit_count)
return 0;
@@ -1668,9 +1596,6 @@ int reset_commit_soft(NCursesDiffViewer *viewer, int commit_index) {
return 0;
}
/**
* Reset commit (hard) - undo commit and discard changes
*/
int reset_commit_hard(NCursesDiffViewer *viewer, int commit_index) {
if (!viewer || commit_index < 0 || commit_index >= viewer->commit_count)
return 0;
@@ -1712,9 +1637,6 @@ int reset_commit_hard(NCursesDiffViewer *viewer, int commit_index) {
return 0;
}
/**
* Amend the most recent commit
*/
int amend_commit(NCursesDiffViewer *viewer) {
if (!viewer || viewer->commit_count == 0)
return 0;
@@ -2205,9 +2127,6 @@ int execute_git_with_auth(const char *base_cmd, const char *username,
return result;
}
/**
* Push specific commit
*/
int push_commit(NCursesDiffViewer *viewer, int commit_index) {
if (!viewer || commit_index < 0 || commit_index >= viewer->commit_count)
return 0;
@@ -2427,9 +2346,6 @@ int push_commit(NCursesDiffViewer *viewer, int commit_index) {
return 0;
}
/**
* Pull commits from remote
*/
int pull_commits(NCursesDiffViewer *viewer) {
if (!viewer)
return 0;
@@ -2471,9 +2387,6 @@ int pull_commits(NCursesDiffViewer *viewer) {
return 0;
}
/**
* Render the file list window
*/
void render_file_list_window(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->file_list_win)
return;
@@ -2614,9 +2527,6 @@ void render_file_list_window(NCursesDiffViewer *viewer) {
wrefresh(viewer->file_list_win);
}
/**
* Render the commit list window
*/
void render_commit_list_window(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->commit_list_win)
@@ -2730,9 +2640,6 @@ void render_commit_list_window(NCursesDiffViewer *viewer) {
wrefresh(viewer->commit_list_win);
}
/**
* Render the file content window with split staging view
*/
void render_file_content_window(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->file_content_win)
return;
@@ -2966,9 +2873,6 @@ void render_file_content_window(NCursesDiffViewer *viewer) {
wrefresh(viewer->file_content_win);
}
/**
* Render the status bar
*/
void render_status_bar(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->status_bar_win)
return;
@@ -3148,9 +3052,6 @@ void render_status_bar(NCursesDiffViewer *viewer) {
refresh();
}
/**
* Update sync status and check for new files
*/
void update_sync_status(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -3464,9 +3365,6 @@ int commit_staged_changes_only(NCursesDiffViewer *viewer,
return 0;
}
/**
* Handle keyboard input for navigation
*/
int handle_ncurses_diff_input(NCursesDiffViewer *viewer, int key) {
if (!viewer)
return 0;
@@ -4749,9 +4647,6 @@ int handle_ncurses_diff_input(NCursesDiffViewer *viewer, int key) {
return 1; // Continue
}
/**
* Run the ncurses diff viewer
*/
int run_ncurses_diff_viewer(void) {
NCursesDiffViewer viewer;
@@ -4882,13 +4777,7 @@ int run_ncurses_diff_viewer(void) {
return 0;
}
/**
* Get list of git stashes
*/
/**
* Get list of git branches
*/
int get_ncurses_git_branches(NCursesDiffViewer *viewer) {
if (!viewer)
@@ -4999,9 +4888,6 @@ int get_ncurses_git_branches(NCursesDiffViewer *viewer) {
return 1;
}
/**
* Get branch name input from user for new branch creation
*/
int get_branch_name_input(char *branch_name, int max_len) {
if (!branch_name || max_len <= 0)
return 0;
@@ -5086,9 +4972,6 @@ cleanup:
return result;
}
/**
* Create a new git branch
*/
int create_git_branch(const char *branch_name) {
if (!branch_name || strlen(branch_name) == 0)
return 0;
@@ -5112,9 +4995,6 @@ int create_git_branch(const char *branch_name) {
return (system(cmd) == 0);
}
/**
* Get new branch name input from user for branch renaming
*/
int get_rename_branch_input(const char *current_name, char *new_name,
int max_len) {
if (!current_name || !new_name || max_len <= 0)
@@ -5205,9 +5085,6 @@ cleanup_rename:
return result;
}
/**
* Rename a git branch
*/
int rename_git_branch(const char *old_name, const char *new_name) {
if (!old_name || !new_name || strlen(old_name) == 0 || strlen(new_name) == 0)
return 0;
@@ -5219,9 +5096,6 @@ int rename_git_branch(const char *old_name, const char *new_name) {
return (system(cmd) == 0);
}
/**
* Show delete branch confirmation dialog
*/
int show_delete_branch_dialog(const char *branch_name) {
if (!branch_name)
return DELETE_CANCEL;
@@ -5302,9 +5176,6 @@ int show_delete_branch_dialog(const char *branch_name) {
}
}
/**
* Show universal error popup
*/
void show_error_popup(const char *error_message) {
if (!error_message)
return;
@@ -5341,9 +5212,6 @@ void show_error_popup(const char *error_message) {
refresh();
}
/**
* Get available git remotes
*/
int get_git_remotes(char remotes[][256], int max_remotes) {
FILE *fp = popen("git remote 2>/dev/null", "r");
if (!fp)
@@ -5370,9 +5238,6 @@ int get_git_remotes(char remotes[][256], int max_remotes) {
return count;
}
/**
* Show upstream selection dialog
*/
int show_upstream_selection_dialog(const char *branch_name,
char *upstream_result, int max_len) {
if (!branch_name || !upstream_result)
@@ -5498,9 +5363,6 @@ int show_upstream_selection_dialog(const char *branch_name,
return 0;
}
/**
* Get current git branch name
*/
int get_current_branch_name(char *branch_name, int max_len) {
if (!branch_name)
return 0;
@@ -5523,9 +5385,6 @@ int get_current_branch_name(char *branch_name, int max_len) {
return 0;
}
/**
* Check if a branch has an upstream
*/
int branch_has_upstream(const char *branch_name) {
if (!branch_name)
return 0;
@@ -5537,9 +5396,6 @@ int branch_has_upstream(const char *branch_name) {
return (system(cmd) == 0);
}
/**
* Delete git branch based on option
*/
int delete_git_branch(const char *branch_name, DeleteBranchOption option) {
if (!branch_name || option == DELETE_CANCEL)
return 0;
@@ -5607,9 +5463,6 @@ int get_ncurses_git_stashes(NCursesDiffViewer *viewer) {
return viewer->stash_count;
}
/**
* Get stash name input from user
*/
int get_stash_name_input(char *stash_name, int max_len) {
if (!stash_name)
return 0;
@@ -5761,9 +5614,6 @@ int get_stash_name_input(char *stash_name, int max_len) {
return strlen(stash_name) > 0 ? 1 : 0;
}
/**
* Create a new git stash
*/
int create_ncurses_git_stash(NCursesDiffViewer *viewer) {
if (!viewer)
return 0;
@@ -5797,9 +5647,6 @@ int create_ncurses_git_stash(NCursesDiffViewer *viewer) {
return result;
}
/**
* Render the stash list window
*/
void render_stash_list_window(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->stash_list_win)
return;
@@ -6169,9 +6016,6 @@ void render_branch_list_window(NCursesDiffViewer *viewer) {
wrefresh(viewer->branch_list_win);
}
/**
* Parse and load content lines from text with diff highlighting
*/
int parse_content_lines(NCursesDiffViewer *viewer, const char *content) {
if (!viewer || !content) {
return 0;
@@ -6250,9 +6094,6 @@ int parse_content_lines(NCursesDiffViewer *viewer, const char *content) {
return viewer->file_line_count;
}
/**
* Load commit details for viewing
*/
int load_commit_for_viewing(NCursesDiffViewer *viewer,
const char *commit_hash) {
if (!viewer || !commit_hash) {
@@ -6274,9 +6115,6 @@ int load_commit_for_viewing(NCursesDiffViewer *viewer,
return 0;
}
/**
* Load stash details for viewing
*/
int load_stash_for_viewing(NCursesDiffViewer *viewer, int stash_index) {
if (!viewer || stash_index < 0) {
return 0;
@@ -6297,9 +6135,6 @@ int load_stash_for_viewing(NCursesDiffViewer *viewer, int stash_index) {
return 0;
}
/**
* Load commits for a specific branch for the hover preview
*/
int load_branch_commits(NCursesDiffViewer *viewer, const char *branch_name) {
if (!viewer || !branch_name) {
return 0;
@@ -6322,9 +6157,6 @@ int load_branch_commits(NCursesDiffViewer *viewer, const char *branch_name) {
return viewer->branch_commit_count;
}
/**
* Parse branch commits into navigable lines for branch view mode
*/
int parse_branch_commits_to_lines(NCursesDiffViewer *viewer) {
if (!viewer || viewer->branch_commit_count == 0) {
return 0;
@@ -6394,9 +6226,6 @@ int parse_branch_commits_to_lines(NCursesDiffViewer *viewer) {
return viewer->file_line_count;
}
/**
* Start background fetch process
*/
void start_background_fetch(NCursesDiffViewer *viewer) {
if (!viewer || viewer->fetch_in_progress ||
viewer->critical_operation_in_progress) {
@@ -6417,9 +6246,6 @@ void start_background_fetch(NCursesDiffViewer *viewer) {
}
}
/**
* Check if background fetch is complete and update UI accordingly
*/
void check_background_fetch(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->fetch_in_progress) {
return;
@@ -6497,9 +6323,6 @@ void check_background_fetch(NCursesDiffViewer *viewer) {
}
}
/**
* Update preview based on current mode and selection
*/
void update_preview_for_current_selection(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -6565,9 +6388,6 @@ void update_preview_for_current_selection(NCursesDiffViewer *viewer) {
}
}
/**
* Load file preview showing the top of the file content
*/
int load_file_preview(NCursesDiffViewer *viewer, const char *filename) {
if (!viewer || !filename)
return 0;
@@ -6620,10 +6440,6 @@ int load_file_preview(NCursesDiffViewer *viewer, const char *filename) {
return 1;
}
/**
* Helper function to wrap a long line into multiple display lines
* Returns the number of wrapped lines created
*/
int wrap_line_to_width(const char *input_line, char wrapped_lines[][1024],
int max_lines, int width) {
int input_len = strlen(input_line);
@@ -6655,10 +6471,6 @@ int wrap_line_to_width(const char *input_line, char wrapped_lines[][1024],
return line_count;
}
/**
* Render a single line with proper wrapping and coloring
* Returns the number of display rows used
*/
int render_wrapped_line(WINDOW *win, const char *line, int start_y, int start_x,
int width, int max_rows, int color_pair, int reverse) {
char wrapped_lines[10]
@@ -6689,9 +6501,6 @@ int render_wrapped_line(WINDOW *win, const char *line, int start_y, int start_x,
return rows_used;
}
/**
* Calculate how many display lines a wrapped line will take
*/
int calculate_wrapped_line_height(const char *line, int width) {
int line_len = strlen(line);
if (line_len <= width) {
@@ -6700,10 +6509,6 @@ int calculate_wrapped_line_height(const char *line, int width) {
return (line_len + width - 1) / width; // Ceiling division
}
/**
* Move cursor up/down while skipping empty lines
* direction: -1 for up, 1 for down
*/
void move_cursor_smart(NCursesDiffViewer *viewer, int direction) {
if (!viewer || viewer->file_line_count == 0) {
return;
@@ -6783,10 +6588,6 @@ void move_cursor_smart(NCursesDiffViewer *viewer, int direction) {
}
}
/**
* Move cursor up/down in unstaged pane with proper scrolling
* direction: -1 for up, 1 for down
*/
void move_cursor_smart_unstaged(NCursesDiffViewer *viewer, int direction) {
if (!viewer || viewer->file_line_count == 0) {
return;
@@ -6895,10 +6696,6 @@ void move_cursor_smart_unstaged(NCursesDiffViewer *viewer, int direction) {
}
}
/**
* Move cursor up/down in staged pane with proper scrolling
* direction: -1 for up, 1 for down
*/
void move_cursor_smart_staged(NCursesDiffViewer *viewer, int direction) {
if (!viewer || viewer->staged_line_count == 0) {
return;
@@ -6985,9 +6782,6 @@ void move_cursor_smart_staged(NCursesDiffViewer *viewer, int direction) {
}
}
/**
* Clean up ncurses diff viewer resources
*/
void cleanup_ncurses_diff_viewer(NCursesDiffViewer *viewer) {
if (viewer) {
// Clean up any background fetch process
@@ -7024,9 +6818,6 @@ void cleanup_ncurses_diff_viewer(NCursesDiffViewer *viewer) {
endwin();
}
/**
* Initialize fuzzy search state
*/
void init_fuzzy_search(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7050,9 +6841,6 @@ void init_fuzzy_search(NCursesDiffViewer *viewer) {
viewer->fuzzy_last_filtered_count = -1;
}
/**
* Cleanup fuzzy search windows
*/
void cleanup_fuzzy_search(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7067,10 +6855,6 @@ void cleanup_fuzzy_search(NCursesDiffViewer *viewer) {
}
}
/**
* Calculate fuzzy match score - higher score is better match
* Returns 0 if no match, positive score if match
*/
int calculate_fuzzy_score(const char *pattern, const char *filename) {
if (!pattern || !filename)
return 0;
@@ -7149,9 +6933,6 @@ int calculate_fuzzy_score(const char *pattern, const char *filename) {
return score;
}
/**
* Compare function for sorting scored files (higher scores first)
*/
int compare_scored_files(const void *a, const void *b) {
const struct {
int file_index;
@@ -7165,9 +6946,6 @@ int compare_scored_files(const void *a, const void *b) {
file_a->score; // Descending order (higher scores first)
}
/**
* Update fuzzy search filter based on current query
*/
void update_fuzzy_filter(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7196,9 +6974,6 @@ void update_fuzzy_filter(NCursesDiffViewer *viewer) {
}
}
/**
* Enter fuzzy search mode
*/
void enter_fuzzy_search_mode(NCursesDiffViewer *viewer) {
if (!viewer || viewer->current_mode != NCURSES_MODE_FILE_LIST)
return;
@@ -7234,9 +7009,6 @@ void enter_fuzzy_search_mode(NCursesDiffViewer *viewer) {
viewer->fuzzy_needs_full_redraw = 1;
}
/**
* Exit fuzzy search mode
*/
void exit_fuzzy_search_mode(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7249,9 +7021,6 @@ void exit_fuzzy_search_mode(NCursesDiffViewer *viewer) {
refresh();
}
/**
* Render fuzzy search input field only
*/
void render_fuzzy_input(NCursesDiffViewer *viewer) {
if (!viewer->fuzzy_input_win)
return;
@@ -7275,9 +7044,6 @@ void render_fuzzy_input(NCursesDiffViewer *viewer) {
wrefresh(viewer->fuzzy_input_win);
}
/**
* Render fuzzy search file list content only (no borders)
*/
void render_fuzzy_list_content(NCursesDiffViewer *viewer) {
if (!viewer->fuzzy_list_win)
return;
@@ -7329,9 +7095,6 @@ void render_fuzzy_list_content(NCursesDiffViewer *viewer) {
wrefresh(viewer->fuzzy_list_win);
}
/**
* Create fuzzy search windows with borders (one-time setup)
*/
void create_fuzzy_windows_with_borders(NCursesDiffViewer *viewer) {
if (!viewer->fuzzy_input_win || !viewer->fuzzy_list_win)
return;
@@ -7348,9 +7111,6 @@ void create_fuzzy_windows_with_borders(NCursesDiffViewer *viewer) {
wrefresh(viewer->fuzzy_list_win);
}
/**
* Main fuzzy search render function with granular updates
*/
void render_fuzzy_search(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->fuzzy_search_active)
return;
@@ -7393,9 +7153,6 @@ void render_fuzzy_search(NCursesDiffViewer *viewer) {
viewer->fuzzy_last_filtered_count = viewer->fuzzy_filtered_count;
}
/**
* Handle fuzzy search input
*/
int handle_fuzzy_search_input(NCursesDiffViewer *viewer, int key) {
if (!viewer || !viewer->fuzzy_search_active)
return 0;
@@ -7458,9 +7215,6 @@ int handle_fuzzy_search_input(NCursesDiffViewer *viewer, int key) {
}
}
/**
* Select file from fuzzy search results
*/
void select_fuzzy_file(NCursesDiffViewer *viewer) {
if (!viewer || viewer->fuzzy_filtered_count == 0)
return;
@@ -7506,9 +7260,6 @@ void select_fuzzy_file(NCursesDiffViewer *viewer) {
}
}
/**
* Initialize grep search state
*/
void init_grep_search(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7533,9 +7284,6 @@ void init_grep_search(NCursesDiffViewer *viewer) {
viewer->grep_last_filtered_count = -1;
}
/**
* Cleanup grep search windows
*/
void cleanup_grep_search(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7550,9 +7298,6 @@ void cleanup_grep_search(NCursesDiffViewer *viewer) {
}
}
/**
* Extract branch name from stash info
*/
void extract_branch_from_stash(const char *stash_info, char *branch_name,
int max_len) {
if (!stash_info || !branch_name || max_len <= 0)
@@ -7583,9 +7328,6 @@ void extract_branch_from_stash(const char *stash_info, char *branch_name,
}
}
/**
* Calculate grep match score for text content
*/
int calculate_grep_score(const char *pattern, const char *text) {
if (!pattern || !text)
return 0;
@@ -7648,9 +7390,6 @@ int calculate_grep_score(const char *pattern, const char *text) {
return score;
}
/**
* Compare function for sorting grep scored items
*/
int compare_grep_scored_items(const void *a, const void *b) {
const struct {
int item_index;
@@ -7663,9 +7402,6 @@ int compare_grep_scored_items(const void *a, const void *b) {
return item_b->score - item_a->score; // Descending order
}
/**
* Update grep search filter based on current query and mode
*/
void update_grep_filter(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7758,9 +7494,6 @@ void update_grep_filter(NCursesDiffViewer *viewer) {
}
}
/**
* Enter grep search mode for current view mode
*/
void enter_grep_search_mode(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7795,9 +7528,6 @@ void enter_grep_search_mode(NCursesDiffViewer *viewer) {
viewer->grep_needs_full_redraw = 1;
}
/**
* Exit grep search mode
*/
void exit_grep_search_mode(NCursesDiffViewer *viewer) {
if (!viewer)
return;
@@ -7810,9 +7540,6 @@ void exit_grep_search_mode(NCursesDiffViewer *viewer) {
refresh();
}
/**
* Render grep search input field only
*/
void render_grep_input(NCursesDiffViewer *viewer) {
if (!viewer->grep_input_win)
return;
@@ -7836,9 +7563,6 @@ void render_grep_input(NCursesDiffViewer *viewer) {
wrefresh(viewer->grep_input_win);
}
/**
* Render grep search list content only (no borders)
*/
void render_grep_list_content(NCursesDiffViewer *viewer) {
if (!viewer->grep_list_win)
return;
@@ -7980,9 +7704,6 @@ void render_grep_list_content(NCursesDiffViewer *viewer) {
wrefresh(viewer->grep_list_win);
}
/**
* Create grep search windows with borders (one-time setup)
*/
void create_grep_windows_with_borders(NCursesDiffViewer *viewer) {
if (!viewer->grep_input_win || !viewer->grep_list_win)
return;
@@ -8015,9 +7736,6 @@ void create_grep_windows_with_borders(NCursesDiffViewer *viewer) {
wrefresh(viewer->grep_list_win);
}
/**
* Main grep search render function with granular updates
*/
void render_grep_search(NCursesDiffViewer *viewer) {
if (!viewer || !viewer->grep_search_active)
return;
@@ -8060,9 +7778,6 @@ void render_grep_search(NCursesDiffViewer *viewer) {
viewer->grep_last_filtered_count = viewer->grep_filtered_count;
}
/**
* Handle grep search input
*/
int handle_grep_search_input(NCursesDiffViewer *viewer, int key) {
if (!viewer || !viewer->grep_search_active)
return 0;
@@ -8125,9 +7840,6 @@ int handle_grep_search_input(NCursesDiffViewer *viewer, int key) {
}
}
/**
* Select item from grep search results
*/
void select_grep_item(NCursesDiffViewer *viewer) {
if (!viewer || viewer->grep_filtered_count == 0)
return;

View File

@@ -1,7 +1,3 @@
/**
* themes.c
* Implementation of theme system for shell appearance
*/
#include "themes.h"
#include <stdio.h>
@@ -195,9 +191,6 @@ static ShellTheme catppuccin_mocha_theme = {
// Path to the theme configuration file
char theme_config_path[PATH_MAX];
/**
* Initialize the theme system
*/
void init_theme_system(void) {
// Determine theme config file location in user's home directory
char *home_dir = getenv("HOME");
@@ -230,12 +223,6 @@ void init_theme_system(void) {
}
}
/**
* Load a specific theme by name
*
* @param theme_name Name of the theme to load
* @return 1 if successful, 0 if theme not found
*/
int load_theme(const char *theme_name) {
if (strcmp(theme_name, "default") == 0) {
memcpy(&current_theme, &default_theme, sizeof(ShellTheme));
@@ -253,10 +240,6 @@ int load_theme(const char *theme_name) {
return 0;
}
/**
* Apply the current theme settings
* Called whenever theme-dependent UI elements need to be updated
*/
void apply_current_theme(void) {
// When called, the shell can update any on-screen elements that depend on
// theme colors. This function would be called when changing themes or at startup.
@@ -289,16 +272,8 @@ void apply_current_theme(void) {
}
}
/**
* Get pointer to the current theme
*
* @return Pointer to the current theme structure
*/
const ShellTheme *get_current_theme(void) { return &current_theme; }
/**
* List all available themes
*/
void list_available_themes(void) {
printf("Available themes:\n");
printf(" default - Standard shell colors\n");
@@ -317,9 +292,6 @@ void list_available_themes(void) {
}
}
/**
* Initialize themes at shell startup
*/
void init_themes(void) {
// Call the theme system initialization
init_theme_system();
@@ -328,9 +300,6 @@ void init_themes(void) {
apply_current_theme();
}
/**
* Shutdown theme system
*/
void shutdown_themes(void) {
// Reset terminal color to default
printf(ANSI_COLOR_RESET);
@@ -338,12 +307,6 @@ void shutdown_themes(void) {
// Currently, no other cleanup is needed for the theme system
}
/**
* Command handler for the "theme" command
*
* @param args Command arguments
* @return 1 to continue shell execution, 0 to exit shell
*/
int lsh_theme(char **args) {
if (args[1] == NULL) {
// No arguments, show usage info and current theme

View File

@@ -1,7 +1,3 @@
/**
* countdown_timer.c
* Implementation of a focus timer that integrates with the shell status bar
*/
#include "countdown_timer.h"
#include "common.h"
@@ -28,9 +24,6 @@ static struct {
// programs
} timer_state = {FALSE, 0, "", "", 0, FALSE, FALSE};
/**
* Update timer display text based on remaining time
*/
static void update_timer_display(void) {
if (!timer_state.is_active) {
strcpy(timer_state.display_text, "");
@@ -66,9 +59,6 @@ static void update_timer_display(void) {
}
}
/**
* Timer thread function
*/
static void *timer_thread_func(void *param) {
while (!timer_state.should_exit) {
// Update timer display
@@ -94,9 +84,6 @@ static void *timer_thread_func(void *param) {
return NULL;
}
/**
* Start a new countdown timer
*/
int start_countdown_timer(int seconds, const char *name) {
// Stop any existing timer
if (timer_state.is_active) {
@@ -136,9 +123,6 @@ int start_countdown_timer(int seconds, const char *name) {
return 1;
}
/**
* Stop the current countdown timer
*/
void stop_countdown_timer() {
if (!timer_state.is_active) {
return;
@@ -165,14 +149,8 @@ void stop_countdown_timer() {
timer_state.session_name[0] = '\0';
}
/**
* Check if a timer is currently active
*/
BOOL is_timer_active() { return timer_state.is_active; }
/**
* Get the current timer display text
*/
const char *get_timer_display() {
if (timer_state.is_temporarily_hidden || !timer_state.is_active) {
return "";
@@ -180,19 +158,10 @@ const char *get_timer_display() {
return timer_state.display_text;
}
/**
* Temporarily hide the timer display
*/
void hide_timer_display(void) { timer_state.is_temporarily_hidden = TRUE; }
/**
* Restore the timer display after it was hidden
*/
void show_timer_display(void) { timer_state.is_temporarily_hidden = FALSE; }
/**
* Parse time string in format "XhYmZs" to seconds
*/
static int parse_time_string(const char *time_str) {
if (!time_str || !*time_str) {
return 0;
@@ -252,9 +221,6 @@ static int parse_time_string(const char *time_str) {
return total_seconds;
}
/**
* Command handler for the focus timer command
*/
int lsh_focus_timer(char **args) {
if (!args[1]) {
// No arguments - show help

View File

@@ -1,20 +1,9 @@
/**
* timer.c
* Implements a command to measure execution time of other commands
*/
#include "builtins.h"
#include "common.h"
#include "shell.h"
#include <time.h>
/**
* Format a time interval in milliseconds to a readable string
*
* @param ms Time in milliseconds
* @param buffer Buffer to store formatted time
* @param buffer_size Size of the buffer
*/
void format_time(double ms, char *buffer, size_t buffer_size) {
if (ms < 1.0) {
// Microseconds
@@ -33,13 +22,6 @@ void format_time(double ms, char *buffer, size_t buffer_size) {
}
}
/**
* Implementation of the timer command
* Usage: timer COMMAND [ARGS...]
*
* @param args Command arguments
* @return 1 to continue, 0 to exit
*/
int lsh_timer(char **args) {
if (!args[1]) {
printf("timer: usage: timer COMMAND [ARGS...]\n");
@@ -87,11 +69,4 @@ int lsh_timer(char **args) {
return result;
}
/**
* Implementation of the time command (alias for timer)
* Usage: time COMMAND [ARGS...]
*
* @param args Command arguments
* @return 1 to continue, 0 to exit
*/
int lsh_time(char **args) { return lsh_timer(args); }

View File

@@ -1,8 +1,3 @@
/**
* weather.c
* Implementation of weather information fetching and display for Linux
* Uses wttr.in service to display weather with its rich UI
*/
#include "weather.h"
#include "favorite_cities.h"
@@ -13,10 +8,6 @@
// this is a test
// this is another test
/**
* Command handler for the "weather" command
* Executes curl to get weather from wttr.in with full UI
*/
int lsh_weather(char **args) {
char command[256];
char location[128] = ""; // Default empty location