Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new version of help50 #210

Open
wants to merge 83 commits into
base: main
Choose a base branch
from
Open

Adds new version of help50 #210

wants to merge 83 commits into from

Conversation

dmalan
Copy link
Member

@dmalan dmalan commented May 9, 2024

To be squashed when merging.

This new version is implemented in Bash (instead of Python) as follows, wherein usage is inspired by systemctl, even though it doesn't run as a daemon but, rather, per login shell. It runs locally and automatically now, without any server.

  • help50 start sets $HELP50 to $$, the PID of the shell in which the command was run and launches script, which logs standard I/O to /tmp/help50.$$.typescript.
  • help50 stop sends SIGHUP to the PID of script.
  • help50 status checks for $HELP50, which is set only when help50 is started for a shell.
  • help50 disable writes /tmp/help50.lock.
  • help50 enable deletes /tmp/help50.lock.
  • help50 is-enabled checks for /tmp/help50.lock.

  • /etc/profile.d/help50.sh is a config that that's only sourced when $HELP50 is set.
    • It sets $PROMPT_COMMAND to _help50, which is a Bash function implemented therein that, if the most recent command exited with non-0 status (per $?), checks for /tmp/help50.$HELP50.typescript, passes it as standard input to each executable in /opt/cs50/lib/help50/ (implemented in any language).
    • If any of those echo output, it passes it to a _helpful function that, by default, displays it in yellow to help the user.
    • It none of those echo output, it passes the failed command's typescript to _helpless instead, which doesn't do anything in cs50/cli but can be overridden in cs50/codespace to relay it to ddb50.
    • Else if the most recent command exited successfully, _helped is called, which doesn't do anything in cs50/cli but can be overridden in cs50/codespace to indicate to the user that help is (no longer) available.
  • /etc/profile.d/cli.sh starts help50 automatically.
  • /opt/cs50/lib/cli contains several helper functions (written in Bash) that our own wrappers and help50 use.

$ git fetch
$ git checkout help50
$ make build
$ make run

/mnt/ $ help50 start

/mnt/ $ ps f
  PID TTY      STAT   TIME COMMAND
    1 pts/0    Ss     0:00 bash --login
   24 pts/0    S      0:00 /bin/bash /opt/cs50/bin/help50 start
   26 pts/0    S+     0:00  \_ script --append --command bash --login ; exit 1 --flush --quiet --return /tmp/help50.1.typescript
   27 pts/1    Ss     0:00      \_ sh -c bash --login ; exit 1
   28 pts/1    S      0:00          \_ bash --login
  143 pts/1    R+     0:00              \_ ps f

/mnt/ $ help50 stop

Session terminated, killing shell... ...killed.

/mnt/ $ ps f
  PID TTY      STAT   TIME COMMAND
    1 pts/0    Ss     0:00 bash --login
  178 pts/0    R+     0:00 ps f

@dmalan
Copy link
Member Author

dmalan commented May 10, 2024

Thank you! Addressed all of these and working on a few more tweaks before merging!

@dmalan dmalan marked this pull request as draft May 10, 2024 18:37
@dmalan dmalan marked this pull request as ready for review October 5, 2024 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants