Skip to content

Commit

Permalink
Cleanup demo runner
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykv committed Jan 29, 2023
1 parent e402daf commit df6d481
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 59 deletions.
114 changes: 57 additions & 57 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
# PYBASH DEMO #
def run():
# dynamic interpolation
options = {'version': '-v', 'help': '-h'}
>git {{{options['h']}}}
namespace = "coffee"
>kubectl get pods {{{"--" + "-".join(['show', 'labels'])}}} --namespace {{{namespace}}}
# static interpolation
git_command = "status"
option = "-v"
>git {{git_command}} {{option}}
#TODO:
#a = >echo "hello" >> test.txt
#a = >sort < test.txt | grep "HELLO"
#print(f"test: {a}")
# 1. use inside methods
def cp_test():
print("1. >cp test.txt test_copy.txt")
>cp test.txt test_copy.txt

cp_test()

# 2. simple bash command execution with output
print("2. >python --version\n >echo \\nthis is an echo")
>python --version
>echo \\nthis is an echo

# 3. set output to python variable directly
out = >cat test.txt
test_data = out.decode('utf-8').strip()
print(test_data.replace("HELLO", "HOWDY"))

# 4. wrapped, in-line execution
print((>cat test.txt).decode('utf-8').strip())

# 5. redirection
>echo "hello" >> test4.txt

# 6. pipe chaining
>cat test.txt | sed 's/HELLO/HOWDY/g' | sed 's/HOW/WHY/g' | sed 's/WHY/WHEN/g'
# 7. chaining pipes and redirection- works with all!
>cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test5.txt
# 8. chained redirection
>cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test1.txt >> test2.txt > test3.txt

# 9. input redirection
>sort < test.txt >> sorted_test.txt
>sort < test.txt | sed 's/SORT/TEST\\n/g'
# 10. Glob patterns
$ls .github/*

# dynamic interpolation
options = {'version': '-v', 'help': '-h'}
>git {{{options['help']}}}

namespace = "coffee"
>kubectl get pods {{{"--" + "-".join(['show', 'labels'])}}} --namespace {{{namespace}}}

# static interpolation
git_command = "status"
option = "-v"

>git {{git_command}} {{option}}

#TODO:
#a = >echo "hello" >> test.txt
#a = >sort < test.txt | grep "HELLO"
#print(f"test: {a}")

# 1. use inside methods
def cp_test():
print("1. >cp test.txt test_copy.txt")
>cp test.txt test_copy.txt

cp_test()

# 2. simple bash command execution with output
print("2. >python --version\n >echo \\nthis is an echo")
>python --version
>echo \\nthis is an echo

# 3. set output to python variable directly
out = >cat test.txt
test_data = out.decode('utf-8').strip()
print(test_data.replace("HELLO", "HOWDY"))

# 4. wrapped, in-line execution
print((>cat test.txt).decode('utf-8').strip())

# 5. redirection
>echo "hello" >> test4.txt

# 6. pipe chaining
>cat test.txt | sed 's/HELLO/HOWDY/g' | sed 's/HOW/WHY/g' | sed 's/WHY/WHEN/g'

# 7. chaining pipes and redirection- works with all!
>cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test5.txt

# 8. chained redirection
>cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test1.txt >> test2.txt > test3.txt

# 9. input redirection
>sort < test.txt >> sorted_test.txt
>sort < test.txt | sed 's/SORT/TEST\\n/g'

# 10. Glob patterns
$ls .github/*
6 changes: 4 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python3

##
# Setup hook
import pybash

pybash.add_hook()

##
# Import demo script and run
if __name__ == "__main__":
import demo

Expand Down

0 comments on commit df6d481

Please sign in to comment.