Giter Club home page Giter Club logo

psh's Introduction

psh: a fancy POSIX-like shell

Welcome to psh!
blob@PSH → psh $ ls
bin  CODE_OF_CONDUCT.md  LICENSE  Makefile  README.md  script.sh  src

This project is part of Tilde 3.0 HSP PESU-ECC's summer mentoring program: where 5 students developed this project under the guidance of 4 mentors.

Contributors:

Mentors:

Run locally

git clone https://github.com/homebrew-ec-foss/psh; cd psh
make run

Devlogs

psh's People

Contributors

pro696969 avatar adityatr64 avatar polarhive avatar g-anupam avatar tejas-techstack avatar 2sumithrasuresh avatar ninsid711 avatar alaynamonteiro avatar navneetnayak avatar

Stargazers

 avatar Achyuth Yogesh Sosale avatar  avatar  avatar  avatar  avatar Smaran Jawalkar avatar  avatar

Watchers

 avatar Adithya Mallya avatar  avatar

psh's Issues

fc issues (just to make note)

fc -r (Seg fault)
fc -n(Seg fault)
fc -e (does not show the last command yet but opens the editor)

i will add on to this if i see any other issues

pwd -L not working

image
okay so pwd -L is supposed to give the logical directory but it shows the physical one

feat/qol: basic themeing and extensions

Setup a .pshrc file to design basic themes for $PS1. Basic RGB colors for the prompt and bg/fg colors if possible, although it's upto the terminal like kitty or gnome-console to handle this.

Include helpful functions like: battery status, last git commit hash, or branch if there is a .git folder in the pwd. These can be simple .sh scripts or C program binaries, as a PoC.

ctrl D seg fault

image
happens only when you hit ctrl D without running a command before that
its working fine if you run any other command and then do ctrl D

feat/qol: tab key autocomplete

Support tab key autocomplete/matching.

Proof of concept:

