资讯专栏INFORMATION COLUMN

Yet Another shell can run anywhere Python exists.

Jinkey / 3311人阅读

PySh

Another shell can run anywhere Python exists.

Why another shell

Because it"s fun.

Supported shell feature

Common shell features can be found here. Pysh already have:

|, Pipe output

$var, Use value for variable

" ", double quote (allows variable and command expansion)

Usage
git clone https://github.com/jiacai2050/pysh.git
cd pysh
python -m pysh.shell

## Demo
> ls
.git
.gitignore
.pre-commit-config.yaml
assets
pysh
README.md

> echo $HOME
/Users/liujiacai

> echo ${JAVA_HOME}
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home

> pwd
/Users/liujiacai/codes/python/pysh

> cd ..
/Users/liujiacai/codes/python

> pwd
/Users/liujiacai/codes/python

> cat /etc/hosts | grep 127.0.0.1
127.0.0.1       localhost

> grep 127.0.0.1 /etc/hosts
127.0.0.1       localhost

Supported commands can be found here.

More commands are on the way. PR welcomed !

Have fun ?

How PySh work

A shell in unix box is a bridge bewteen user and the kernel through system call.

As we can see from above picture (taken from here), some commands (eg ls, cat) are passed to other programs, while built-in commands (eg cd, exit) are executed inside shell. This way can keep shell small in size and strong in function.

In order to let PySh run anywhere (hi, Windows, I mean you), PySh implmented all commands in its core, so there is no differences bewteen builtins and one that is not, also you can say all commands are builtins.

One thing I should mention here is:

Pipelines between different commands are supported by generator in Python.

So, every command should yield something, this is like s-expression in Lisp world, where every s-expression should return a value.

How to contribute

PySh use pre-commit to ensure code quality, so you should install it before contribute.

Fork and PR ?

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/38072.html

相关文章

  • 使用REACT VR构建web虚拟现实

    Building virtual reality experiences on the web with React VR Over the past year, virtual reality has made major strides toward becoming the next computing platform. With Oculus Rift, consumer-grade h...

    anquan 评论0 收藏0
  • 剖析 Laravel 计划任务--避免重复

    摘要:持有鸡的人是唯一被允许谈话的人。这样可以确保人们互不说话,也有自己的空间。所以当作业第一次启动时,创建一个互斥,然后每次作业运行时,它检查互斥是否存在,只有在没有工作的情况下运行。 译文GitHub https://github.com/yuansir/diving-laravel-zh 原文链接 https://divinglaravel.com/task-scheduling/pr...

    li21 评论0 收藏0
  • Embedding Python modules into C applications.

    In official Doc. of Python 3, there is a short introduction to embedding Python in another application like C/C++ (seeEmbedding Python in Another Application). The common procedure is as follows, w...

    youkede 评论0 收藏0
  • 线程的状态

    摘要:运行中,线程状态中并没有这一状态,但是实际执行中是有的可运行状态的线程获得了时间片,执行程序代码。其他阻塞运行的线程发出了请求时,会把该线程置为阻塞状态。当处理完毕时,线程重新转入可运行状态。 Thread.State 首先看JDK中的代码: java.lang.Thread.State /** * A thread state. A thread can be i...

    zhou_you 评论0 收藏0

发表评论

0条评论

Jinkey

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<