Install py-tree on Pythonista3

How to install py-tree on Pythonista3 and use it easily.

With py-tree command, you can list files and directories in a tree view

[mysite]$ tree
.
|-- db.sqlite3
|-- manage.py
|-- mysite
|   |-- __init__.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- polls
    |-- __init__.py
    |-- admin.py
    |-- apps.py
    |-- models.py
    |-- tests.py
    |-- urls.py
    |-- views.py
    `-- migrations
        |-- 0001_initial.py
        `-- __init__.py

Not only in Pythonista3 but also in many cases, you want to see all directories and files of your project in a better format in CLI, StaSh in Pythonista3’s case. The py-tree command is the solution.

Installation

You can easily install by running the following command in StaSh (type strings after the command prompt [stash]$ and hit [enter]).

[stash]$ pip install py-tree

Run the command by entering only “tree”.

Entering a dash “-” character in iPhone is a bit annoying so let’s create an alias tree.
In StaSh, you can create .stashrc file which works like .bashrc file for Linux’s  bash shell. Follow the example below to create an alias.

[stash]$ cd site-packages/stash/
[stash]$ la
.gitignore .stash_history .stash_tips .travis.yml CHANGES.md LICENSE README.md __init__.py bin docs getstash.py lib man stash.py system
[stash]$ touch .stashrc
[stash]$ echo "alias tree='py-tree'" >> .stashrc
[stash]$ cat .stashrc
alias tree='py-tree'
[stash]$ la
.gitignore .stash_history .stash_tips .stashrc .travis.yml CHANGES.md LICENSE README.md __init__.py bin docs getstash.py lib man stash.py system

Quit and relaunch Pythonista3 to let StaSh load the .stashrc file. Now you can use the tree command. Woo-hoo!

Create and edit files with different file extension than “xxx.py”.

You cannot create a file like “.stashrc” in Pythonista3 as it adds surfix “.py”. Also, once a file is created, it won’t appear in the file list to edit. So, when you need to create such a file, use touch command then use edit command to edit it in Pythonista’s Edit screen. ls -a or its alias la is the command to show invisible files in StaSh.

Summary

PurposeStaSh CommandExample
Create invisible file.touchtouch .invisible
Edit file in Pythonista3.editedit .invisible
List files including invisible files.ls -a
or simply
la
la
(la .*
lists only invisible files.)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© Peddals.com