|
5 | 5 | <link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
|
6 | 6 | <link href="https://learnbyexample.github.io"/>
|
7 | 7 | <generator uri="https://www.getzola.org/">Zola</generator>
|
8 |
| - <updated>2023-08-16T00:00:00+00:00</updated> |
| 8 | + <updated>2023-08-17T00:00:00+00:00</updated> |
9 | 9 | <id>https://learnbyexample.github.io/atom.xml</id>
|
| 10 | + <entry xml:lang="en"> |
| 11 | + <title>Interactive exercises for GNU grep, sed and awk (TUI apps)</title> |
| 12 | + <published>2023-08-17T00:00:00+00:00</published> |
| 13 | + <updated>2023-08-17T00:00:00+00:00</updated> |
| 14 | + <link rel="alternate" href="https://learnbyexample.github.io/interactive-grep-sed-awk-exercises/" type="text/html"/> |
| 15 | + <id>https://learnbyexample.github.io/interactive-grep-sed-awk-exercises/</id> |
| 16 | + <content type="html"><p>Having an interactive program that automatically loads questions and checks the solution is immensely helpful to have while learning a topic. I've written <a href="https://github.com/learnbyexample/TUI-apps">TUI apps</a> with plenty of beginner to intermediate level exercises for <code>GNU grep</code>, <code>GNU sed</code> and <code>GNU awk</code>.</p> |
| 17 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/GrepExercises/grep_exercises.png" alt="Sample screenshot for GNU grep exercises" loading="lazy" /></p> |
| 18 | +<span id="continue-reading"></span><br> |
| 19 | +<h2 id="installation">Installation<a class="zola-anchor" href="#installation" aria-label="Anchor link for: installation">🔗</a></h2> |
| 20 | +<p>For the past few months, I've been using a Python framework called <a href="https://textual.textualize.io/">Textual</a> to create interactive TUI apps.</p> |
| 21 | +<p>You'll need Python for this (I used 3.8, it should work for more recent versions too). This app is available on PyPI as <a href="https://pypi.org/project/grepexercises/">grepexercises</a>, <a href="https://pypi.org/project/sedexercises/">sedexercises</a> and <a href="https://pypi.org/project/awkexercises/">awkexercises</a>. Example installation instructions are shown below, adjust them based on your preferences and OS.</p> |
| 22 | +<pre data-lang="bash" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#7f8989;"># virtual environment |
| 23 | +</span><span style="color:#5597d6;">$</span><span> python3</span><span style="color:#5597d6;"> -m</span><span> venv textual_apps |
| 24 | +</span><span style="color:#5597d6;">$</span><span> cd textual_apps |
| 25 | +</span><span style="color:#5597d6;">$</span><span> source bin/activate |
| 26 | +</span><span style="color:#5597d6;">$</span><span> pip install grepexercises sedexercises awkexercises |
| 27 | +</span><span> |
| 28 | +</span><span style="color:#7f8989;"># launch the app, example shown for the grep command |
| 29 | +</span><span style="color:#5597d6;">$</span><span> grepexercises |
| 30 | +</span></code></pre> |
| 31 | +<p>To run the app without having to enter the virtual environment again, add aliases to <code>.bashrc</code> (or equivalent):</p> |
| 32 | +<pre data-lang="bash" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#7f8989;"># you&#39;ll have to change the path |
| 33 | +</span><span style="color:#b39f04;">alias </span><span style="color:#c23f31;">grepexercises</span><span style="color:#72ab00;">=</span><span style="color:#d07711;">&#39;/path/to/textual_apps/bin/grepexercises&#39; |
| 34 | +</span><span> |
| 35 | +</span><span style="color:#7f8989;"># similarly, you can add aliases for the other apps as well |
| 36 | +</span></code></pre> |
| 37 | +<p>As an alternative, you can install <code>textual</code> (see <a href="https://textual.textualize.io/getting_started/">Textual documentation</a> for more details), clone my <a href="https://github.com/learnbyexample/TUI-apps">TUI-apps repository</a> and run the Python file from respective folders. For example, <code>grep_exercises.py</code> for the <code>grep</code> command.</p> |
| 38 | +<p>Adjust the terminal dimensions for the widgets to appear properly, for example 84x25 (characters x lines).</p> |
| 39 | +<blockquote> |
| 40 | +<p><img src="/images/info.svg" alt="info" /> You can use alternative CLI tools to solve these exercises as well. For example, <code>perl</code> instead of <code>GNU awk</code> or <code>ripgrep</code> instead of <code>GNU grep</code> and so on.</p> |
| 41 | +</blockquote> |
| 42 | +<br> |
| 43 | +<h2 id="brief-guide">Brief Guide<a class="zola-anchor" href="#brief-guide" aria-label="Anchor link for: brief-guide">🔗</a></h2> |
| 44 | +<p>You can either click the buttons using mouse or press the key combinations listed below:</p> |
| 45 | +<ul> |
| 46 | +<li>Press <strong>F1</strong> to view the complete guide from within the app itself.</li> |
| 47 | +<li>Press <strong>Ctrl+p</strong> and <strong>Ctrl+n</strong> to navigate the questions list.</li> |
| 48 | +<li>Type the command in the box below the question.</li> |
| 49 | +<li>Press <strong>Enter</strong> to execute the command. |
| 50 | +<ul> |
| 51 | +<li>Output would be displayed below the command box.</li> |
| 52 | +<li>If the output matches the expected results, the command box will turn <em>green</em> and reference solutions will also be shown.</li> |
| 53 | +<li>Issues due to errors and timeout (about <code>2</code> seconds) will be displayed in <em>red</em>.</li> |
| 54 | +</ul> |
| 55 | +</li> |
| 56 | +<li>Press <strong>Ctrl+s</strong> to view reference solutions anytime you want.</li> |
| 57 | +<li>Press <strong>Ctrl+t</strong> to toggle between light and dark themes.</li> |
| 58 | +<li>Press <strong>Ctrl+q</strong> to quit the app.</li> |
| 59 | +<li>Some basic readline-like shortcuts are supported, for example <strong>Ctrl+u</strong>, <strong>Ctrl+k</strong>, <strong>Ctrl+w</strong>, etc</li> |
| 60 | +</ul> |
| 61 | +<p>Your progress is automatically saved when you close the app and restored when you launch it again later. Already answered questions will be skipped.</p> |
| 62 | +<blockquote> |
| 63 | +<p><img src="/images/warning.svg" alt="warning" /> There is no safeguard against the command you are executing. They are treated as if you typed them from a shell session.</p> |
| 64 | +</blockquote> |
| 65 | +<br> |
| 66 | +<h2 id="ebooks">Ebooks<a class="zola-anchor" href="#ebooks" aria-label="Anchor link for: ebooks">🔗</a></h2> |
| 67 | +<p>The exercise questions in these apps have been adapted from my programming ebooks: <a href="https://learnbyexample.github.io/books/">https://learnbyexample.github.io/books/</a></p> |
| 68 | +<br> |
| 69 | +<h2 id="feedback">Feedback<a class="zola-anchor" href="#feedback" aria-label="Anchor link for: feedback">🔗</a></h2> |
| 70 | +<p>I'd highly appreciate your feedback. Please file <a href="https://github.com/learnbyexample/TUI-apps/issues">an issue</a> if there are bugs, crashes, etc.</p> |
| 71 | +<p>Hope you find these TUI apps useful. Happy learning :)</p> |
| 72 | +</content> |
| 73 | + </entry> |
10 | 74 | <entry xml:lang="en">
|
11 | 75 | <title>Python tip 32: positive lookarounds</title>
|
12 | 76 | <published>2023-08-16T00:00:00+00:00</published>
|
|
0 commit comments