Skip to content

Instantly share code, notes, and snippets.

@bk2204
Created June 10, 2016 22:38
Show Gist options
  • Save bk2204/d0280168ee5f498c4e29221b4f83e09a to your computer and use it in GitHub Desktop.
Save bk2204/d0280168ee5f498c4e29221b4f83e09a to your computer and use it in GitHub Desktop.
Transcript of editing session using ex
What is this?

A transcript of an editing session using ex.

ex?

If you’ve used Vim or vi, any time you type a command starting with “:”, you’re writing an ex command. ex is the command-line only editor, and vi was originally written to provide better editing on non-dumb terminals.

Why use ex?

This is an exercise in what editing used to be like before the advent of vi. Basically, a retro computing exercise. ex is also easily scriptable from the command line; I’ve used it in git hooks.

What program did you write?

This is a Ruby implementation of sha256sum (generation only). It appears to work correctly.

vauxhall ok % ex -s hash.rb
i
#!/usr/bin/ruby
require 'digest'
def main(args)
.
:echo &ts
echo &ts
set
helplang=es modified fileencodings=ucs-bom,utf-8,default,latin1
a
fp = args.map { |f| File.new(f, 'r') }
fp = [$stdin] if fp.empty?
.
%p
#!/usr/bin/ruby
require 'digest'
def main(args)
fp = args.map { |f| File.new(f, 'r') }
fp = [$stdin] if fp.empty?
a
.
p
fp = [$stdin] if fp.empty?
-1
p
fp = args.map { |f| File.new(f, 'r') }
.,.+1c
fp = args.map { |f| [f, File.new(f, 'r')] }
fp = [['-', $stdin]] if fp.empty?
.
%p
#!/usr/bin/ruby
require 'digest'
def main(args)
fp = args.map { |f| [f, File.new(f, 'r')] }
fp = [['-', $stdin]] if fp.empty?
a
fp.each do |(name, io)|
d = Digest::SHA256.new
io.each { |l| d << l }
puts d.hexdigest + " " + name
end
end
.
%p
#!/usr/bin/ruby
require 'digest'
def main(args)
fp = args.map { |f| [f, File.new(f, 'r')] }
fp = [['-', $stdin]] if fp.empty?
fp.each do |(name, io)|
d = Digest::SHA256.new
io.each { |l| d << l }
puts d.hexdigest + " " + name
end
end
a
main(ARGV) if __FILE__ == $PROGRAM_NAME
.
%p
#!/usr/bin/ruby
require 'digest'
def main(args)
fp = args.map { |f| [f, File.new(f, 'r')] }
fp = [['-', $stdin]] if fp.empty?
fp.each do |(name, io)|
d = Digest::SHA256.new
io.each { |l| d << l }
puts d.hexdigest + " " + name
end
end
main(ARGV) if __FILE__ == $PROGRAM_NAME
w
q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment