Giter Club home page Giter Club logo

closh's People

Contributors

agilecreativity avatar borkdude avatar djblue avatar dundalek avatar gdeer81 avatar gitter-badger avatar hlolli avatar it-praktyk avatar jeroenvandijk avatar johanatan avatar johannesloetzsch avatar kirillsalykin avatar marcomorain avatar mnewt avatar ssyh avatar thearthur avatar torild avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

closh's Issues

File redirection issues

File redirection seems to be broken when using functional pipes, e.g.:

echo hello | (clojure.string/upper-case) > tmp.txt

Last result value in repl is shifted

Clojure REPL keeps the result of last command in variable *1 and previous results in *2 and *3. However, this gets broken because we evaluate function that renders prompt after each command. The function used for evaluation is execute-text, the results are set in process-1-2-3.

Possible solutions:

  1. Hack lumo so that we can evaluate particular code without setting 1-2-3.
  2. Back up the values, render prompt, then restore them.

Slow tests

The whole test suite takes minutes to run, which is too slow. The reason for this is that it spawns child process to evaluate each closh case.

Possible solutions:

  1. Make the test runner run on Lumo, that way we could evaluate the test cases within the test runner process.
  2. Start one evaluator process, then use some sort of IPC to send code to evaluate and results back to test runner process.

Loading files and libraries

  • Load clojurescript files with (load-file "some/file.cljs") (seems to be broken at the moment).
  • Require globally installed nodejs libraries like (def decode-prompt (js/require "decode-prompt").
  • Require clojurescript libraries with (require 'libname.core). The trouble is with specifying classpath.
    • Maybe if libs are downloaded via Maven from Clojars they will get picked up automatically from ~/.m2/repository
    • Maybe we need to expose Lumo's option to specify classpath.

POSIX Shell compability

Have you considered using POSIX Shell compatible syntax?

That would allow sourcing shell scrips (e.g. virtualenv activate).

As far I can see, POSIX Shell have following incompatibles with closh:

  • ( ... ) is a subshell (example: cd /bin; (cd /;pwd); pwd)
  • |> is parsed as | > (example: ls / |> out.txt tac is same as ls / | tac > out.txt)
  • # is comment (so ls / | #(...) <newline> tac is same as ls / | tac in POSIX shell, but is invalid in closh).

One way of having compatible syntax is make sure that that every part of syntax of closh is either have same meaning in POSIX Shell or invalid in POSIX Shell. For example, prepend every clojure command with %, and use |} instead of |>:

ls | %#(clojure.string/replace % #"\.txt" ".md")
ls |} %(reverse) | %(take 5)

Another one is using shopt to enable/disable POSIX compatible mode:

shopt no_closh # only POSIX syntax allowed from now on
source ./bin/activate
ls_root() ( cd / && echo * | tr ' ' '\n' )
shopt closh # closh syntax is enabled back
ls_root |> (reverse)

[QUESTION] How to use conda?

Conda uses a .sh script to start itself up, and running that script via source-shell does no good.

 $ conda activate

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". /Users/evar/anaconda/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

    $ sudo ln -s /Users/evar/anaconda/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bash_profile

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file.  You should manually remove the line that looks like

    export PATH="/Users/evar/anaconda/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

Feature: User-defined Aliases, Abbreviations, Functions and Commands

For user defined helpers I am thinking of supporting following:

Aliases

Aliases for defining / overriding functionality. When alias is used it does not get expanded and is saved into history as is.

Example:

(defalias ls "ls --color=auto")

Abbreviations

Abbreviations are similar to aliases but expand to underlying definition. Therefore autocomplete can work seamlessly and also full command is saved to history. Inspired by abbr in fish. See also discussion.

(defabbrev ga "git add")
(defabbr gaa "git add --all")

Functions

Classic Clojure functions, already works.

(defn hello [name]
  (str "Hello " name))

Run in command line like: (hello "World").

Commands

Similar to functions, but can be executed like commands without parens. Related to builtin commands. Defining similar to defn:

(defcmd hello [name]
  (str "Hello " name))

Run in command line like: hello World. There should probably also be a way to promote existing function to a command.

`closh` starts Lumo after installation to $HOME

I installed Closh like this:

$ cd $HOME
$ npm install lumo-cljs closh
$ export "PATH=$HOME/node_modules/.bin:$PATH"

