After finally getting my shell to respond to the up key, I needed to be able to integrate a history interface, so that instead of writing ‘get previous in history,’ the up key would print the actual history. Writing the history interface was actually pretty easy - and I got it working with no snags. Then I needed to figure out how get raw bytes in order to respond to key presses, without losing the ease of use of python’s sys.stdin.readline() function in order to handle each complete line of input correctly.
Continue reading
After fixing the bug that had kept me enthralled for days on end, I decided to add history to my shell. Like how in a normal terminal, when you press the UP key, it lets you walk through a whole bunch of earlier commands, to save yourself the typing. (Really smart shells have tab-autocompletion as well, but that’s another project for another day).
Continue reading
Where I left my shell yesterday, I knew that I had a problem, and I had spent hours tinkering with the code to diagnose the error. Why did single file redirects (ls -la > lsa.txt
) and multiple pipes (ls | wc | head
) work as expected, but piping & redirecting in the same command (ls | wc > ls_wc.txt
) go nuts?
Continue reading
Today I added input redirection to my shell (cat < ls.txt
). This actually went more smoothly than any previous redirect handling, YAY! BUT… when I tried to enable piping from an input redirect, I realized that the program was going in all sorts of circles. The ‘MUST REFACTOR’ this bells went off in my head. One problem: the only thing I knew about refactoring is that it’s what you’re supposed to do when your code is repetitive and/or hard to follow. I had no clue how you’re supposed to go about DOING it.
Continue reading