Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bash typewriter simulator

554 views
Skip to first unread message

chipschap

unread,
Nov 24, 2011, 2:01:36 PM11/24/11
to
For all of you creative writers out there who like minimalist
environments, here is a bash typewriter simulator. No arrow keys,
backspacing, cut and paste, nothing. What you type is what you get and
you better get it right the first time. Some writers think this helps
them focus and think about what they're writing instead of just typing
any old thing. Other writers say it makes them faster because they
can't back up and edit, they just have to keep typing. Whatever.

The script is posted below. Updates (if any, hah), and a clean version
without potential superfluous line wraps caused by posting, appear at

http://www.bobnewell.net/filez/bashwriter

############################ begin bashwriter
#############################
#!/bin/bash

# Bash typewriter simulator.

# Runs on any relatively recent Linux system.
# Not tested on anything else.

# This is a 'pure typing' environment. Like a typewriter,
# you can't backspace, can't edit, can only type. This is
# supposed to increase creative writing quality and output,
# though your mileage definitely may vary. The ideas are that

# (1) you have no choice but to keep typing and
# (2) you type less junk when you know you can't erase it.

# That's the theory, anyhow. But the fact is that this is a
# dead simple typing environment (it's certainly not an editor
# as such) that will run on just about any modern Linux system.

# Usage: bashwriter filename

# 'filename' is the input/output file and is required.
# The program is exited by pressing ctrl-C or ctrl-Z.

# Typing: this is like a typewriter. You have to do a carriage
# return at the end of a line. A real typewriter has a backspace
# key, tab key, etc., but this one doesn't because we can't simulate
# overstrikes on a terminal and we don't want to bother with coding
# stuff like tab settings.

# Additional features are not anticipated; they would not be in
# keeping with this bare minimalist approach. So no typing sounds,
# color changes, choice of fonts, etc. You can do some of that stuff
# by setting up a bash profile. Call it a 'typing' profile if you
# want and put a command on your menu to call this program with that
# profile. Black type on a creamy white background and a fixed-width
# typewriter font would be in keeping with the theme.

# If you are foolish enough to think this script is any good,
# consider the fact that another fellow wrote an excellent typewriter
# simulator in about 20 lines of HTML. Now *that* is good!

# Comments, bugs, changes to: bashw...@bobnewell.net
# Note that this is not a promise of performance.

# The script is Copyright (C) 2011 by Futrezo Software Systems, a
division
# of Mr. Fred Investments. A free, unlimited, non-exclusive license
# to use the script in any legal manner is granted. You may use it,
# change it, create derivative works, sell it, give it away, or do
# anything you like as long as it is lawful, but you may not take
# ownership of the original script from us.

# No warranties are provided, nor is any form of liability accepted.
# No support is offered or provided.

# 2011/11/24 0.02 Thanksgiving Day release.
# Cleaned up a few things.
# Probably as 'final' as it's going to get.
# (Famous last words.)
# 2011/11/23 0.01 Bob Newell, Honolulu, Hawai`i.
# Initial coding.

function fish {
# Program termination function, as in 'go fish'.
IFS=$saveifs
reset
exit 0
}

version="0.02 of 24 Nov 2011"

saveifs=$IFS
IFS=""

# The size of the preserved text on the screen. This helps
# mimic typewriter-like scrolling up. Right now it's hardwired.
# It should really be based on the screen height but $LINES doesn't
# seem to work within a bash script.

tailsize=10

tfile=$1

echo "BASHWRITER typewriter simulator, version $version."

# Test for specification of file.
if [[ "$tfile" == "" ]]
then
echo "No typewriter file specified."
exit 1
fi

# Test existence of file. If not, try to create.
if [[ ! -f "$tfile" ]]
then
touch "$tfile" 2>/dev/null
if [[ $? -ne 0 ]]
then
echo "Cannot create typewriter file $tfile."
exit 1
fi
fi

# See if the file is writable.
if [[ ! -w "$tfile" ]]
then
echo "Typewriter file $tfile cannot be opened for writing."
exit 1
fi

