Giter VIP home page Giter VIP logo

repl's Introduction

REPL

A simple CLT to prefix any command with a given one

Installing

Make sure Xcode 10.2 or higher is installed first.

Homebrew

$ brew install Samasaur1/core/repl

Mint

Install

$ mint install Samasaur1/REPL
Update
$ mint install Samasaur1/REPL

Swift Package Manager

Use CLI

$ git clone https://github.com/Samasaur1/REPL.git
$ cd REPL
$ swift run REPL

repl's People

Contributors

samasaur1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

repl's Issues

determine shell

import Darwin

var action: posix_spawn_file_actions_t? = nil
posix_spawn_file_actions_init(&action);
defer { posix_spawn_file_actions_destroy(&action) }
let m: mode_t = S_IRWXU | S_IRWXG | S_IRWXO
posix_spawn_file_actions_addopen(&action, 1, "/tmp/shell", (O_WRONLY | O_CREAT | O_TRUNC), m)

let args = ["/usr/bin/env", "ps", "-p", "\(getppid())", "-o", "comm="]
let c_args = args.map { $0.withCString(strdup)! }
defer { for arg in c_args { free(arg) } }

var pid = pid_t()
let rv = posix_spawn(&pid, c_args[0], &action, nil, c_args + [nil], environ)
guard rv == 0 else {
  // Should get errno
  exit(1)
}
//print(pid)

var exitCode: Int32 = 0
waitpid(pid, &exitCode, 0)

adapted from the method of determining PS1. read /tmp/shell and see something like -bash, zsh, nu, csh, etc.

REPL commands should be entered into bash history

After running this:

[sam](~)$ repl git
Initializing REPL with command: git
Use ^D to exit

[sam](~)$ git status
fatal: not a git repository (or any of the parent directories): .git
[sam](~)$ git config --global user.name "Samasaur1"
[sam](~)$ git ^D
Exiting REPL

bash's history does not contain the git lines. This means that !! does not work, nor does history or arrow keys after exiting REPL.

Any commands run in the REPL should be added to the history. I'm not sure how hard this is to do, but if possible it should be done.

Mock user's prompt

REPL should, instead of using my current prompt, read from user config files to duplicate their prompt

Ctrl-C should add a new line

In macOS's Terminal.app running bash, Ctrl-C (^C) leaves what's on the line and produces a new line. REPL should emulate this.

Color replication

When REPL is used on tools that produced colored output (the example I'm thinking of is git), the colors are not seen. This should be remedied.

Allow for configuration of the REPL prompt

Although #11 mocks the user's PS1 for the REPL prompt, there are a few problems with this. First, if you use a shell other than bash, you're up a creek without a paddle. Second, you may perhaps want a different REPL prompt than your bash prompt.

This config file would probably go in ~/.config/repl/ and should also include the aliases in #12

Arrow Key Support

REPL should support up and down arrow keys to go through terminal history. Right now, all it produces is ^[[A for up arrow and ^[[B for down arrow.

Migrate from Process (using `bash -c`) to `posix_spawn`

I know the title makes it seem like we're going backwards in time, not forwards, but in my experience something like the following works better:

var pid: pid_t = 0
let args = ["/usr/bin/env"] + effectiveEditor + [dir + "/" + helpme + ".txt"]
let c_args = args.map { $0.withCString(strdup)! }
posix_spawn(&pid, c_args[0], nil, nil, c_args + [nil], environ)
waitpid(pid, nil, 0)

(from helpme-swiftly)

This should also work better with lots of arguments, especially quoted ones, since we're invoking the actual command rather than /bin/bash -c "command and arguments"

use GNU readline

I don't know if I actually want to use the GNU readline, but I want support for ^A, ^E, ^W, etc. โ€” so that it feels like a standard shell edit line.

see #18

!! Support

As mentioned in #7 and #6, REPL should support using !! to refer to the previous command. This specifically relates to #6, as the work being done for that (having a history of commands) means that substituting !! for the previous command should be easy.

Ability to create REPL aliases

While we're waiting for #5, it would be nice to have aliases configurable in REPL. For example, to get color in git right now, instead of saying repl git, I say repl git -c color.ui=always -c color.status=always. For ls, it's ls --color=auto.

It would be nice to have repl check some configuration file and, if the input command matches, substitute it for the longer one. This would be easy, be a simpler way to enable color than faking being a tty/opening a pty, and would be useful beyond enabling color.

The configuration file should be combined with #131

Footnotes

  1. a ticket i have not yet created, so I'm curious how this will work out โ†ฉ

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.