Afterwards, executing closh drops me into a Lumo REPL instead of Closh:

$ closh
Lumo 1.0.0-alpha3
ClojureScript 1.9.293
 Exit: Control+D or :cljs/quit or exit
cljs.user=>

The generated file $HOME/node_modules/.bin/closh does not appear to be terribly wrong:

#!/usr/bin/env node
'use strict';
var spawn = require('child_process').spawn;
var path = require('path');
var os = require('os');
var fs = require('fs');

var isWindows = /^win/.test(process.platform);
var bin = isWindows ? 'lumo.cmd' : 'lumo';
var args = [
  '--classpath', path.join(__dirname, '..', 'src'),
  '--cache', path.join(os.homedir(), '.lumo_cache'),
  '-m', 'closh.main',
];

// NODE_PATH seems to be missing when running as global binary
var paths = [
  path.join(__dirname, '..', 'node_modules'),
  path.join(__dirname, '..', '..')
];
if (process.env.NODE_PATH) {
  paths.push(process.env.NODE_PATH);
}
process.env.NODE_PATH = paths.join(isWindows ? ';' : ':');

spawn(bin, args, { stdio: 'inherit' }).on('exit', process.exit);

read-line

Would be a nice feature to add (read-line) support (synchronously). Now I need to include a library like https://github.com/anseki/readline-sync which seems a bit involved for a simple script.
Planck also has read-line support which could serve as inspiration.

Prompt gets printed when terminal window is resized

When running a long running process and resizing the terminal window, closh prompt gets print mixing with the process output. This is likely bug in the readline implementation. It should be solved with the new readline implementation.

Get existing aliases, abbreviations, and commands