Utilize or extend the inbuilt hashmap to scan through a list of available programs in $PATH. Usually anything under /usr/bin/*.

Then use a fuzzy matching algorithm to predict the most probable command to execute.

feat: parse ;

echo "hello"; echo "world";

Input multiple commands in a single line

This is a prereq for: #42

Bugs related to cd

Following are the flags that currently do not work in cd :

  • cd -e : Should check if a directory exists.
  • cd -L & cd - P For symlinks

refactor: split program into modular .c and .h files

Prototype:

  • Separated main logic into main.c and psh.h
  • Moved tokenizing and external command execution to execute.c
  • Isolated built-in commands in builtin.c and builtin.h
  • Extracted helper functions to helpers.c
  • Updated Makefile to support new file structure

Main File: main.c

Will contain the main function and the PSH_READ function.

// main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "psh.h"
#include "builtin.h"

Header File: psh.h

Contains the declarations for the functions and variables used across multiple files.

// psh.h
#ifndef PSH_H
#define PSH_H

#include <linux/limits.h>
#include <stdlib.h>
#include <unistd.h>

// Global Variables
extern char path_history[MAX_HISTORY][PATH_MAX];
extern int history_index;
extern char cwd[1024];
extern char *builtin_str[];
extern int (*builtin_func[])(char **);
extern int size_builtin_str;

// Function Declarations
int PSH_READ();
char **PSH_TOKENIZER(char *);
int PSH_EXEC_EXTERNAL(char **);
void remove_last_component(char *);
int resolve_and_manage_symlink(char *, char *);
char *commonSuffix(char *, char *);
char *helper_cd_func1(const char *, const char *);

#endif

Header File for Built-in Commands: builtin.h

This file will contain the declarations for the built-in commands.

// builtin.h
#ifndef BUILTIN_H
#define BUILTIN_H

int PSH_EXIT(char **);
int PSH_CD(char **);
int PSH_ECHO(char **);
int PSH_PWD(char **);
int PSH_HISTORY(char **);

#endif

builtin.c

char path_history[MAX_HISTORY][PATH_MAX];
int history_index = 0;
char cwd[1024];
char *builtin_str[] = {"exit", "cd", "echo", "pwd", "history"};
int (*builtin_func[])(char **) = {&PSH_EXIT, &PSH_CD, &PSH_ECHO, &PSH_PWD, &PSH_HISTORY};
int size_builtin_str = sizeof(builtin_str) / sizeof(builtin_str[0]);

int PSH_EXIT(char **token_arr)
{
...
}

Execute.c tokenizer and execution of external commands

#include <unistd.h>
#include "psh.h"

char **PSH_TOKENIZER(char *line)
{...}

helpers.c

// helpers.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "psh.h"

void remove_last_component(char *path)
{
...
}

int resolve_and_manage_symlink(char *localdir, char *resolved_path)
{
...
}

Sample makefile (update with our file structure)

# Makefile
CC = gcc
CFLAGS = -Wall -Wextra -g

OBJ = main.o execute.o builtin.o helpers.o

psh: $(OBJ)
    $(CC) $(CFLAGS) -o psh $(OBJ)

main.o: main.c psh.h builtin.h
    $(CC) $(CFLAGS) -c main.c

execute.o: execute.c psh.h
    $(CC) $(CFLAGS) -c execute.c

builtin.o: builtin.c psh.h builtin.h
    $(CC) $(CFLAGS) -c builtin.c

helpers.o: helpers.c psh.h
    $(CC) $(CFLAGS) -c helpers.c

clean:
    rm -f *.o psh

feat: arrow keys

someone decide to work on arrow keys, if you have time start doing it, if you cant finish it before week 1 its fine, but start working on it

meta: Few basic commands

From the given below list each of you have to implement one built in function and test one external function :
Built in :

  • cd
  • pwd
  • echo
  • export
  • history
    External Command to be tested :
  • ls
  • mv
  • rm
  • find
  • cp

While testing you have to check all possible uses cases of that function. You may not have to necessarily change the code for testing, but whenever you are pushing your change, Please give a description of what you found out while testing.

You are allowed to discuss among yourselves and decide who takes which function.

Constraints :

  • Each person must have one built in function and one external function
  • Each person must create a branch and push the changes

As soon as a Pull request is made and merged a message will be put in the group. At that time all other members will have to pull the branch to ensure that you are code is updated with all changes. Do feel free to ask us how to pull ur branch. Good luck Coding!

seg fault when \n is entered

if you enter a \n there is a segmentation fault generated, i guess this is happening because stripping the \n creates an empty pointer and something is happening i dont know but yea there is this error

command: alias/unalias

write a function to create a shell command for alias

alias : shows all the created aliases
alias list="ls -la" : creates an alias called list that runs the command ls -la
unalias list : removes an alias created
the above statement is just an example you should be able to take care of any commands and variable names
also one more thing
if the alias name given has a conflict with an existing command (for example if you have an alias alias cd="ls -la"
running cd should first run the alias command and not the original cd command.

feat/qol: record mode

Your shell should have a start-record keybind, say: CTRL+R and a prompt shows up.

Usecase: a new user has no clue what caused an error and they've to keep scrolling to take screenshots and you have to manually read through and type commands one by one from that screenshot to reproduce their errors. Instead: psh lets them share their logs from that specific session.

It starts to log anything on the STDOUT and appends it to a file. The user can publish this file to a pastebin. This in essence is like (a long-screenshot) so that you can share what went it wrong while debugging.

Try building it natively, otherwise if out of time, let call ascii cinema in a forked process when the CTRL+R keybind is pressed. ref: ascii cinema

feat/qol: vim copy/paste shortcuts

CTRL+I or any keybind (TBD), should show a prompt saying: vim mode active press yy to yank or copy the last command from the session file or buffer to clipboard. Similarly use p to paste from clipboard into the buffer.

You might need to spawn wl-clipboard daemon in watch mode.

feat/qol: reverse i search

Hitting CTRL+R should let the user browse through the session history file and select a command to execute. This depends on the matching engine found in: #73

Get a prompt running

Write C code to generate a prompt that awaits input from the user

psh $ <waiting for input>

chore/ci: automate testing

Automate the process of checking if the output of our shell matches zsh's output using unit tests.

TODO:

  • Writing and structuring unit tests
  • Prioritizing commands for testing
  • CI/CD pipeline integration

feat: while loops

prereq: #40, #54 #41

Implement for and while loops so you can run:

#!/bin/psh
# Using brace expansion to iterate over numbers 1 through 3

for num in {1..3}; do
 echo "Number: $num"
done

Will output:

Number: 1
Number: 2
Number: 3

bug: symlinks

Cd now functions properly except when symlinks are used the cd ends up inside the linked dir and can't go back into parent/dir with the symlink using cd ..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.