Package: sharpshooter
🌳 tree (sharpshooter)Shorthand templates for creating (or destroying) file-systems.tree could be written for any language.installpython3-mpipinstallsharpshooter--upgrade# for just sharpshooterpython3-mpipinstallsharpshooter[jinja2]# sharpshooter with jinja2 cli extensionCLI quick startcd/path/to/some/folder
sharpshooter-chello# now open and edit the created hello.tree file in any text editor of your choice# i.e sudo vim hello.treesharpshooter-thello.tree# run -t to testsharpshooter-fhello.tree# or -f to create folders/files specified hello.treesharpshooter--mock# creates a sharpshooter.tree file of the current working directoryintroTo create a plain empty file just type a word i.e.fileto create or access a dir use a slash //dirTo create a file inside a dir use a 4 spaces (or tab)/dir
    fileputting it all together…/dir
    file
    /plugins
    /mail
        /vendor
        index.html
            /something # this one will fail
        file.py
        file.py/ (slash) Creating a treefromsharpshooterimporttreetree('''/dirfile/plugins/mail/vendorindex.htmlfile.pyfile2.py''')tree doesn't wait to be told. Your files are now there.- (minus) deleting a treetree can also remove dirs and files. You guessed it. With the the - minus symboltree='''/dir/plugins-mail'''tree will not ask twice. Your files are gone.But be mindful this example would also 'create' the dir and plugins folders if they didn't exist. Because tree by nature creates by default.To read info about a file or folder without creation use colon ':' to indicate read-only.tree=''':/dir:/plugins-mail'''More on colons : later.WARNING - be careful using minus. tree could destroy your entire filesytem if used incorrectly# (hash) commentsUse # to comment out a line or instruction.s='''/:dirfile# some ignored text here/plugins/mail'''WARNING - the # symbol is ignored if it comes after the <, $ or > symbols. (see why further down): (colon) read onlyTo read info about a file or folder, without creating any, use a colon ':'You can then format the tree with an f-string to get the result which produces similir output as 'ls -al' on nix systems i.e.test=tree(''':README.md''')print(f"{test}")# -rw-r--r-- byteface staff 2100 21 Sep 07:58 README.mdor for a directory...test=tree(''':venv''')print(f"{test}")# drwxr-xr-x byteface staff 192 Mon Sep 20 10:18:44 2021 venvNotice the little 'd' at the front lets you know it's a directory. Just like in a terminal.you can safely change change order of colon and plus i.e. will still work.tree(''':/dont:/make:this''')but i prefer to use the colon right before the file or folder name .i.e.tree('''/:dont/:make:this''')up to you.test modeIf you are feeling unsure. Try tree in test mode.It will log what it would do to the console but won't actually create any files or folders.You just have to past test=True to the tree function. i.emytree='''/somedir/anotherdirsomeotherfile.pngfile.txtfile2.gif'''tree(mytree,test=True)# notice how we set test=TrueNow check the console and if you feel confident set test=False and run the code again.~ (tilde) users home direcoryusers home path is supported.s1=""":/~test.png/somedirsomescript.py"""tree(s1,test=True)tree(s1,test=False)< (lt) write to a file< This symbol can be used to write a string to a file.mystring="""/somedirsomescript.py < print('hello world!')some.txt < hello world!script.sh < echo 'hello world'"""tree(mystring)you can use \n to add more than one line to a file.mystring="""/somedirsomepage.md < # heading\n## another heading\n### and another heading"""tree(mystring)WARNING - the comment # symbols are ignored after the < so they can be succesfully written to files. (i.e. .md files)$ (dollar) pass to the shellAnything after the $ symbol is passed to the shell and the result is written to the file.mystring="""/somedirtest.txt $ cowsay moo"""tree(mystring)WARNING - comments # symbol is ignored after the $ so don't use comments on these lines or they could be sent to the terminal> (gt) pass to windows cmdbash commands won't work on windows. Instead use the > symbol for windows commandsAnything after the > symbol is passed to cmd with the result written to the file.mystring="""/somedirtest.txt $ ls -altest.txt > dir"""tree(mystring)WARNING - comments # symbol is ignored after the > so don't use comments on these lines or they could be sent to cmd? (question)A question will take user input. It can be used in place of a filename.mystring="""/somedirsomefile.txt?anotherfile.txt ?/?info.txt"""tree(mystring)In this example a prompt would ask for a filename inbetween creating somefile.txt and anotherfile.txt.Then a multi-line prompt would ask for content to be input for anotherfile.txt.Lastly a prompt would ask for the folder name to be created before putting info.txt in it.WARNING - comments # symbol is ignored after the > so don't use comments on these lines or they could be sent to cmd#[name] labelsA label is a way to store multiple trees in a single file.By using square brackets after a # symbol you can label a tree. i.e.#[mylabel]
