Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Created September 20, 2025 07:40
Show Gist options
  • Save lbvf50mobile/1efc56b9b42ed34cfe3360f8e235ff9e to your computer and use it in GitHub Desktop.
Save lbvf50mobile/1efc56b9b42ed34cfe3360f8e235ff9e to your computer and use it in GitHub Desktop.
Pipeline filter for Esperanto alphabet
#!/usr/bin/env -S ruby -n
# Esperanto filter.
#
# ^c, ^g, ^h, ^j, ^s, ^u => ĉ, ĝ, ĥ, ĵ, ŝ, ŭ
#
# It is a filter to be used in vim `V` selection and `!eo`.
# Neet to be placed into the $PATH. I.e. parent dir must be in $PATH, and
# filter must me named `eo`.
#
# Take a selection of text in vim and pipe it into this script,
# output will be placed into the selection.
#
# ^c, ^g, ^h, ^j, ^s, ^u => ĉ, ĝ, ĥ, ĵ, ŝ, ŭ
# https://apidock.com/ruby/String/gsub
# 'hello'.gsub(/[eo]/, 'e' => 3, 'o' => '*') #=> "h3ll*"
print $_.gsub(/\^[cghjsu]/i,
{'^c'=>?ĉ, '^g'=>?ĝ, '^h'=>?ĥ, '^j'=>?ĵ, '^s'=>?ŝ, '^u'=>?ŭ,
'^C'=>?Ĉ, '^G'=>?Ĝ, '^H'=>?Ĥ, '^J'=>?Ĵ, '^S'=>?Ŝ, '^U'=>?Ŭ
})
# But it changes a hole line, not just a selectio.
# ĉampiono => ĉampiono
# ^C Ĉ
# ^campiono ĉampiono
# ^cokolado ĉokolado
# ^G Ĝ
# eta^go etaĝo
# in^geniero inĝeniero
# ^H Ĥ
# ^horo ĥoro
# ^hemio ĥemio
# ^J Ĵ
# ^jaketo ĵaketo
# ^jurio ĵurio
# ^S Ŝ
# ma^sino maŝhino
# ati^so atiŝo
# ^soforo ŝoforo
# ^U Ŭ
# a^utomobilo aŭtomobilo
# a^uto aŭto
# a^utobuso aŭtobuso
# a^utoro aŭtoro
# kosmona^uto kosmonaŭto
# pa^uzo paŭso
# E^uropo
# Eŭropo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment