12 ms·
Entering text in the terminal is complicated
- pixelbeat 2y agoThe vi vs emacs thing permeates a lot of tools. I find it useful to map all tools to be consistent with one or the other. Personally I use vi. Unfortunately setting vi mode for readline has a few caveats, but I was able to work around all of them with the settings in: https://www.pixelbeat.org/settings/.inputrc https://www.pixelbeat.org/settings/.inputrc
- glial 2y agoNice to see this writeup. Entering text into the terminal, and copying output out, is a huge barrier to entry for beginners. Windows terminals in particular feel downright antagonistic to use.
- kapitanjakc 2y agoFor me, Ubuntu's terminal is perfect. Give me arrows, tab, Ctrl+(R/C/D/W) etc and its a great. But I agree with the point that different systems have their own implementation which could lead to frustration. I am working on set of servers only accessible through PAM and those admins don't allow anything. It gets so frustrating. I feel a lot of the frustration also comes from shifting to unfamiliar environment. Like I work on those restricted servers and am cursing the admins, but when I switch to Ubuntu's terminal I am thanking the gods for liberation.
- frankus 2y agoPeriodic reminder that many emacs-like keybindings exist in almost every text field in macOS: Ctrl A, E, P, N, K, Y, T, and probably others I'm forgetting (start of line, end of line, previous line, next line, kill (delete everything to the end of the line and put it in a special pasteboard), yank (paste from that special pasteboard) and transpose characters). Edit: more complete list here: https://jblevins.org/log/kbd https://jblevins.org/log/kbd Edit 2: can't believe I forgot Ctrl-D, which is forward delete.
- squigz 2y agoIt took the author 15 years to learn basic readline commands?
- asciimov 2y agoTerminal feature discovery is hard. If you don't regularly use the commands it's easy to forget they exist.
- eequah9L 2y agoYeah, I have my doubts about the claim. I forgot what I read way back when as an intro book, but I suspect it was more like a month in my case, if that. But I remember having been surprised at various points that there was an undo (C-_), and a clipboard (C-y to paste) including a history (M-y). So yeah, I guess it depends on the scope. Maybe it's a hyperbole? Dunno, doesn't really read that way.
- 0cf8612b2e1e 2y agoHow can you discover something on the terminal itself? You fall into a pattern and stick with it. It is only if you get out of band information that you can learn these tricks.
- squigz 2y agoBit confused by this comment. I don't think anybody suggested you're going to find these things solely by interacting with the terminal - but rather through "out of band information" as you put it, which in GP's case, as he said, was a book. The surprising part of TFA, and replies to my comment - to me anyway - is how one can go so many years without picking up that information.
- 0cf8612b2e1e 2y agoI have never read a book about improving my terminal knowledge. I have a few tricks I have picked up over time (probably through posts like this!), but never done holistic research on the subject. Therefore, despite having used the terminal for decades, I likely have a similarly long list of basic terminal knowledge gaps. I do not know what I do not know.
- asciimov 2y agoIn bash, if you set $EDITOR to your favorite text editor, you can send the current line to $EDITOR with ctrl-x ctrl-e. After editing the command you can save and exit for the command to execute.
- cyberpunk 2y agoYou can also just press 'v' if you're using vi mode in ksh like hardened old unixbeards like me :}
- abound 2y agoAnd for the fish folk, it's Alt-e
- oalders 2y agoOr even just bind it to ctrl-e in bash: bind '\C-e: edit-and-execute-command'
- chasil 2y ago> some programs (the dash shell, cat, nc, git commit --interactive, etc) don’t support using arrow keys at all. The dash shell does in fact support an editing mode if compiled with libedit. Debian derivatives do not do so (likely for concerns of space). They very much should, as people who start with bash will have much to unlearn. The POSIX standard also specifies "set -o vi" as an optional extension. Every shell claiming POSIX-compatibility must support set -o vi if the shell implements this editing mode (so ignore inputrc if it pleases you). "[set -o] vi: Allow shell command line editing using the built-in vi editor. Enabling vi mode shall disable any other command line editing mode provided as an implementation extension." https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...
- account42 2y ago> They very much should, as people who start with bash will have much to unlearn. Dash on Debian is intended as a light POSIX sh to execute shell scripts. It isn't meant to be your login shell or for interactive use. It makes sense to keep the dependencies light in that context.
- chasil 2y agoBash can do a lot of damage to somebody who ends up needing to write POSIX shell scripts for dash. I very much disagree that dash should be prepared without something that POSIX specifically mentions. This is bad from several perspectives.
- hawski 2y agoI plan to make one day an alternative to terminals. My idea is not fully fleshed out, but I would like to try to forgo TTYs altogether. Use only pipes, file descriptors and job control. The closest thing I saw to what I have in mind is this: https://github.com/letoram/cat9/ https://github.com/letoram/cat9/ but more in a way of interface.
- hnlmorg 2y agoI’m working on a similar vision. Except instead of replacing the terminal, I’m turning it into a more of an ergonomic interface for structured data and multimedia. I’m open to discussing thoughts on this.
- cxr 2y agoOne thing to start with is to not throw the user into a screen consisting of a grid of fixed width character cells at the very beginning. This is what immediately sends a signal of discomfort to most users not already familiar with terminal emulators. There's no real reason why the default experience of having a dialog with your system installation couldn't take place within an interface that resembles iMessage or ChatGPT or something like Quicksilver. Things like /bin/rm certainly don't care whether they're being invoked from a terminal emulator that has the conventional look or whether it's in a chat-like interface—it doesn't rely on any line drawing characters or output alignment. Even the Python REPL doesn't depend on that sort of thing a great deal, except for stuff like ASCII art arrows pointing to syntax errors. Only when you want to use stuff like vi or ps and ls helpfully trying to put things into columns will you start running into trouble if your terminal emulator has an non-traditional UI. This can be ameliorated to some degree with heuristics to detect e.g. spaces being used for alignment and cursor positioning escape sequences in the output stream.
- nine_k 2y agoAre you talking about terminals, or about shells? I suppose the latter. Have you checked Oilshell, Elvish, or PowerShell (yes, on Windows)?
- ykonstant 2y agoThe utility in your link, and the entire Arcan system, seem very pleasant to me; a dream of mine is to have a complete graphical LISP command-and-control via an interface like that; like the old lisp machine UIs but with more direct incorporation and seamless handling of multimedia Objects.
- Workaccount2 2y agoI have continually contented that the terminal is the single thing eternally condemning Linux to <5% market penetration. It's not just entering text. The entire experience is complicated. It's a Concorde jet cockpit[1] (with no labels too), when 95% of the population just wants to fly their drone around[2]. [1]https://qph.cf2.quoracdn.net/main-qimg-2566f4c91b894e4169d77133c43e927f https://qph.cf2.quoracdn.net/main-qimg-2566f4c91b894e4169d77... [2]https://media.thedroningcompany.com/images/tincy/WQZpC56vqMpSMXfkpY9gKX8LfHvldqFnXSBHW1E7.png https://media.thedroningcompany.com/images/tincy/WQZpC56vqMp...
- squigz 2y ago95% of the population doesn't need to use the terminal.
- Waterluvian 2y agoIf you love cars, popping the hood is probably part of the experience. For everyone else, it’s the sign of a very frustrating day ahead. As computer lovers, I feel we must endeavour to remain mindful that almost everyone else aren’t like us. They’re trying to get a task done. They don’t want to maintain or talk with the computer.
- squigz 2y ago> As computer lovers, I feel we must endeavour to remain mindful that almost everyone else aren’t like us. They’re trying to get a task done. They don’t want to maintain or talk with the computer. This was pretty much my point. 95% of the population isn't like us, and don't need to interact with the terminal; thus, thinking the terminal is what's keeping Linux back doesn't make much sense to me
- Waterluvian 2y agoSorry if I was vague! I was commenting in complete agreement with you.
- 2y ago
- thestoicattack 2y ago> the readline keybindings come from Emacs > Because I’m a vim user, It took me a very long time to understand where these keybindings come from libreadline supports a basic vi mode. In bash, `set -o vi` lets you use vim-style editing. It is a lifesaver.
- nightpool 2y agoAlready addressed in the article
- eviks 2y ago> took me maybe 15 years of using the terminal every single day to get used to using Ctrl+A to go to the beginning of the line (or Ctrl+E for the end). And the curse of bad defaults strikes again (daily). After the realization that this is a weird default you don't train yourself for 15 years, but change it to your comfortable/common keybinds!
- jorams 2y agoI wonder what terminal that is, because the Home and End keys, which I'm pretty sure are the expected alternatives, work fine in every terminal for me on Linux.
- a1o 2y agoI have the same experience.
- cellularmitosis 2y agoI feel like you're being willfully obtuse here. I can't remember the last time I used a laptop which had Home / End keys. Edit: actually I do remember -- it was an HP ProBook from 2011.
- userbinator 2y agoI can't remember the last time I used a laptop without Home/End keys. Among them are a Dell from 2002, an IBM from 2006, another Dell from 2018, and a Lenovo from 2019. ...and here's one from 2024 that still does: https://www.storagereview.com/wp-content/uploads/2024/04/StorageReview-Dell-Latitude-9450-08.jpg https://www.storagereview.com/wp-content/uploads/2024/04/Sto...
- arp242 2y agoAlmost every (Windows) laptop has them, although they do all use their own unique (IMHO often awkward) layout.
- jorams 2y agoFor the complaint to make any sense in the first place there needs to be an expected alternative way to go back to the beginning and end of a line. Otherwise it would be "it took me maybe 15 years to get used to being able to go to the beginning or end of a line in one keystroke". The two such options I'm aware of are Home/End (on macbooks I believe that is Fn+arrow keys) and Ctrl-a/Ctrl-e. What alternative key combinations do you expect to work for the purpose?
- xg15 2y ago> First, there’s “the baseline” – what happens if a program just accepts text by calling fgets() or whatever and doing absolutely nothing else to provide a nicer experience. [...] there are actually a few features that you get for free just from your terminal, without the program needing to do anything special at all. The things you get for free are: [...] - backspace - Ctrl+W, to delete the previous word - Ctrl+U, to delete the whole line Linux noob here, so this may be a stupid question, but how does that work under the hood? The documentation for fgets() says [1]: > Reads at most count - 1 characters from the given file stream and stores them in the character array pointed to by str. Parsing stops if a newline character is found (in which case str will contain that newline character) or if end-of-file occurs. Does that mean that, by default, fgets() blocks until the user enters a newline and, before they do, it lets them edit the line buffer using the backspace, CTRL+W and CTRL+U shortcuts? But there seems to be no guarantee that a program is using fgets() to read an entire line - it could also set count to 2 and read individual characters. Those could not be "unread" anymore when a backspace occurs. Is there some magic that lets fgets() buffer characters internally in such a situation, or would the backspace/line editing functionality just be broken then? [1] https://en.cppreference.com/w/c/io/fgets https://en.cppreference.com/w/c/io/fgets
- samatman 2y agoIt's provided by the terminal (emulator) in "cooked" mode: https://en.wikipedia.org/wiki/Terminal_mode https://en.wikipedia.org/wiki/Terminal_mode raw mode doesn't do this.
- kkfx 2y agoAlso worth mention the Plan 9 "fixed prompt" where any command is at the top, with it's output underneath, there are few variants and in few cases they are comfy.
- I_complete_me 2y agoI have great respect for Julia Evans and love her contributions that get shown here. But... > "I’ve always thought that vi mode seems really cool, but for some reason even though I’m a vim user I didn’t really like using it when I tried it." Really, that seems weird to me. I use zsh (btw) and the problem she describes is a non-issue. And I am not a pro. (Sorry, Julia).
- drewg123 2y agoI don't find that strange at all (prefering emacs to vi mode). I feel the same way. I use tcsh, and have it configured for emacs-style command line editing. I use emacs for complex stuff (coding) and vi for simple stuff (editing a config file), so I'm comfy with both. I think my issue is that it seems slightly unnatural to remember the mode I'm in on a random terminal command line, and much easier to just use the emacs keys to edit when needed.
- sevg 2y agoI have to agree with the other commenter (drewg123). Been a Vim user for decades but don't use Vi-mode in the terminal. > the problem she describes is a non-issue. And I am not a pro. Not sure what you're saying here. Julia didn't describe a problem but a preference ("I didn’t really like using it"). I'm not sure how you can you call someone's preference a non-issue. It's a preference and we're allowed to have those last I checked! :p
- I_complete_me 2y ago"even though entering some text and editing it is a very “basic” task, it took me maybe 15 years of using the terminal every single day to get used to using Ctrl+A to go to the beginning of the line (or Ctrl+E for the end)." This sounded to me like she was describing a problem. My bad. And I too am allowed express opinions, no?
- sevg 2y agoIn your first comment, you said it "seems weird" that Julia doesn't like Vi-mode. In this comment, you quote Julia talking about Emacs-mode. Which doesn't really follow on from your first comment.
- vrnmh 2y agoAnother neat trick is to use ctrl-x ctrl-e, this gets the command in a vim buffer (default editor for me). Edit the command and then :wq to reflect the changes
- shmerl 2y agoThat's neat!
- hnlmorg 2y ago> some things this post left out + wide characters + different keyboard modes causing the same key press to be presented by different ANSI escape sequences + different TTY states (eg local echo) + different OSs having subtly different syscalls for changing TTY states + differing support for terminal emulation (most these days roughly emulate xterm, but even there, none aim for 100% be compatibility) + a lack of a consensus on how to check for features provided by a terminal (some use ANSI escape sequences and wait for an ansi sequence to be returned from the term (that’s how the old VTs worked), some check $TERM (that’s how the first wave of terminal emulation was detected), some terms expose themselves as xterm and ignore the VT feature sequences, but set other env vars. it’s honestly a bigger mess than the user-agent string. …and this is assuming a POSIX system. Things get doubly interesting when you throw Windows into the mix
- deleted 2y ago[deleted]
- jFriedensreich 2y agowarp and and some powershell version were the only “terminals” i used that seemed fixing the input line, but also did not quite feel right. the worst parts of terminals for me are that input line does not behave like a normal text field with mouse click, select and everything a user would expect in another context, that history mostly scrolls on a line basis instead of smooth pixel scrolling like any other document (don’t get me started on pagers, i still don't manage to disable man pages opening in some archaic mode that takes 3 tries to even exit from git), commands that default to tuis or clearing the screen. i tried to avoid unix as long as possible because of this and the absurd random / hostile folder names + layout but just because *nixes won does that mean we have to keep these archaic absurdities alive? why does even something where innovation would be simple like the vscode terminal feel like that and not like the chrome console with a normal text input line with graphic autocomplete and mostly immutable command response history with collapse/expandable sections? even unix commands that would not work in this mode could just run in something like an inline widget or new tab where they could read input lines by character or whatever weird behavior they expect.
- Asooka 2y agoIdeally we'd have the equivalent of an ipython notebook for the terminal. But GUI on Unix is still an unsolved question with more and more incompatible implementations being written daily, so I'm not holding my breath. After using Linux for over 20 years now, I've concluded that if you want a desktop OS, use Windows. If you use Linux, learn to live in the terminal - it's the only consistently working piece of the OS, everything else is consistently broken.
- phreack 2y agoI think the lowest hanging fruit would be doing something (anything) to improve discovery of commands. I have great grokking abilities but terrible memorization skills, and I end up forgetting how to do what I want to do and maybe even have done before. Browsing man pages for every command is my bane. It's also why I dislike GUI with unlabelled icons, I never remember what each one does.
- syndicatedjelly 2y agoHaven’t used it much but “apropos” is probably what you want. https://man7.org/linux/man-pages/man1/apropos.1.html https://man7.org/linux/man-pages/man1/apropos.1.html
- shadowgovt 2y agoAt this point Google has basically taken over that function... "How do I _ on the command line?" more often than not gives one some starting point to develop from.
- jryb 2y agoMaybe try fish? Tab completion will suggest subcommands, and if you type - or -- and hit tab, it will suggest the available options with help text generated from man pages (example: https://flaviocopes.com/images/fish-shell/autocomplete.png https://flaviocopes.com/images/fish-shell/autocomplete.png). Doesn't really help with positional arguments but it's definitely enhanced the discoverability of many tools for me.
- phreack 2y agoThis is by far the best practical option! Life could be even better, but out of all options this one's great.
- bongodongobob 2y agoGPT is great at this. I wrote a little program that I can call from a shell. Bashai.py show me a bash one liner that does x. It then shows me the command and asks if I want to run it with or without root. Simple, yet one of the best tools I've ever made for myself.
- shadowgovt 2y ago> license reasons, if the program’s license is not GPL-compatible – readline is GPL-licensed, not LGPL The older I get, the less patient I become with finding out some user experience sucks because of GPL / non-GPL knife fights. It's been thirty-nine years now. I think the GPL was useful at its origin, but now the benefits of open-source are proven out, the world is deeply interconnected via the Internet, and it's a hindrance to have some code burden other code with requirements. I, for one, don't expect to write any further GPL code in my lifetime. I'd rather code be maximally unencumbered from interoperation.
- mxuribe 2y ago@shadowgovt Genuine question: if i wanted to create new software nowadays, and i wished for it to be as you noted "mmaximally unencumbered from interoperation", which license should i choose for my software? Which license would you use? Again, not trying to be snarky; just wanting to learn and understand. :-)
- shadowgovt 2y agoI generally use the ISC license these days. It is short, indemnifies me from damage caused by the software I write being used by other people, has a thin requirement that the copyright be carried forward into other projects using my code (A requirement that I'm probably not going to enforce), And that's it. No encumbrances against interoperation with other people's code.
- mxuribe 2y agoToday I learned! I hadn't heard of the ISC license. I've heard of GPL, Apache, MIT, and other common ones, but not USC until now. Thanks!
- shadowgovt 2y agoThe ISC is basically pretty similar to the MIT license.
- 2y ago
- Uehreka 2y agoSo when I use Windows Terminal and I press Ctrl-C, it always does the right thing: If I’m selecting text I want to copy it, if I’m not selecting text I want to kill the running process. On Linux, every Terminal app I’ve used stubbornly refuses to copy when I press Ctrl-C, demanding I press Ctrl-Shift-C. When I paste, if I forget my manners and use Ctrl-V instead of Ctrl-Shift-V, I am punished by getting a weird character when I start typing again. And I am constantly pressing Ctrl-V because of muscle memory since no other app works this way. Is there any terminal app for Linux that does things the Windows Terminal way and won’t slap me on the wrist for Improper Teletype Usage?
- FooBarWidget 2y agoI've always configured my terminal to copy on select. I never press ctrl-c. I mean, why would I want to select text if not to copy it?
- agapon 2y agoE.g., to press Ctrl-(Shift)-V and replace the selection with something you copied (to the buffer / clipboard) earlier?
- kragen 2y agothat doesn't work in terminal emulators because the terminal emulator doesn't know how to delete the selected text in whatever program drew it there (which may no longer even exist)
- ordu 2y agoI copy from/to terminal with middle mouse button. Just select some text and click middle button where you want to paste the text. Some people don't like it because it needs a mouse, they prefer to keep their hands on the keyboard, but I don't see any issues with it. This way to copy/paste uses it's own Xorg buffer, so you can copy something with Ctrl-C and select something else, and then Ctrl-V will paste the first thing and middle click the second. I have issues using Windows and smartphones because I sometimes try to copy by just selecting things, forgetting to hit Ctrl-C or something. It is really annoying. > Is there any terminal app for Linux that does things the Windows Terminal way and won’t slap me on the wrist for Improper Teletype Usage? I think not. The trouble is programs running in terminal may want to deal with Ctrl-C by themselves. Text editors for example do that, but terminals have no way to know it. Terminals even don't know what program is running now, because job control is a job of a shell.
- helenhoward998 2y ago[dead]
- groos 2y agoWirth showed us decades ago how to do UIs using text in a modern way yet we remain firmly tied to digital analogues of teletype terminals. https://en.wikipedia.org/wiki/Oberon_(operating_system) https://en.wikipedia.org/wiki/Oberon_(operating_system)
- emmelaich 2y agoFrom which, plan9/sam/acme got it's inspiration afaik. The downside is being required to use the mouse often plus some dexterity.
- LordDragonfang 2y agoSee also the same blog's previous article, "What happens when you press a key in your terminal?" https://jvns.ca/blog/2022/07/20/pseudoterminals/ https://jvns.ca/blog/2022/07/20/pseudoterminals/ (It's a great article, and I'm fairly surprised the post doesn't directly link to it)
- inickt 2y agoLikely an unpopular take, but I switched to the "Natural text editing" preset in iTerm2 to get editing shortcuts that match the traditional macOS ones. It has the advantage of just remapping to the normal control sequences inside terminal apps, so you basically get this functionality everywhere without needed to change it in multiple places/worry about readline support/etc. It isn't perfect (I have rarely needed to enter sequences manually that then are remapped), but I find I have used way more command editing since its part of my muscle memory. https://pliszko.com/blog/post/2021-10-31-natural-text-editing-in-iterm2 https://pliszko.com/blog/post/2021-10-31-natural-text-editin...
- thiht 2y agoCame here to say this, it's one of the first things I configure when I install iTerm. Being able to naturally use cmd+arrows, opt+arrows, cmd+del or opt+del is invaluable to me. I don't want text editing in my terminal to be special.
- alganet 2y agoThis is nice. As always, Julia's articles are always a win. Here's some stuff that's missing: Within shell scripts, you can use `stty` to change a lot of stuff about the terminal, including how it deals with inputs. You can rewire all of these defaults and behaviors. Here's an experiment I did a while ago using sh and stty: https://gist.github.com/alganet/63f1dbc97b8fd35f7bb14ec30f79d2a5 https://gist.github.com/alganet/63f1dbc97b8fd35f7bb14ec30f79... It is able to capture and understand most keyboard combinations and even mouse gestures (hold/drag/drop) from within the shell in any VT100-compatible terminal (mintty, xterm, Terminal.app, vscode, so many others). Runnable demo: bash -c "$(curl -L https://git.io/fjToH)" Run it and press some keys or move the mouse. Use Ctrl+W to exit. It supports zsh and ksh too, but not dash or other shells lacking `read -rn1`. --- Here's another funny thing: `vi | cat -v` If you pipe an interactive program to `cat -v`, you can see which VT100 escapes that program is using. I learned a lot from how vi does it.
- alganet 2y agoHere's a bonus: Ever ran a command that left your terminal mangled after it finished? No output, weird chars, etc. That's lack of proper tty hygiene on the offending command. Instead of killing your terminal, type: stty sane And you'll demangle it.
- anothername12 2y agoI think the command “reset” does something similar
- alganet 2y agoYou are correct! I think it does a little more (restoring cursor if hidden, etc). If you have it, it is probably better than `stty sane`
- Biganon 2y agoAny idea what can cause the cursor to suddenly dissappear? It's the only issue I currently have with wezterm, an otherwise fantastic terminal emulator
- hi_dang_ 2y agoI thought this was going to cover RS232 implementations. Oh well, next time :-)
- 1vuio0pswjnm7 2y ago"The other day I asked what folks on Mastodon find confusing about working in the terminal, and one thing that stood out to me was "editing a command you already typed in". This really resonated with me: even though entering some text and editing it is a very "basic" task, it took me maybe 15 years of using the terminal every single day to get used to using Ctrl+A to go to the beginning of the line (or Ctrl+E for the end)." Only took me a year or so to get used to using "v" in vi mode and fc. I am not a "developer" but I prefer textmode command line to GUI. I do not use X11/Wayland/etc. I learned sh on NetBSD which I still think is one of the best shells available. It's fast. vi mode is the default. People may disagree but I think for editing single a line of text, i.e., a "command", vi mode offers more precision. For example, being able to jump directly to a particular column number. https://web.archive.org/web/20240528201424if_/https://pubs.opengroup.org/onlinepubs/9699919799/utilities/fc.html https://web.archive.org/web/20240528201424if_/https://pubs.o... #list previous commands fc -l #edit 5th command on the list fc 5 IMO, as a dumb computer user who is not a "developer", this is not complicated. I think terminal emulators are complicated, though. I do not use them. I believe fc came to POSIX from ksh. For me, it is not that UNIX is objectively good. It is that the available alternatives are still comparatively bad.
- kragen 2y agoyes, fc is from ksh going to a particular column number is not useful to me because my commands are not on punched cards with column numbers printed on them. going to a particular piece of text is, and ^r or ^s gets me there with readline (in vi mode or emacs mode). i don't want to mentally count how many characters are on the line before the place i want to go; i have a computer to do that for me vi movement by words is useful though, and slightly easier than emacs alt-f and alt-b
- imp0cat 2y ago> editing a command you already typed in It's been mentioned here before, but you should suggest the Ctrl + X, Ctrl + E combo - they can edit the command in their favourite text editor and then it gets executed when they exit the editor.
- 1vuio0pswjnm7 2y ago
- kazinator 2y agoI've never seen dash dump escape sequences instead of acting on arrow keys. Probably, it's due to a missing or wrong TERM value? Nowadays, programs should be hard-coded to accept ANSI sequences and ignore TERM (unless they need to make some fine-grained distinction like do we have 256 color xterm compatibility). Those programs will never have that problem of not understanding arrow keys.
- kragen 2y agoit's more likely because she's running a version of dash compiled without readline support, probably debian's version (which is compiled that way because it's not intended as an interactive shell, but rather the lightest-weight posix-compliant shell they could build) i agree about ansi sequences. even that doesn't go far enough, though: we should probably be moving past character-cell terminals to something better so we can have things like proportional fonts, multiple font sizes, properly spaced borders, and rounded corners
- kazinator 2y agoLooks like I'm wrong. If I fire up an interactive dash on Ubuntu or Debian, no arrow keys. /bin/sh is dash, but that's only for hash bang scripts. Not just no arrow keys, but nothing. No Ctrl-P to recall previous line. No editing beyond the POSIX TTY line discipline stuff: Ctrl-W word erase, Ctrl-U line erase, backspace.
- kragen 2y agoalso i'm wrong; it doesn't have an option to compile with readline, just libedit (which indeed is not included in the debian package configuration). the incantation was as follows: : Downloads; apt-get source dash : Downloads; cd dash-0.5.12/ : dash-0.5.12; sudo apt install libedit-dev : dash-0.5.12; ./configure --with-libedit : dash-0.5.12; make : dash-0.5.12; src/dash -E libedit supports ^r but not ^o on the other hand my dash process with libedit is 1.3 megs rss while my bash process is 7 megs rss. and the dash executable is only 130k. still, bash is only about 20% slower to start up
- kragen 2y agothe top three default readline keybindings that would improve people's lives if they knew about them: - control-w, which julia mentions in the post, to delete the last word - control-o: when you're recalling a line from history, edited or no, runs the line and recalls the following line from history. so you can run a sequence of five commands from history by navigating to the first one and hitting control-o five times - control-r: search backwards in time through your history as you type a search string. control-r again jumps to the previous hit, control-s goes back forward in time. hitting enter or control-o executes it
- dgfitz 2y agoOh I always do ctrl+shift+r for that last bit, like reverse-tabbing on a gui. Good to know about ctrl+s, though I imagine muscle memory will prevent me for ever using it. :)
- kragen 2y agonormally control-shift-r is just control-r; both key combinations send the same byte, 0x12, so they both search backwards in readline history. is your terminal emulator doing something different? if you type control-v control-shift-r enter control-d as the input to the command od -t x1a, what does it say?
- foresto 2y agoI've always wondered why control-s was chosen for this, given the obvious conflict with XOFF (pause), which in my experience is the default almost everywhere. One would have to (a) know why it wasn't working and (b) be willing to disable XOFF, in order to use that key combination for the forward history feature.
- colmmacc 2y agoOver 20 years ago now I wrote a state machine around readline that meant you could use it as a multi-line editor. Not "multi-line" as in a single line can wrap, but a true editor that lets you move up and down, but is windowless. Here's a video: https://github.com/colmmacc/jot/raw/master/jot-demo.mp4 and the CVS repository for the Unix terminal IM client it is part of is at: https://c-hey.redbrick.dcu.ie/src/c-hey_cvs_latest/ It tracks and redraws your cursor when you move up and down between lines, and also pays attention to SIGWINCH to redraw things when the terminal size changes. I've never had the time to rewrite it in Rust, but I'd like to and then release it as a small library. It's always surprised me that nobody else has done this.
- Willish42 2y agoThis was fascinating!! Please do consider bringing it back to life as a library and sharing with HN. I had no idea how much better such an editing experience is until your video, and completely agree about the benefit of not having to context-switch a la git commit "interactive mode". The "inline typewriter" effect is also really cool
- Pr0ject217 2y agoChecked out the video. Looks cool!
- jxy 2y agoYeah. That's how rio's text windows [0] look like in hold mode, except that it has a much simpler design and better support of mouse. [0] https://p9f.org/magic/man2html/1/rio https://p9f.org/magic/man2html/1/rio
- atiedebee 2y agoOh, that looks really cool! Is the current iteration of the program stable?
- marttt 2y agoThanks for the screencast. Another +1 for bringing it back to life!
- 2y ago
- cancerhacker 2y agoA meta-question for those of us very comfortable composing complex sequences on the command line: when I’m trying to help someone with something, how can I avoid becoming frustrated by their lack of facility - or worse, their lack of interest in obtaining facility, without being an ass and taking over the keyboard? Grumble.
- Sparkyte 2y agoOr you can just write a bash script file to do shortcut executions of complicated terminal commands...
- userbinator 2y agoWhenever someone brings up this subject, I'm reminded of this classic article from Linus which has appeared many times on HN: http://www.linusakesson.net/programming/tty/index.php http://www.linusakesson.net/programming/tty/index.php
- ykonstant 2y agoAlways a good read; I enjoy rereading it every time.
- larsbrinkhoff 2y agoMode ∞: shell mode in Emacs.
- Drygord 2y agoI just press and hold backspace and try again from scratch
- imp0cat 2y agoRlwrap is a great utility. rlwrap telnet ... makes life so much easier.
- willlma 2y agoI switched my Mac terminal to Warp.dev simply for the default mac text input. I can ⌥ and ⌘ left and right to select words or until the end of the line ⌘A to select all. It comes with so many other bells and whistles that I've mostly ignored for this simple convenience. I don't use emacs (or vim) keybindings in any other context and I'm not sure why the terminal forces you to.
- pama 2y agoI use M-x shell and variants in Emacs for almost all of my command line work. No problems with editing, as it is always Emacs on top. For true ncurses apps there are some limitations inside vterm or ansi term but even there, I can still use elisp and fix these problems if needed.
- account42 2y ago> it took me maybe 15 years of using the terminal every single day to get used to using Ctrl+A to go to the beginning of the line (or Ctrl+E for the end) Ctrl+LeftArrow and Ctrl+RightArrow also work with every readline-compatible shell and they are much more intuitive, especially if you are not used to terminal text editors. > it’s very inconsistent between programs Readline or emulations thereof are pretty common and the de-facto standard. But of course programs can do their own thing if they want to - it's not like GUI text eidtors all have consistent shortcuts. cat / nc / etc. are not editors at all and therefore don't provide those shortcuts. They take an input stream and forward it.
- kragen 2y agothose move by words, not to the end of the line
- kazinator 2y ago> It took me maybe 15 years of using the terminal every single day to get used to using Ctrl+A to go to the beginning of the line (or Ctrl+E for the end). That looks like some cognitive problem or ADHD. (Obviously, completely unrelated to intellect.) > some programs (cat, nc, git commit --, etc) don’t support using arrow keys at all: if you press arrow keys, you’ll just see ^[[D^[[D^[[C^[[C^ I've long argued that the readline-like functionality should be in the kernel. The POSIX line discipline should be replaced or augmented with full blown editing with history recall. Imagine rlwrap, but always there, all the time, in the TTY driver. There are downsides, because history wants to be contextual and persistent. The kernel knows what process is making the read() call on the TTY, though, so that could be somehow arranged. Certain new security issues come up also.