# Clear screen and put initial lines up.
clear
tail -$tailsize $tfile 2>/dev/null

# Traps follow. 'fish' is a closeout routine which resets
# the console, etc.

trap fish QUIT
trap fish INT
trap fish HUP
trap fish TSTP

C=""

# Remember: we have to ctrl-C out of the program.

while [[ 1 -eq 1 ]];
do

# Read one character at a time, no escape sequences, no screen echo.

read -n 1 -s -r C
if [[ $C != "" ]]
then

# Process anything but carriage return, which comes through as "".
# Then test printable, ignore if not. This gets rid of backspace etc.
# If the char is usable, echo to the file and to the screen.
# This requires POSIX which any relatively recent Linux system will
have.

if [[ $C == [[:print:]] ]]
then
echo -n $C >>$tfile
echo -n $C
fi
else

# Carriage return was evidently typed, triggering a scroll up.

echo "" >>$tfile
clear
tail -$tailsize $tfile
fi
done

############################# end bashwriter #########################

bakric...@gmail.com

unread,
Oct 10, 2012, 9:30:11 PM10/10/12
to
how do i d.l?

Chris F.A. Johnson

unread,
Oct 10, 2012, 9:58:32 PM10/10/12
to
On 2012-10-11, bakric...@gmail.com wrote:
> On Thursday, November 24, 2011 2:01:36 PM UTC-5, chipschap wrote:
...
>> http://www.bobnewell.net/filez/bashwriter
...
> how do i d.l?

wget http://www.bobnewell.net/filez/bashwriter

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

Kaz Kylheku

unread,
Oct 10, 2012, 11:32:20 PM10/10/12
to
On 2012-10-11, Chris F.A. Johnson <cfajo...@gmail.com> wrote:
> On 2012-10-11, bakric...@gmail.com wrote:
>> On Thursday, November 24, 2011 2:01:36 PM UTC-5, chipschap wrote:
> ...
>>> http://www.bobnewell.net/filez/bashwriter
> ...
>> how do i d.l?
>
> wget http://www.bobnewell.net/filez/bashwriter

Bah,

http://git.savannah.gnu.org/cgit/bash.git/tree/examples/scripts/line-input.bash

Chris F.A. Johnson

unread,
Oct 11, 2012, 12:06:27 AM10/11/12
to
The original script was designed to be a "typewriter" that accepted no
editing. That needs nothing more than:

printf "Enter file name: "
read file
echo "Press ^D to quit"
cat > "$file"

Aaron W. Hsu

unread,
Oct 11, 2012, 2:06:40 PM10/11/12
to
On Thu, 11 Oct 2012 00:06:27 -0400, Chris F.A. Johnson
<cfajo...@gmail.com> wrote:

> The original script was designed to be a "typewriter" that accepted no
> editing. That needs nothing more than:
>
> printf "Enter file name: "
> read file
> echo "Press ^D to quit"
> cat > "$file"

On most systems, that will still allow for line editing, unless you
explicitly disable it.

--
Aaron W. Hsu | arc...@sacrideo.us | http://www.sacrideo.us
Programming is just another word for the Lost Art of Thinking.

Chris F.A. Johnson

unread,
Oct 11, 2012, 6:10:11 PM10/11/12
to
On 2012-10-11, Aaron W. Hsu wrote:
> On Thu, 11 Oct 2012 00:06:27 -0400, Chris F.A. Johnson
><cfajo...@gmail.com> wrote:
>
>> The original script was designed to be a "typewriter" that accepted no
>> editing. That needs nothing more than:
>>
>> printf "Enter file name: "
>> read file
>> echo "Press ^D to quit"
>> cat > "$file"
>
> On most systems, that will still allow for line editing, unless you
> explicitly disable it.

I haven't seen a system where it allows any editing other than backspacing
and deleting the previous character.

This bash script allows more line editing:

printf "Enter file name: "
read file
echo "Press ^D to quit"
while IFS= read -rep ''
do
printf "%s\n" "$REPLY"
done > "$file"