You can find these out with, for example, (prn closh.core/*closh-aliases*) and (closh.core/expand-alias) but there should be a more user-friendly way to access them.

@dundalek What do you think? Add an alias or getalias command (and corresponding commands for abbreviations and commands)?

cd does not return success value

Therefore in cd && echo x the echo command does not get executed. We could return true on the successful change dir, but then simple cd would print to the output.

History file is not created

For me the ~/.closh/closh.sqlite file for the history is not created. There is neither a folder nor the file during or after execution of closh.
No error is printed either. It just doesn't happen.

Tested on macOS and Arch Linux. Installed via nmp install -g lumo-cljs closh

Any suggestions on how to debug this?

REPL server

Add some REPL server support so we can have closh backend and connect to it with different frontend readline implementations like omnia or rebel-readline.

It would be also cool to explore possibility to run REPL via clj CLI tool.

History DB initialization race condition

When typing and pressing enter while closh is starting there is a Cannot save history error because db is not yet initialized.

We should probably use a promise and queue the operations until the db is initialized.

Does not work

I am zero in Node JS. Could someone advice me what need to do to fix it?

$ npm install -g lumo-cljs closh
/usr/local/bin/closh -> /usr/local/lib/node_modules/closh/bin/closh.js
/usr/local/bin/lumo -> /usr/local/lib/node_modules/lumo-cljs/bin/lumo.js

> [email protected] install /usr/local/lib/node_modules/lumo-cljs
> node scripts/npm_install.js || nodejs scripts/npm_install.js


 Downloading [========================================] 2961197/bps 100% 0.0s

+ [email protected]
+ [email protected]
added 3 packages, removed 1 package, updated 2 packages and moved 64 packages in 22.908s
$ closh
Could not require closh.core in file closh/main.cljs
	 (new)
	 Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2024:72)
	 Function.cljs.analyzer.error.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2639:92)
	 (NO_SOURCE_FILE <embedded>:5950:320)
	 (Object.lumo.repl.run_sync_BANG_)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5927:185)
	 Object.cljs.js.process_libs_deps (NO_SOURCE_FILE <embedded>:5930:60)
	 (NO_SOURCE_FILE <embedded>:5948:474)
	 (Object.lumo.repl.run_sync_BANG_)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5927:185)

Could not locate the bindings file. Tried:
 → /usr/local/lib/node_modules/closh/node_modules/deasync/build/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/build/Debug/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/build/Release/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/out/Debug/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/Debug/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/out/Release/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/Release/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/build/default/deasync.node
 → /usr/local/lib/node_modules/closh/node_modules/deasync/compiled/9.2.0/darwin/x64/deasync.node
	 bindings (/usr/local/lib/node_modules/closh/node_modules/bindings/bindings.cljs:88:9)
	 (/usr/local/lib/node_modules/closh/node_modules/deasync/index.cljs:34:32)
	 Object.<anonymous> (/usr/local/lib/node_modules/closh/node_modules/deasync/index.cljs:76:2)
	 Module._compile (module.cljs:641:30)
	 Object.Module._extensions..js (module.cljs:652:10)
	 Module.load (module.cljs:560:32)
	 tryModuleLoad (module.cljs:503:12)
	 Function.Module._load (module.cljs:495:3)
	 Module.require (module.cljs:585:17)
	 require (internal/module.cljs:11:18)

$ node -v
v9.5.0
$ npm -v
5.6.0

Reconsider closh and lumo distribution

As I am working on the signal handling I've been running into an issue that lumo installed via npm does not start directly but inside a js script running in node which spawns the lumo child process. Therefore pressing ctrl+c interrupts the parent process and pipe to the lumo process gets closed and closh errors out and exits.

To solve the issue we could do native exec to replace the process (using something like kexec, but it does not work on windows). Or run run the script directly with the lumo binary without the node wrapper.

There are couple of ways we could go:

  1. Keep using npm, but make the shell script that would use exec to run closh on lumo.
  2. Stop using npm to install, distribute lumo with closh and run directly.
  3. It might worth to try compile closh into a single binary using the lumo's build process and distribute a single executable.

Shell mode reader improvements

This is an idea for some further time in future, but it may be cool to support reader macros somehow.

For example current single quoting functionality has a trade-off to be consistent with Clojure but it will fail to interpret common snippets from the internet. An example (brought by @eriktjacobsen in Gitter):

aws --profile profile-name ec2 describe-instances --filters "Name=tag:OwnerContact,[email protected]" --query 'Reservations[*].Instances[*].[InstanceId,InstanceType,NetworkInterfaces[*].[PrivateIpAddress],Tags[?Key==`Name`].Value]' --output text

If we had reader macros then user could fine tune these trade-offs to their preference.

Add E2E tests

Currently we test by either calling eval directly or spawning a special helper process.

It would be good to add tests that spawn the closh itself and send commands via stdin. This would also allow us to test UI interaction (e.g. history search).

There might be some trickiness to figure out to wait for the process to start and parsing out the prompt.

Improved reader

We use built-in clojure reader to parse the command mode, but it does not accept some shell forms.

Possible approaches:

  1. Try to hack the current reader to accept those forms (this would be my favorite if possible).
  2. Build the parse for command mode, then hand the forms in clojure code the built-in reader (probably a way to go).

Interesting inspiration might be Racket, since it is so flexible defining new languages.

Current limitations I am aware of:

  • IP addresses (invalid number error)
    replace ping 8.8.8.8
    with ping "8.8.8.8"
  • unquoted brace expansion (gets parsed as symbol and a map)
    replace ls *.{cljc,clj}
    with ls (expand "*.{cljc,clj}")
  • tilde with slash
    e.g. vim ~/.closhrc
  • at sign, tries to deref var e.g. git clone [email protected]:dundalek/closh.git
  • multiple variable expansion, e.g. echo $USER/$DISPLAY

for loops

Hi,

Simple example that does not work for me:

(for [i (range 100)] 
  (sh echo i))```

2 problems: 
1. multi-line input does not seem to be supported, the loop works in using 1 line. 
2. the value of i is not expanded. `(for [i (range 100)] i)` works as expected...

Still experiencing issues on macOS

I've tried to re-install with the new master after the fix in issue 52, but I'm still getting errors when trying to run closh:

which closh
/Users/domparry/.nvm/versions/node/v8.9.3/bin/closh
➜  fulliautomatix git:(master) ✗ closh
Could not require closh.util in file closh/builtin.cljs
	 (new)
	 Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2024:72)
	 Function.cljs.analyzer.error.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2639:92)
	 (NO_SOURCE_FILE <embedded>:5950:320)
	 (Object.lumo.repl.run_sync_BANG_)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5927:185)
	 Object.cljs.js.process_libs_deps (NO_SOURCE_FILE <embedded>:5930:60)
	 (NO_SOURCE_FILE <embedded>:5948:474)
	 (Object.lumo.repl.run_sync_BANG_)
	 Object.cljs.js.process_deps (NO_SOURCE_FILE <embedded>:5927:185)

Cannot find module 'tmp'
	 Function.Module._resolveFilename (module.cljs:542:15)
	 Function.Module._load (module.cljs:472:25)
	 Module.require (module.cljs:585:17)
	 require (internal/module.cljs:11:18)
	 (evalmachine.<anonymous>:6:18)
	 ContextifyScript.Script.runInThisContext (vm.cljs:50:33)
	 Object.runInThisContext (vm.cljs:152:38)
	 (Object._t)
	 lumo.repl.caching_node_eval (NO_SOURCE_FILE <embedded>:6481:68)
	 (NO_SOURCE_FILE <embedded>:5949:410)

➜  fulliautomatix git:(master) ✗

[BUG] powerline-shell prompt eats stdout

As you see, the prompt is eating a line from stdout:
image

upper -u | cat

My .powerline-shell.json:

{
  "segments": [
    "time",
    "username",
    "ssh",
    "cwd",
    "git",
    "hg",
    "jobs",
    "exit_code",
    "read_only",
    "newline",
    "root"
  ],
  "theme": "~/anaconda/lib/python3.6/site-packages/powerline_shell/themes/solarized_light.py"
}

can't install on osx

When attempting to install closh i get the following error:

[2018-01-31T22_49_10_691Z-debug.log](https://github.com/dundalek/closh/files/1683596/2018-01-31T22_49_10_691Z-debug.log)
$ npm install -g lumo-cljs closh
/usr/local/bin/closh -> /usr/local/lib/node_modules/closh/bin/closh.js
/usr/local/bin/lumo -> /usr/local/lib/node_modules/lumo-cljs/bin/lumo.js

> [email protected] install /usr/local/lib/node_modules/lumo-cljs
> node scripts/npm_install.js || nodejs scripts/npm_install.js


Download failed.
sh: nodejs: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] install: `node scripts/npm_install.js || nodejs scripts/npm_install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jsiddall/.npm/_logs/2018-01-31T22_49_10_691Z-debug.log

OS: MacOS Sierra 10.12.6
Node: v9.4.0
NPM: 5.6.0

Node & NPM installed via pkg file from https://nodejs.org/en/
I've tried reinstalling Node/NPM multiple times and get the same problem.

Windows support

There is a trouble running a startup script on Windows. In order to make closh on Windows I imagine two ways could work:

  1. Create a .bat file to run closh and use a package manager like Chocolatey or Scoop.
  2. Keep using npm for and try out cygwin to make the bootstrap shell script work.

If anyone uses Windows please give it a shot. Any help is appreciated.

Cannot use ~

This works fine

$ nano .closhrc

This does not

$ nano ~/.closhrc
                      ⬆
WARNING: No such namespace: , could not locate .cljs, .cljc, or JavaScript source providing "" at line 1

                      ⬆
WARNING: Use of undeclared Var / at line 1

Unexpected token .
         createScript (vm.cljs:74:10)
         Object.runInThisContext (vm.cljs:116:10)
         (Object.lt)
         (Object.lumo.repl.caching_node_eval)
         (NO_SOURCE_FILE <embedded>:6020:273)
         z (NO_SOURCE_FILE <embedded>:6021:263)
         Object.cljs.js.eval_str_STAR_ (NO_SOURCE_FILE <embedded>:6022:328)
         Function.cljs.js.eval_str.cljs$core$IFn$_invoke$arity$5 (NO_SOURCE_FILE <embedded>:6025:508)
         lumo.repl.execute_text (NO_SOURCE_FILE <embedded>:6511:475)
         closh$eval$execute_text (evalmachine.<anonymous>:7:24)

"$ "

Same goes for cd

$ cd ~
Unmatched delimiter ).
         (new)
         Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:1928:72)
         Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2 (NO_SOURCE_FILE <embedded>:1927:449)
         Function.cljs.tools.reader.impl.errors.throw_ex.cljs$core$IFn$_invoke$arity$variadic (evalmachine.<anonymous>:53:25)
         Function.cljs.tools.reader.impl.errors.reader_error.cljs$core$IFn$_invoke$arity$variadic (evalmachine.<anonymous>:91:47)
         (Object.cljs$tools$reader$impl$errors$throw_unmatch_delimiter)
         cljs.tools.reader.read_unmatched_delimiter (NO_SOURCE_FILE <embedded>:2157:270)
         Object.cljs.tools.reader.read_STAR__internal (NO_SOURCE_FILE <embedded>:2269:407)
         Function.cljs.tools.reader.read_STAR_.cljs$core$IFn$_invoke$arity$6 (NO_SOURCE_FILE <embedded>:2272:111)
         Function.cljs.tools.reader.read_STAR_.cljs$core$IFn$_invoke$arity$5 (NO_SOURCE_FILE <embedded>:2271:116)

"$ "

Tab completion

Having intelligent tab completion would be great 🥇

Completion V2

Current tab-completion is a proof of concept. It uses node readline implementation of completion which has some limitations. I would like to address these by doing custom completion rendering. This will come later when we start on custom rendering and interactivity with escape sequences.

Limitations which will be addressed:

  • show only the last part of the completion (node readline which shows the whole thing)
  • pagination - I imagine something like fish, show couple of lines, if user starts navigating then expand to height of the terminal (currently completes common prefix then shows all items on second tab press)

Crash when accessing a vector through a string

$ ls |> (group-by (comp first (fn [x] (.toLowerCase x)))) | (take 1) | (map #(update % "xx" count))
readline.js:1017
            throw err;
            ^

Error: Vector's key for assoc must be a number.
    at cljs.core.PersistentVector.cljs$core$IAssociative$_assoc$arity$3 (<embedded>:1098:178)
    at Object.cljs.core._assoc (<embedded>:275:106)
    at Function.cljs.core.assoc.cljs$core$IFn$_invoke$arity$3 (<embedded>:490:88)
    at Function.cljs.core.update.cljs$core$IFn$_invoke$arity$3 (<embedded>:1061:87)
    at cljs.core.update (<embedded>:1059:86)
    at evalmachine.<anonymous>:4:25
    at <embedded>:983:205
    at cljs.core.LazySeq.fn (<embedded>:983:210)
    at cljs.core.LazySeq.sval (<embedded>:698:151)
    at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (<embedded>:704:255)
✘-1 ~

Cannot start with npm

Hi. I'm new to open source contributing and git, so sorry in advance for any silly misunderstandings.
I am not able to start Closh with npm. I have cloned both from my own fork and from the original repo with the same results. When using npm install, I get the following #message:

`> [email protected] install /home/logan/Documents/closh/node_modules/deasync

node ./build.js

linux-x64-node-6 exists; testing
Binary is fine; exiting
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})`

and when using npm start, I get this message:

`> [email protected] start /home/logan/Documents/closh

node ./bin/closh.js

events.js:160
throw er; // Unhandled 'error' event
^

Error: spawn lumo ENOENT
at exports._errnoException (util.js:949:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
at onErrorNT (internal/child_process.js:348:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Function.Module.runMain (module.js:577:11)
at startup (node.js:160:18)
at node.js:445:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node ./bin/closh.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/logan/.npm/_logs/2017-11-09T02_35_58_352Z-debug.log`

version of npm: 5.5.1
version of node: v6.1.0

Any idea where I'm going wrong here? Thank you!

P.S. I can't seem to figure out the formatting. If somebody wouldn't mind helping me out there as well, that would be very much appreciated.

Parsing manual pages for auto-completion

This is not an immediate concern but I am creating an issue for discussion and to collect currently existing approaches and maybe for someone to take a stab at it.

Parsing manual pages is a messy business since there is no single standard and there are many slight variations.

Existing approaches:

  • Only project I am currently aware to attempt this is fish with fish_update_completions (source here).
  • Other project is explainshell but it does not handle command grammars so it is not a suitable approach (it could generate invalid suggestions).

What I imagine:

  • If completion definitions for a command are not available then try to parse man command or command --help or command -h
  • There are many variations so using a high-level parsing library like Instaparse is preferred. We can define different variant of parsing rules and reuse the common rules.
  • Docopt seems to be most formal description of command line arguments, so it makes sense to start with parsing its format, then extend to other manual pages in the wild.

`closh.sh` doesn't work on macOS

closh.sh uses two features that just about every Unix-like has, but not macOS:

  • realpath
  • readlink -f
> bin/closh.sh
readlink: illegal option -- f
usage: readlink [-n] [file ...]
usage: dirname path
bin/closh.sh: line 10: realpath: command not found
usage: dirname path
usage: dirname path
bin/closh.sh: line 15: /lumo: No such file or directory
bin/closh.sh: line 15: exec: /lumo: cannot execute: No such file or directory

The solution needs to do the same thing with only POSIX tools. A refactor shouldn't be too terrible although it might be harder to cover edge cases. While we're at it, a test or two would probably be good.

I'll send a pull request when I get the chance.

Option to pass script to closh

Is it possible to pass a script to closh, so you can execute a script from, say, bash?

bash$ closh myscript.closh

or

#!/usr/local/bin/closh
ls |> #(println (coun t%))

Paredit + You Are Awesome

Hi! This is awesome - thank you!

How to integrate paredit support and rainbow parens?

Clj/Cljs has been my primary scripting language for a while now, but it's a pain to deal with I/O and process control, so this hits the sweet spot. I think it would aid adoption to show users how to make closh their default shell :).

Creating a in-browser playground for Closh

Hello,

While I'm not nearly as experienced as probably most of you all who look into Closh are, I thought it might be interesting if we could create sort of a in-browser Closh playground for people to check out easily. Obviously it'd be written in Clojure[Script] 😉, but I think it'd be a fun project.

Unhandled error on Windows 7

Seems it "closhed" in unahdled error on Windows 7. May be due to demokit dependency

C:\Users\4mithc\AppData\Roaming\npm-cache\_logs>closh
events.js:163
  throw er; // Unhandled 'error' event
      ^
Error: spawn lumo ENOENT
    at exports._errnoException (util.js:1050:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

I think of demokit because it's install also ends with
`C:\Users\dfomin\AppData\Roaming\npm-cache_logs>npm install -g demokit
C:\Users\dfomin\AppData\Roaming\npm\demokit -> C:\Users\dfomin\AppData\Roaming\n
pm\node_modules\demokit\bin\demokit-cli.js

> [email protected] postinstall C:\Users\dfomin\AppData\Roaming\npm\node_modules\dem
okit
> node install.js

events.js:163
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm ENOENT
    at exports._errnoException (util.js:1050:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "demokit"
npm ERR! node v7.10.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1

npm ERR! [email protected] postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'node install.js'.`

And seems demokit is not supporting Windows

Move lumo into git submodule or subtree?

Should the lumo repo be imported as a subproject of closh?

  • It would make things easier for someone to build it if the link to lumo was already built in
  • It would lock down the version of lumo

If that seems like a good idea, should it be a submodule or subtree? I don't feel strongly either way. I guess I lean toward subtree.

I'm happy to send a PR

handle Ctrl-C

Closh doesn't process Ctrl-C while a command is running (maybe it doesn't pass it to the child process?). And when Ctrl-C is pressed at the prompt it exits (is that read-line trapping it?).

$ sleep 10
<press Ctrl-C>
<10 seconds later>
$
<closh exits>

Expected outcome is:

  1. Ctrl-C interrupts a child process
  2. At the prompt, Ctrl-C clears whatever, if anything, is written on the command line but otherwise does nothing. This is just my preference as it's the way fish does it and it's nice. The alternative of moving to a new prompt line (like bash) would also work.

Syntax highlighting?

A la fish, where it’s very useful for, e.g., verifying that a pasted-in string does not need escaping. Feel free to close if it’s not in the pipeline.

Terminal colours

Is there a way to get terminal colours ? Would that involve some sort of tty emulation ?

[BUG] Multiline commands are not supported

Just paste this snippet and you'll see:

(require-macros '[closh.core :refer [sh-str]])

(defn closh-prompt []
  (sh-str fish -c fish_prompt))

When I make it into one-line commands, the error is gone:

(require-macros '[closh.core :refer [sh-str]])

(defn closh-prompt []  (sh-str fish -c fish_prompt))

Environment variable integration

As for now one can use the JS interop to access and set environment variables:

echo (str js/process.env.VAR_NAME)
;; or
echo (expand "$VAR_NAME")

;; change with
(aset js/process.env "VAR_NAME" value)

Maybe we want to introduce helper functions like (setenv) or (setenv!) and (getenv) ?

Another thing is setting an env variable only for the child process, alternative to bash:
NODE_ENV=production npm start

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.