#!/bin/sh
printf 'ABC %s: ' "$(date --rfc-3339=date)" | xclip
Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
You have 404 comments
You should look into Espanso. It was made for this kind of things, and many others you didn't thought you need!
Basically, it replaces "triggers" input into strings, which can be set dynamically with short scripts.
I had been using beeftext for the longest time but it's windows only, espanso looks dope!
It is. Working great on Linux. The only pain is it has to be recompile from time to time (several months apart) on a rolling, but otherwise I had a great experience with it. It's been recommended to me on this very community, so I'm sharing the tip!
What program are you using to write or edit the comments?
Just a normal internal website. Imagine there is a comment section. You press the input box and can type within it. Then press save :)
I'd write a bookmarklet for that case:
javascript:
{
const name = 'ABC';
const d = new Date();
const year = d.getFullYear();
const month = d.getMonth();
const date = d.getDate();
document.activeElement.value = `${year}/${month}/${date} ${name}`;
void 0;
}
This bookmarklet inserts the desired text into the currently focused text box. Tested on Lemmy Web UI.
Amazing! Will fiddle around with this as a temporary fix. Wish I could mark some comments as being the 'solution' and highlight them in some way. Much appreciated!
You could write a simple python script using datetime
and pyperclip
. Datetime would supply the date format and pyperclip to copy that to your clipboard. You could setup a key binding to call the script then [Ctrl + v]
to paste.
I believe all linix distros have python installed OTB.
There are probably a bash solution but my bash is rubbish.
Edit:
The bash solution that has been provided is the best option IMO. I just thought I should provide the code for my solution so you have options. This python script is easily extendable / customizable. All this depends in you installing the python module pyperclip
. datetime
should be part if the standard python library so you dont have to install it.
installing pyperclip
with pip
.
pip install pyperclip
The script:
#!/usr/bin/env python3
"""A simple script to copy a formatted datetime string to the users clipboard"""
import datetime
import pyperclip
def clipboard_timestamp(initials) -> None:
"""Function to create a formatted timestamp string to users clipboard.
Arguments:
initials: Uses the provided string during formatting of the timestamp."""
time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
pyperclip.copy(f"{initials} {time}")
if __name__ == "__main__":
clipboard_timestamp('ABC')
The above script also adds the hours minutes and seconds to the timestamp. If not needed remove the %H:%M:%S
. Dont forget to edit anything that you want like the 'ABC'
near the end.
Save script somewhere. I usually save personal scripts to ~/.local/bin
so they are out of the way. I used the name clipboard_timestamp.py
Doesn't really matter as long as you remember the name. Next you have 2 options. You can make the script executable using chmod a+x clipboard_timestamp.py
. If you dont want to take this step you will have to tell the shortcut that python is executing the script by prefacing the script's full path with python
like so python ~/.local/bin/clipboard_timestamp.py
If you made the script executable you just use ~/.local/bin/clipboard_timestamp.py
.
I use KDE but your system should be similar-ish. in your desktop's setting's search for keyboard
and you should see something that says something like shortcuts
. Add New
-> Command or Script
. Point this to your newly saved python script /.local/bin/clipboard_timestamp.py
. Then you choose the keystroke combination.
If I were to do it, I’d do it with doom eMacs. ‘’’q i ABC SPC ESC SPC i s current-time RET’’’. Then press Q to recall macro.
Personaly I use KeepassXC autotype functionality for this kind of thing (since I'm already using it as a password manager anyway).. I have entries that are just notes and then have the autotype command be: {NOTES}{ENTER}
so it types the content of the note and presses enter.
The nice thing is that I can leverage the autotype dialogs from Keepass so I just need to remember 1 shortcut and it will open a dialog showing different Note options based on the title of the window I'm in. It also works across platforms (which is great if at work you still need to use Windows). However, Wayland is still not supported well.
I haven't tried to use date/time placeholders, but in theory, they are suported in the keepass documentation (no idea if keepassXC in particular supports them): https://keepass.info/help/base/placeholders.html (check out the {CMD:/CommandLine/Options/}
placeholder that lets you run arbitrary commands and optionally have their output replace the placeholder, which is very powerful)
In the auto-type docs they also have placeholders that even allow you to add delays, switch active windows, and press all kind of key combinations. Again, I've not tested if all of that works in KeepassXC but if not you can always use the official keepass app.