Kaz Kylheku

unread,
Oct 11, 2012, 6:57:31 PM10/11/12
to
On 2012-10-11, Chris F.A. Johnson <cfajo...@gmail.com> wrote:
> On 2012-10-11, Aaron W. Hsu wrote:
>> On Thu, 11 Oct 2012 00:06:27 -0400, Chris F.A. Johnson
>><cfajo...@gmail.com> wrote:
>>
>>> The original script was designed to be a "typewriter" that accepted no
>>> editing. That needs nothing more than:
>>>
>>> printf "Enter file name: "
>>> read file
>>> echo "Press ^D to quit"
>>> cat > "$file"
>>
>> On most systems, that will still allow for line editing, unless you
>> explicitly disable it.
>
> I haven't seen a system where it allows any editing other than backspacing
> and deleting the previous character.

Right, erasing and retyping are not the *true* Scotsman's editing features.

Ben Bacarisse

unread,
Oct 11, 2012, 8:48:48 PM10/11/12
to
"Chris F.A. Johnson" <cfajo...@gmail.com> writes:

> On 2012-10-11, Aaron W. Hsu wrote:
>> On Thu, 11 Oct 2012 00:06:27 -0400, Chris F.A. Johnson
>><cfajo...@gmail.com> wrote:
>>
>>> The original script was designed to be a "typewriter" that accepted no
>>> editing. That needs nothing more than:
>>>
>>> printf "Enter file name: "
>>> read file
>>> echo "Press ^D to quit"
>>> cat > "$file"
>>
>> On most systems, that will still allow for line editing, unless you
>> explicitly disable it.
>
> I haven't seen a system where it allows any editing other than backspacing
> and deleting the previous character.

My Linux system also allows me to erase a word and to kill the whole
line.

<snip>
--
Ben.

Chris F.A. Johnson

unread,
Oct 11, 2012, 9:59:29 PM10/11/12
to
So it does. But it will only delete to the left, and one cannot move the
cursor over the line as you can with read -e.

Aaron W. Hsu

unread,
Oct 12, 2012, 3:57:20 AM10/12/12
to
On Thu, 11 Oct 2012 21:59:29 -0400, Chris F.A. Johnson
<cfajo...@gmail.com> wrote:

> On 2012-10-12, Ben Bacarisse wrote:
>> "Chris F.A. Johnson" <cfajo...@gmail.com> writes:
>>
>>> On 2012-10-11, Aaron W. Hsu wrote:
>>>> On Thu, 11 Oct 2012 00:06:27 -0400, Chris F.A. Johnson
>>>> <cfajo...@gmail.com> wrote:
>>>>
>>>>> The original script was designed to be a "typewriter" that
>>>>> accepted no
>>>>> editing. That needs nothing more than:
>>>>>
>>>>> printf "Enter file name: "
>>>>> read file
>>>>> echo "Press ^D to quit"
>>>>> cat > "$file"
>>>>
>>>> On most systems, that will still allow for line editing, unless you
>>>> explicitly disable it.
>>>
>>> I haven't seen a system where it allows any editing other than
>>> backspacing
>>> and deleting the previous character.
>>
>> My Linux system also allows me to erase a word and to kill the whole
>> line.
>
> So it does. But it will only delete to the left, and one cannot move
> the
> cursor over the line as you can with read -e.

I think part of the point of the original script was to simulate a
typewriter. One of the main points about a typewriter in that script is
that you cannot do *any* editing. Being able to erase characters defeats
the simulation. The simulator is supposed to be just like typing directly
onto the paper.

Barry Margolin

unread,
Oct 12, 2012, 10:40:49 AM10/12/12
to
In article <op.wl121usr0p3ku8@localhost>,
It's been a while, but I think the last typewriter I used had an
automatic white-out feature that could be used to delete individual
characters backwards.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Aaron W. Hsu

unread,
Oct 12, 2012, 3:31:49 PM10/12/12
to
On Fri, 12 Oct 2012 10:40:49 -0400, Barry Margolin <bar...@alum.mit.edu>
wrote:

> It's been a while, but I think the last typewriter I used had an
> automatic white-out feature that could be used to delete individual
> characters backwards.

I always considered that cheating. :-) Mostly, the only typewriters that
have really interested me were the Selectric (for the novel type-ball) and
the purely mechanical ones. Did any of the pure mechanical ones have a
ribbon for white-out? I guess the UNIX line editing features would sort of
constitute the white-out feature, but the ^W and ^U still do a little more
than that.

giacomo boffi

unread,
Oct 13, 2012, 1:11:17 PM10/13/12
to
"Aaron W. Hsu" <arc...@sacrideo.us> writes:

> I think part of the point of the original script was to simulate a
> typewriter. One of the main points about a typewriter in that script
> is that you cannot do *any* editing. Being able to erase characters
> defeats the simulation. The simulator is supposed to be just like
> typing directly onto the paper.

The simulator is supposed to be just like

<creepy music> punching holes in a card. </creepy music>

David Combs

unread,
Dec 7, 2012, 7:13:20 PM12/7/12
to
In article <op.wl2y7bwz0p3ku8@localhost>,
Aaron W. Hsu <arc...@sacrideo.us> wrote:
>On Fri, 12 Oct 2012 10:40:49 -0400, Barry Margolin <bar...@alum.mit.edu>
>wrote:
>
>> It's been a while, but I think the last typewriter I used had an
>> automatic white-out feature that could be used to delete individual
>> characters backwards.
>
>I always considered that cheating. :-) Mostly, the only typewriters that
>have really interested me were the Selectric (for the novel type-ball) and
>the purely mechanical ones. Did any of the pure mechanical ones have a
>ribbon for white-out?

Yes, I remember a wee reel of IBM white-out tape that fit on a selectric.
And on hitting a certain key (I don't recall which), the white-out tape
would pop up in front of the ink-tape (which itself was between the ball
and the paper, of course.)

But that's just my memory; I could be wrong.

I do recall saying, when the conversation got to IBM computers and especially
OSes such as TSO and VM/CMS, that well, they sure made good typewriters! (if
nothing else).



I guess the UNIX line editing features would sort of
>constitute the white-out feature, but the ^W and ^U still do a little more
>than that.
>
>--
>Aaron W. Hsu | arc...@sacrideo.us | http://www.sacrideo.us
>Programming is just another word for the Lost Art of Thinking.

David

Jon LaBadie

unread,
Dec 8, 2012, 6:51:44 PM12/8/12
to
On 12/07/2012 07:13 PM, David Combs wrote:
> In article <op.wl2y7bwz0p3ku8@localhost>,
> Aaron W. Hsu <arc...@sacrideo.us> wrote:
>> On Fri, 12 Oct 2012 10:40:49 -0400, Barry Margolin <bar...@alum.mit.edu>
>> wrote:
>>
>>> It's been a while, but I think the last typewriter I used had an
>>> automatic white-out feature that could be used to delete individual
>>> characters backwards.
>>
>> I always considered that cheating. :-) Mostly, the only typewriters that
>> have really interested me were the Selectric (for the novel type-ball) and
>> the purely mechanical ones. Did any of the pure mechanical ones have a
>> ribbon for white-out?
>
> Yes, I remember a wee reel of IBM white-out tape that fit on a selectric.
> And on hitting a certain key (I don't recall which), the white-out tape
> would pop up in front of the ink-tape (which itself was between the ball
> and the paper, of course.)
>
> But that's just my memory; I could be wrong.
>

My memory differs slightly. The IBM Selectric didn't us an "inked ribbon"
but a clear film coated with fine black powder. The impact left the carbon
on the surface of the paper rather than being absorbed into the fibers.

The erase tape was not "white out" but a film coated with adhesive. When
it was struck, it picked up the black powder from the surface of the paper.
It didn't cover it up the way "white out" would, but actually removed it.

jl


Message has been deleted
0 new messages