This commit is contained in:
2025-05-03 15:50:41 +02:00
parent a4512c95b3
commit 5cab701dba
7 changed files with 1156 additions and 71 deletions

1124
grep.c

File diff suppressed because it is too large Load Diff

11
grep.h
View File

@@ -8,6 +8,14 @@
#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
*
@@ -20,6 +28,9 @@
* --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
*/

BIN
grep.o

Binary file not shown.

BIN
shell

Binary file not shown.

5
test.txt Normal file
View File

@@ -0,0 +1,5 @@
hello world
This is a test file for the grep command
It contains multiple lines
Boyer-Moore algorithm
testing the grep

View File

@@ -1,8 +1,7 @@
/**
* weather.c
* Implementation of weather information fetching and display for Linux
* This is a simplified version that provides basic information about using curl/wget
* instead of implementing full HTTP functionality
* Uses wttr.in service to display weather with its rich UI
*/
#include "weather.h"
@@ -14,62 +13,44 @@
/**
* Command handler for the "weather" command
* In this Linux version, we'll provide instructions for using curl/wget
* Executes curl to get weather from wttr.in with full UI
*/
int lsh_weather(char **args) {
printf("\n");
printf("╭─────────────────────────────────────────────────────────────╮\n");
printf("│ Weather Command (Linux Version) │\n");
printf("├─────────────────────────────────────────────────────────────┤\n");
printf("│ This is a simplified version of the weather command for │\n");
printf("│ Linux. The full version would use libcurl for HTTP requests. │\n");
printf("│ │\n");
printf("│ To get weather information on Linux: │\n");
printf("│ │\n");
printf("│ 1. Using curl: │\n");
printf("│ curl wttr.in/[city] │\n");
printf("│ │\n");
printf("│ 2. Using wget: │\n");
printf("│ wget -O - wttr.in/[city] │\n");
printf("│ │\n");
printf("│ For example: │\n");
printf("│ curl wttr.in/London │\n");
printf("│ curl wttr.in/\"New York\" │\n");
printf("│ │\n");
printf("│ For a shorter format: │\n");
printf("│ curl wttr.in/London?format=3 │\n");
printf("│ │\n");
printf("├─────────────────────────────────────────────────────────────┤\n");
// Check if a city was provided as an argument
char command[256];
char location[128] = ""; // Default empty location
// Check if a location was provided as an argument
if (args[1]) {
char command[256];
// Use wttr.in for a simple demonstration
snprintf(command, sizeof(command), "curl -s wttr.in/%s?format=3", args[1]);
printf("│ Running: %-47s │\n", command);
printf("├─────────────────────────────────────────────────────────────┤\n");
printf("│ Result: │\n");
printf("│ │\n");
// Execute the command
FILE *fp = popen(command, "r");
if (fp) {
char buffer[256];
if (fgets(buffer, sizeof(buffer), fp)) {
// Print the result with padding
printf("│ %-53s │\n", buffer);
} else {
printf("│ No result returned │\n");
}
pclose(fp);
} else {
printf("│ Error executing command │\n");
}
printf("│ │\n");
// Use the provided location
strncpy(location, args[1], sizeof(location) - 1);
location[sizeof(location) - 1] = '\0';
} else {
// No location provided, use current location (blank parameter to wttr.in)
location[0] = '\0';
}
printf("╰─────────────────────────────────────────────────────────────╯\n\n");
// Properly URL-encode spaces in the location
char encoded_location[256] = "";
char *src = location;
char *dst = encoded_location;
while (*src) {
if (*src == ' ') {
*dst++ = '%';
*dst++ = '2';
*dst++ = '0';
} else {
*dst++ = *src;
}
src++;
}
*dst = '\0';
// Format command with the location - using default wttr.in display format
snprintf(command, sizeof(command), "curl -s wttr.in/%s", encoded_location);
// Execute the command and display the full wttr.in UI
system(command);
return 1;
}

BIN
weather.o

Binary file not shown.