restore legacy, include shorcut scripts
This commit is contained in:
76
dmapp/dmos/datetime-clipboard.py
Normal file
76
dmapp/dmos/datetime-clipboard.py
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Date/time clipboard utility for GNOME keyboard shortcuts.
|
||||
Copies various date/time formats to clipboard for quick pasting.
|
||||
|
||||
Usage:
|
||||
datetime-clipboard.py wd # ISO week.day (e.g., 51.2)
|
||||
datetime-clipboard.py 3t # 360-time format (0-359)
|
||||
datetime-clipboard.py uid # UUID first 8 chars
|
||||
"""
|
||||
import sys
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
|
||||
|
||||
def copy_to_clipboard(text):
|
||||
"""Copy text to clipboard using wl-copy (Wayland) or xclip (X11) as fallback."""
|
||||
try:
|
||||
# Try wl-copy first (Wayland)
|
||||
subprocess.run(['wl-copy'], input=text.encode(), check=True)
|
||||
except FileNotFoundError:
|
||||
# Fallback to xclip (X11)
|
||||
try:
|
||||
subprocess.run(['xclip', '-selection', 'clipboard'],
|
||||
input=text.encode(), check=True)
|
||||
except FileNotFoundError:
|
||||
print("Error: Neither wl-copy nor xclip found. Install wl-clipboard or xclip.",
|
||||
file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def get_weekday():
|
||||
"""ISO week.day format (e.g., 51.2)"""
|
||||
ywd = datetime.now().isocalendar()
|
||||
return f"{ywd[1]}.{ywd[2]}"
|
||||
|
||||
|
||||
def get_360time():
|
||||
"""Day divided into 360 parts (0-359)"""
|
||||
t = datetime.now()
|
||||
return str((t.hour * 60 + t.minute) // (1440 // 360))
|
||||
|
||||
|
||||
def get_uid():
|
||||
"""First 8 characters of UUID"""
|
||||
return str(uuid.uuid4())[:8]
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
format_type = sys.argv[1].lower()
|
||||
|
||||
formatters = {
|
||||
'wd': get_weekday,
|
||||
'3t': get_360time,
|
||||
'uid': get_uid,
|
||||
}
|
||||
|
||||
if format_type not in formatters:
|
||||
print(f"Unknown format: {format_type}")
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
text = formatters[format_type]()
|
||||
copy_to_clipboard(text)
|
||||
|
||||
# Optional: print to stdout for verification
|
||||
print(f"Copied to clipboard: {text}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user