Let the terminal bells ring out(muxup.com)
muxup.com
Let the terminal bells ring out
https://muxup.com/2023q4/let-the-terminal-bells-ring-out
35 comments
> [...] but I found it difficult to remember to put `;tput bel` on every command that would be slow [...]
What I do in these situations (assuming the job is still in the foreground, and can be interrupted), is suspend the task with ctrl+z and resume with `fg`, chaining it with some other command:
What I do in these situations (assuming the job is still in the foreground, and can be interrupted), is suspend the task with ctrl+z and resume with `fg`, chaining it with some other command:
fg; notify-send "done"
This uses the "job control" feature of `bash`, so it requires no extra setup. Your approach has the simple advantage however, that once it's set up, it just works, automatically.One of the smart things with zsh is that the hooks¹ like precmd can be replaced with arrays of functions, so that you can cleanly have multiple hooks per hook point. It even provides a nice tool to work with the the arrays too², which makes editing/enabling/disabling far easier.
It makes life far easier when you see people post useful snippets(like wolfgang42's), but don't want to have to mangle them in to your already messy monolithic function.
¹ https://zsh.sourceforge.io/Doc/Release/Functions.html#Hook-F...
² https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht...
It makes life far easier when you see people post useful snippets(like wolfgang42's), but don't want to have to mangle them in to your already messy monolithic function.
¹ https://zsh.sourceforge.io/Doc/Release/Functions.html#Hook-F...
² https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht...
How does this work without `trap` or `PROMPT_COMMAND`?
(I think PROMPT_COMMAND will take an array of functions in later versions of Bash)
(I think PROMPT_COMMAND will take an array of functions in later versions of Bash)
zsh has some special handling if you define functions with magic names: https://zsh.sourceforge.io/Doc/Release/Functions.html#Hook-F...
(I apparently knew this when I wrote the above code, since on closer inspection it doesn’t actually match the gist my comments claim it came from, but I have to admit I had since forgotten it.)
(I apparently knew this when I wrote the above code, since on closer inspection it doesn’t actually match the gist my comments claim it came from, but I have to admit I had since forgotten it.)
Right, but I was asking about Bash, where this worked unchanged on my Mac...
I do actually have something installed in my env, I think, that might trigger those functions automatically if they exist, now that I think about it...
("v" is a "view/show" function I wrote that allows me to see the definition of anything; https://github.com/pmarreck/dotfiles/blob/80a392470f8eddd70e... )
I do actually have something installed in my env, I think, that might trigger those functions automatically if they exist, now that I think about it...
bash> v PROMPT_COMMAND
PROMPT_COMMAND is an indexed array variable
declare -a PROMPT_COMMAND=([0]=$'__bp_precmd_invoke_cmd\nmcfly_prompt_command;_direnv_hook\n:' [1]="__bp_interactive_mode")
(pretty sure that this broke when I tried to force it to be a pure array instead of a 2 element array with the first as a concatenation of functions... unfortunately)("v" is a "view/show" function I wrote that allows me to see the definition of anything; https://github.com/pmarreck/dotfiles/blob/80a392470f8eddd70e... )
is it notify-send, or libnotify, or notify-desktop? (I'm on NixOS and only see the latter 2 options...)
On Ubuntu, the command `notify-send` is provided by libnotify:
$ dpkg-query -S "$(which notify-send)"
libnotify-bin: /usr/bin/notify-send
The README for https://github.com/nowrep/notify-desktop says “It's basically clone of notify-send from libnotify” so I assume that would also work, but I don’t know your system.I'd wanted a bell in the Rust Egui/Winit system. There's no simple cross-platform "beep" or bell feature, short of bringing up a whole audio system.
The original Teletype bell in a Model 15 Teletype is a 3-inch gong with a satisfying "bong" sound. That was intended to be heard across a room of noisy machines. There's also a little end of line bell for typists, but that's not loud.
The original Teletype bell in a Model 15 Teletype is a 3-inch gong with a satisfying "bong" sound. That was intended to be heard across a room of noisy machines. There's also a little end of line bell for typists, but that's not loud.
> The original Teletype bell in a Model 15 Teletype is a 3-inch gong with a satisfying "bong" sound. That was intended to be heard across a room of noisy machines. There's also a little end of line bell for typists, but that's not loud.
What would the machine do if a mischievous prankster ran a program that endlessly outputted ASCII BEL characters in a tight loop?
What would the machine do if a mischievous prankster ran a program that endlessly outputted ASCII BEL characters in a tight loop?
Ring the bell. Doesn't hurt anything. Eventually someone will turn the machine off.
The later ASCII machines don't have the big gong, just a smaller bell.
The later ASCII machines don't have the big gong, just a smaller bell.
I used to have a Model 43 Teletype. Sending a suitable number of BELs and then sleeping 4 seconds made for a convincing simulation of a ringing telephone.
> konsole: As far as I can tell it isn't supported. Creating a new profile and setting the "Terminal bell mode" to "Visual Bell" doesn't seem to result in the urgent hint being set.
However, Konsole has a way better solution for the presented problem: it has been possible to "monitor for (in)activity for a long time. It is also now possible to monitor for process termination, which you can (un)check anytime if you decide that you need to be notified.
These features are very convenient, much better than having to hack a solution using the bell in my opinion.
However, Konsole has a way better solution for the presented problem: it has been possible to "monitor for (in)activity for a long time. It is also now possible to monitor for process termination, which you can (un)check anytime if you decide that you need to be notified.
These features are very convenient, much better than having to hack a solution using the bell in my opinion.
Difference is that what the author wrote is a fair bit more portable since it doesn't require the use of a separate terminal xlient. Sure, konsole is lightweight and relatively portable, but doing it in a shell this way would work regardless of the terminal.
It is indeed way better. The only thing is it doesn't work inside "sudo -i".
> Bells ringing, chiming, or (as is appropriate for the season) jingling all sounds very noisy - but although you can configure your terminal emulator to emit a sound for the terminal bell, I'm actually advocating for configuring a non-intrusive but persistent visual notification.
So, not a bell (remember that noisy awfulness whenever you held backspace for a bit too long and it spammed useless warnings that there is nothing to delete)
> makes it easy to configure behaviour based on the duration of a command and
Glad the article was edited, it's indeed way more reasonable than having the mental overhead to add ;bell every time (though notifications have a benefit that you can add a payload that tells you which command finished and how long it took without having to switch back)
So, not a bell (remember that noisy awfulness whenever you held backspace for a bit too long and it spammed useless warnings that there is nothing to delete)
> makes it easy to configure behaviour based on the duration of a command and
Glad the article was edited, it's indeed way more reasonable than having the mental overhead to add ;bell every time (though notifications have a benefit that you can add a payload that tells you which command finished and how long it took without having to switch back)
(Article author here). I'm typically executing the same compile command from shell history (or via an alias) so missing off the `'; bell` isn't really a concern, but I agree that automatically triggering it after commands of a certain duration is a nicer way of avoiding that mental overhead if you're executing a wider variety of commands.
I thought this was going to be an article about how someone used a Raspberry Pi and some maker fu to connect 0x7 on their terminal to a cathedral or something.
If you've ever wondered why it's ctrl+g:
https://twitter.com/ViolenceWorks/status/1335382435031252992...
https://twitter.com/ViolenceWorks/status/1335382435031252992...
Can't open because twitter, but here's own explanation:
Control-a inputs byte value 1, control-b 2 and so on.
BEL is mapped to value 7 in ascii, thus C-g.
Note control-space usually does input a NUL (0) in most terminals.
Control-a inputs byte value 1, control-b 2 and so on.
BEL is mapped to value 7 in ascii, thus C-g.
Note control-space usually does input a NUL (0) in most terminals.
Another way to look at it is that Ctrl+G takes the code (ASCII) of G, i.e., 71 (binary 1000111) and toggles its 7th least significant bit to get 7 (binary 111) and indeed 7 is the code of the BEL character.
This explanation is over-simplified though. In practice, different systems have used different techniques to derive control codes from key chords. I have a more detailed article about this at https://susam.net/blog/control-escape-meta-tricks.html if anyone is interested to read it.
This explanation is over-simplified though. In practice, different systems have used different techniques to derive control codes from key chords. I have a more detailed article about this at https://susam.net/blog/control-escape-meta-tricks.html if anyone is interested to read it.
Producing ASCII control codes is why the Control code came to be and thats how it got its name:
https://en.wikipedia.org/wiki/Control_key#History
https://en.wikipedia.org/wiki/Control_key#History
This was super cool - I've always wondered why the bell character exists/why it's ctrl+G.
I still connect a piezo to the speaker port of the motherboard front panel block.
Cases don't have the speakers anymore, but boards fortunately still have the port.
It beeps nicely with BEL or with invalid input.
Cases don't have the speakers anymore, but boards fortunately still have the port.
It beeps nicely with BEL or with invalid input.
Mine does not as far as I can tell. Heres the manual:
https://dlcdnets.asus.com/pub/ASUS/mb/LGA1700/ROG_MAXIMUS_Z7...
https://dlcdnets.asus.com/pub/ASUS/mb/LGA1700/ROG_MAXIMUS_Z7...
ow.
I use BEL + IFFTT webhooks to trigger a notification on my laptop and my iPhone whenever something finishes. Echo hi; notification
With an alias for notification
With an alias for notification
The terminal bell is dead; history has killed it.
‘Wuff, Wuff!!’
Spawning a screen session by default is a good habit indeed. Especially on remote hosts when you are doing something critical.
This, except tmux.
Indeed! This is such an important part of my computing environment that I have the following in my ".*shrc":
# Attach to an existing tmux or a launch new tmux.
[ -n "$STY$TMUX$INSIDE_EMACS" ] || tmux at || tmux
Source: https://github.com/susam/dotfiles/blob/main/shrc#L381
(Based on https://gist.github.com/petethepig/2d29e8b7e2ebc808bfe760b63...)