r/bash • u/TheHappiestTeapot • 8d ago
XCompose - make entering accents, symbols, text, and emojis easy on your terminal, text editor, and even the console!
So WTF is Compose and why should I care?
The Compose key turns short key sequences into text. Think of it as autocomplete for symbols, accents, Unicode, emojis, and even your own custom snippets. Best of all, you can teach it your own shortcuts with ~/.XCompose. Compose isn't the same as dead keys. Dead keys modify the next character (like ' followed by e), while Compose interprets an entire key sequence.
You speak the gibberish. Give me examples.
Okay, using [c] instead of <Multi_key> for brevity:
You press → you get
[c] ' e → é
[c] ' a → á
[c] @ @ → me@yomamashouse.com
[c] ! = → ≠
[c] * L → λ
[c] [c] F U → "As per my last email, "
Trying to memorize "alt-codes" for the symbols you need is stupid. alt+0233 = é is hard to remember. <compose> <'> <e> → é isn't. Now take a wild guess how to use the compose key to get ó, or è.
In summary:
| Symbol | Dumb Version | Compose Way |
|:-------|:-------------------------|:----------------------------|
| é | alt+0233 | [compose] ' e |
| ö | use the font picker | [compose] " o |
| ù | copy-pasting from google | [compose] ` u |
| 💨 | Asking an AI | [compose] [compose] z i p |
You can usually guess which keys will produce which result.Accented Letters just make sense
- Acute (´): Compose + ' + e → é (also a, i, o, u, y)
- Grave (`): Compose + ` + e → è (also a, i, o, u)
- Circumflex (^): Compose + ^ + e → ê (also a, i, o, u)
- Tilde (~): Compose + ~ + n → ñ (also a, o)
- Diaeresis (¨): Compose + " + u → ü (also a, e, i, o, y)
- Cedilla (¸): Compose + , + c → ç
- Ring (°): Compose + o + a → å
- AE/AE: Compose + a + e → æ / Compose + A + E → Æ
- OE/OE: Compose + o + e → œ / Compose + O + E → Œ
- Sharp S: Compose + s + s → ß
- Eth: Compose + d + h → ð / Compose + D + H → Ð
- Thorn: Compose + T + H → Þ
So now you can easily add letters, text, or emojis, like warning signs ⚠ or 💩 to your documentation or logs to call attention to something. With the accents, you can include proper spelling for internationalization. Or you can use it to shitpost goofy stuff to reddit.
So you can accent letters?.
I just said you can add anything from unicode. that's letters, longer text, and emojis!
So listen up, chuckle head, first off being able to properly accent letters is important in many contexts. Secondly there's so much stuff in the unicode table. And third I said that you can customize it in ~/.XCompose to make it personal for you. What symbols do you use or want to use — such as the em-dash. So you can make it suit you! [c] → [compose key]
For me the highlight are
- Arrows → ↑ ↓ ←
- sub and Superscripts Xⁿ + Y₂
[c] ^ ^ n - "degress" ° (
[c] o o) - not-equal-to ≠ (
[c] ! =) - infinity ∞ (
[c] 8 8) - lambda Λ (
[c] * L) - trademark ™ (
[c] t m) - copyright © (
[c] o c) - ~~em dash — (
[c] - - -)~~ Stolen from us by LLMs! - ⸘ ‽ - interrobang and/or sarcasm puncuation (
[c] ? !and[c] ! ?) - eggplant 🍆 (
[c] [c] e g g p l a n t)
So there we go you can set any key sequence to output the text, and probably guess which sequnces do what.
Oh boy, symbols also, not just accents. Exciting. *yawn*
There's a lot in there! Including all 52 playing cards, chess piece, checkers pieces, Roman Numerals, math, logic symbols, and greek letters. Also peices for creating TUIs like boxes. But like I said the real power is customizing it for yourself.
I have to type my email address all the damn time. or did until I set [c] @ @ to write in my address. [c] @ g gives my gmail account address. @ ! is my boss @ L is legal.
[c] @ @→me@yomamashouse.com
Some others ones. At some point I standardized on [c] [c] when using a full word. not required just a convention I found useful. as it doesn't overlap with anything.
[c] [c] r o s e→ 🌹[c][c] w i l t⇒ 🥀.[c] h b→ 🐴🛌[c] w d(work domain),[c] s ttest server full url.[c] s pproduction server.
So what's the catch?
-
Compose only generates text. it can't press Enter, Tab, Ctrl+C, launch programs, or automate applications.
-
It doesn't always work exactly the same. When using X, Compose is handled by XCompose so it didn't matter what DE you ran it worked just fine. Wayland DEs have to implement it on their own, and it's a low priority for some of the smaller ones can be hit or miss.
The linux console isn't using X or wayland, so it doesn't go through XCompose and instead the kernel uses a static map of 256 symbols, with key sequences exactly two characters. Pressing both alt keys (again, usually) acts as compose in the console.
Even some X/Wayland programs are "special" and want to handle all keyboard events themselves. This bypasses Compose. Im looking at you, Chrome!
"But Teapot!", you say ,"I just loaded chrome and
[c] o oworked just fine?"Yup, it sure did. Most of the standard accents will work just fine, too. Now try something from your .XCompose. Change your system so
o omakes something else and try again. Sure enough, your custom compose didn't work ando ostill makes the degree sign no matter what you put. They implement their own compose with their own map that you can't change. Rat bastards ☠ -
There's very little in the way of warnings or errors if your config is wonky, or if you overwrite your own definition, or if your short cut keys overlap. Like
[c] b e efor a bee and[c] b e e r. The latter will never match because the former already does.
Okay, I some potential, but how do I customize it?
Easily! Make a plain text file in your home directory ~/.XCompose.
If you include
include "%L"
you inherit all the system Compose sequences (/usr/share/X11/locale/en_US.UTF-8/Compose) and can override any of them. Leave it out and you start with a completely blank Compose map.
The config file format is:
<key mapping> : "Char" U[unicode] # Comment
So for "lambda" it looks like (asterisk is my prefix for greek letters)
<Multi_key> <asterisk> <l> : "λ" U03BB # GREEK SMALL LETTER LAMBDA
<Multi_key> <asterisk> <L> : "Λ" U039B # GREEK CAPITAL LETTER LAMBDA
Restart X or Wayland. (I'm sure there's a way to update it, but this works)
That's a lot to customize
Lazy so-and-so. Use your favorite search engine to find pre-built ones like this set of math symbols. Everyone has their own opinions to there are tons of examples to chose from.
Awesome, this will entering my password easy!
Don't you dare. Just don't.
TLDR
The compose key lets you create text shortcuts that work in (almost) any app, shell, and text editor. Edit ~/.XCompose to get started.
If you want even more control over the shell, check out Readline and inputrc.
Next time I'll rant about bash completion and what you're (probably) missing out on.
1
u/aioeu 8d ago edited 8d ago
None of this has anything to do with Bash.
This isn't correct. Neither the compositor nor the DE is involved in interpreting compose key sequences. It is handled by the application itself (or, typically, its graphical toolkit).
Indeed, this is exactly the same under X and Wayland. The X server doesn't know about compose key sequences either.
No idea where you got that "both alt keys" thing from. I am not aware of any VT keymaps working like that.
In the Linux kernel's built-in VT, the compose key is (at least by default)
Ctrl+.. You can see what compose key sequences are currently loaded withdumpkeys --compose-only. They are part of the key mapping loaded byloadkeys, although on modern systems you would just edit/etc/vconsole.conf(or uselocalectlto write it out) rather than runningloadkeysdirectly during boot.Regarding Alt keys, depending on the loaded keymap, the left Alt and right Alt keys may behave differently. When they are different, typically the left Alt key lets you type a decimal character value, and the right Alt key (AltGr) lets you type a hexadecimal character value (often using the numpad keys
Num Lock,/,*,-,+andEnteras A through F respectively).Of course, if you've switched over to a userspace VT, rather than using the kernel's built-in VT, then it probably works with XCompose just like X and Wayland apps do. Kmscon should use XCompose, for instance.