Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
StaSh - Shell Like an Expert in Pythonista
-
This is a very nice piece of work and quite useful. I use a BT keyboard on my iPad and I am wondering if there is any way that the special keys (e.g., Tab, Up, Ctrl-C) could be made to work from the keyboard?
-
I just submited a pull request.
I've added:
- man.py - lists programs in /bin and displays the docstring.
- edit.py - opens a file in the pythonista editor
- python.py - allows execution of .py files and modules. Basicly allows the -m flag with python. You can run SimpleHTTPServer, pylint, unittests etc.
- added '&' to _word_chars in stash.py - I needed this to allow running a python script in it's own thread emulating bash &.
-
@briarfox - what are the references to Shash and "drag and drop" talking about in your prior posts? Sounds like some other shell where you drag and drop scripts into a window or something. Did you mean StaSh and dnd means something other then what I think it does?
-
@wradcliffe Sorry I was being a bit dyslexic. By Dnd I was referring to adding scripts to StaSh/bin. As in it's easy to extend. Probably not the correct use of the term.
-
Thanks a lot for your pull request. I made some changes to
python.py
after the merge. In short, the script now takes a flag -b to indicate running as background thread instead of &. I usedargparse
module for argument processing. It even provides free help message if you typepython -h
.I personally think the & character shall be handled by the shell instead of the script gets called. Because otherwise every script has to check for & to decide if it runs in background. This task should be handled by shell/OS instead of individual script.
My current preference is to not allow background jobs (commands end with a &). This is mainly because it does not seem possible to end a thread gracefully from another (main) thread.
Thread._Thread__stop()
can be used and often works, but it does not perform any housekeeping tasks (e.g.try: ... finally:
block is not honoured). It just ends the thread abruptly and leaves a somewhat messy state, for example, the socket port will not be released if a http server thread is ended this way. Of course, an external can still spawn threads on its own and StaSh has no control of it since it is not really an OS.The shell in fact should have reported parsing error when sees a &. It was actually a bug that causes the shell ignore the character instead of erring out (it is now fixed). This character is Not part of
_word_char
which is consistent as a real shell. It is a punctuator, similar to;
, to separate commands. I am still debating whether background job shall be directly allowed by StaSh. But as for now, I prefer to leave it out.I hope these changes are OK with you. Thanks!
-
Sorry but I never had a chance to use an external keyboard. So I won't be of much help on this. Hopefully someone else would come up with a solution. Otherwise it'll have to wait till I can get a keyboard ...
-
@ihf re. keyboard, that is possible in a very limited way. See KeyboardControl.py, it uses a delegate and a specifically filled text field to deduce the user's keystrokes. It has issues with some of the more unusual combinations and I doubt it would be possible to integrate it in StaSh. The only thing I could think of would be to detect when the cursor jumps to the beginning of the text field (that is what the up arrow does when there's no line above the current one) and then show the previous history item in the text field. Tab might also work, because there is no other way (except copy and paste) to insert a tab character or multiple spaces at once.
-
Just submitted a pull request with:
- ssh-keygen - Generates rsa/dsa keys for scp and ssh
- scp - Secure copy. Gets and Put files/dirs onto or from a remote.
-
I'm working on an ssh script and would like some feedback. It currently only works for linux. You should use ssh-keygen to create a key pair. Add the .pub to your known_hosts on your server. You can also use the user password if you do not want to use a rsa/dsa key.
I've used this modules with scp to make all my commits and pushes to the stash repo. It's nice to have full git access from Pythonista.
<pre>
ssh client for stash. ssh looks for a valid key generated buy ssh-keygen in .ssh.
You can open an intereactive shell by not passing a command. If a command is passed,
the single command is ran with output then ssh exits.(exit) command will exit shell.
usage: ssh [-h] [--password PASSWORD] [-p PORT] host [command]
positional arguments:
host host ex. user@host.com
command Command to send as a quoted stringoptional arguments:
-h, --help show this help message and exit
--password PASSWORD Password for rsa/dsa key or password login
-p PORT, --port PORT port for ssh default: 22
</pre>
ssh.py -
It would be nice to have the zip comand on Stash, I only see unzip or tar, but Pythonista don't recognize tar.gz
-
@mncfre
zip
is now added. You can get it viaselfupdate
from within StaSh. Or if you want to get the latest development version, trySELFUPDATE_BRANCH=dev selfupdate
. You'll need restart StaSh afterwards. Thanks! -
@ywangd thanks a lot, this is by far the best shell in Pythonista
-
I noticed that the pip command allows you to list all modules installed using this command and specially allows you to update individual modules! This is very useful! So I cleaned up my environment in Pythonista and now I'm handling everything with StaSh.
I was able to run many libraries in Pythonista without having to change them much, I tried only to override the functions. So now I'm creating StaSh scripts for running CLI program written in Python: in practice the first time they are run if the modules they needs are not installed they install these modules (as the command git) and apply monkey patches.
For those who have just installed Pythonista and want to install StaSh I created a simplified installation creating a shortened url for getstash.py.
To install StaSh just copy the following line in the Pythonista console:
import requests; exec requests.get('http://bit.ly/StaSh').text
Congratulations to all for this fantastic tool!
-
@whitone - Thanks for posting this. I have never used pip and my setup under Pythonista is now littered with many modules that I manually "installed". It is not hard, but I figured that there must be a better way. I also have no idea what monkey patches are about so I need to do some reading.
If you have any cycles it would be very instructional to have one quick tutorial on a useful program you installed and converted and the patches you had to apply to get it working and how you now have this captured and automated using stash - pip, etc.
One last question - are you referring to CLI programs in general or using the PyCLI module: https://pythonhosted.org/pyCLI/ ? This seems like a great way to go for writing scripts and gets people going using logging and a good command line interface.
-
-
@whitone Glad you find the pip module useful. It's still limited on which packages it can install but it manages most of the common ones. We have tried to stub out setuptool as best we can but there are so many use cases. Currently pip will simply look for a folder with the same name as the package and put it into site-packages. Then it will look for src/package_name and as a last resort will attempt to run the setup.
I think @omz should add StaSh to the pythonista installation. It;s incredably useful and community developed. Props to @ywangd for creating such an awesome package.
-
@whitone The one line installation is a great idea. If it is OK with you, I'll add it to the README file as part of the installation instruction. The great work of
pip
is done by @briarfox. StaSh is made better by the excellent contributions from the community.After seeing the discussions, I am thinking to have something like "Tip/Treasure of the day" when StaSh starts up. Seems to be a good way for users to discover some useful tools and features in a non-intrusive manner.
-
@ywangd Tip of the day is a great idea, If I hadn't recently dove into linux command-line I'd be lost in staSh.
-
Great tool, thank you.<br /><br />
I want to ask if there is a trick using the find command?<br />
I always get:<br />
stash: IndentationError('unindent does not match any outer indentation level', ('findy.py', 148, 17, ...)<br /><br />
[~/Documents]$ find . -name "*.py" -
@brumm works for me. Probably you edited
bin/find.py
by accident. The original is 147 lines long, but the error message refers to line 148..,