/dir
    fileYou can now pass the label to the tree function.sharpshooter--testmyconfig.tree-lmylabel# use --label to only parse part of a .tree fileAnything else?you can now have spaces in filenames.tips: use with a proxy server and range requests to write partials to files.To see planned features/goals see TODO.mdCLIThere's several commands you can pass to sharpshooter on the command line.python3-msharpshooter--help# shows available commands. also uses -hsharpshooter--version# shows the current version. also uses -vsharpshooter--createsomeconfigname# creates a helloworld.tree file. also uses -csharpshooter--filemyconfig.tree# parses a .tree file and executes it. also uses -fsharpshooter--testanotherconfig.tree# parses a .tree file in test mode. also uses -tsharpshooter--mock# makes a sharpshooter.tree file based on the current working directory. also uses -m# sharpshooter --mock 1  # pass optional depth as intsharpshooter--dir# set the current working directory. use with other commands. also uses -d#i.e. python -m sharpshooter -d tests -f test.treesharpshooter--pretty0# prints a pretty tree of the cwd. also uses -p# i.e# ├── refs# │   ├── heads# │   │   ├── question# │   │   ├── master# │   │   └── anytree# │   ├── tags# │   └── remotes# │       └── origin# │           └── master# takes optional parameter for depth : intThere's an optional feature that requires jinja2:python-mpipinstalljinja2# make sure you have jinja2 installedsharpshooter--jinjamyconfig.treearg1=test# parses a .tree but runs through jinja first. also uses -j(note. jinja2 is not part of sharpshooter so you need to install it yourself. its an optional CLI dependency)(note. jinja2 has no test mode yet so be careful)NOTESI came up with the idea while mucking around with a lexer.https://www.dabeaz.com/ply/https://github.com/dabeaz/plyremember it executes from where your python thinks is the current dir.
If you're unsure set it first. i.e.importos
os.chdir(os.path.dirname(os.path.abspath(__file__)))For your information, tree is the language and sharpshooter is an implementation.pretty is available on the tree class as a static method.from sharpshooter import tree
tree.pretty(tree_string)ContributingIf you think you can write a sharpshooter parser in another language then please do and i'll link to your repo.To dev on this one locally just pull the repo and do...cd/sharpshooter
python3-mvenvvenv
.venv/bin/activate# lnux, # windows: venv\Scripts\activatepipinstall-rrequirements.txtpython-msharpshooter-dtests-ftest.tree# to use code version without installingmaketest# to run testsOr run and write some tests, there's a few to get started in the Makefile.You can install your own version using...python3-mpipinstall-e.There's several test.tree files in the /tests you can tweak and run through the CLI.It creates a tmp folder you can delete and rerun to experiment. i.e./tmp
    /hello
        world.txt < y tho!
        page.html < <html>y tho!</html>
    /this # some comment
        /is
            cool.txt $ cowsay cool
            cool.txt > dir
            test.md < # heading \n## another heading \n### and another heading
    page.html $ curl -s https://www.google.com
    page2.htm $ curl -s https://www.fileformat.info/info/charset/UTF-32/list.htm
    /partial
        star.html $ curl -s -r 32-35 https://raw.githubusercontent.com/byteface/domonic/master/docs/_templates/sidebarintro.html
    files.txt $ find .DISCLAIMER / known bugsUse 4 spaces not tabs.This is a work in progress. It creates and destroys files on your hard drive. So be careful.DON'T leave trailing negative space on lines. I use space to change dirs.comments won't work on lines with bash/windows commands or when writing to file. this is so you can write # symbols to the file.filenames with special chars #?><$ at start or end may cause issues until escaping them is sorted.