From 794b05103d5e742df6b45dd738cc34689c2e93a7 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 1 Aug 2023 09:31:42 +0200 Subject: [PATCH 01/16] bib2html.py: Add umlaut replacement --- bib2html.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bib2html.py b/bib2html.py index dee284e..5d5b4db 100755 --- a/bib2html.py +++ b/bib2html.py @@ -37,7 +37,25 @@ import os, sys, getopt, re def format_latex(text): # Get rid of matching dollar signs text = re.sub(r'\$([^\$]*)\$', r'\1', text) - return text.replace('\mathcal', '').replace('{', '').replace('}', '').replace('\\', '').replace('~', ' ').replace('--', '–') + + # Replace text + subst = { + '\\"a': 'ä', + '\\"o': 'ö', + '\\"u': 'u', + '\mathcal': '', + '{': '', + '}': '', + '\\': '', + '~': ' ', + '---': '–', + '--': '–', + } + + for a, b in subst.items(): + text = text.replace(a, b) + + return text def format_field_span(type, value): return "" + format_latex(value) + "" -- 2.39.5 From d4d771618824ada5d34f22031e3748de27cd68b5 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Thu, 3 Aug 2023 21:15:29 +0200 Subject: [PATCH 02/16] bib2html.py: Make use of date field --- bib2html.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bib2html.py b/bib2html.py index 5d5b4db..a595f42 100755 --- a/bib2html.py +++ b/bib2html.py @@ -32,6 +32,7 @@ __license__ = "MIT" import os, sys, getopt, re +import dateutil.parser def format_latex(text): @@ -159,6 +160,9 @@ def format_entry(entry): def entryDateSortKey(p): k, e = p + if 'date' in e.fields: + return e.fields['date'] + month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \ 'apr' : '04', 'may' : '05', 'jun' : '06', \ 'jul' : '07', 'aug' : '08', 'sep' : '09', \ @@ -176,6 +180,17 @@ def entryDateSortKey(p): return e.fields['year'] + "-" + month +def entryGetYear(e): + if 'year' in e.fields: + return e.fields['year'] + + if 'date' in e.fields: + dt = dateutil.parser.isoparse(e.fields['date']) + return str(dt.year) + + return None + + def usage(): """Print usage text of this program""" @@ -222,7 +237,7 @@ if __name__ == "__main__": bib_data = parser.parse_file(bibfile) entries = bib_data.entries - years = list(set([ b.fields['year'] for b in entries.values() ])) + years = list(set([entryGetYear(e) for e in entries.values()])) years.sort(reverse=True) for year in years: @@ -233,7 +248,7 @@ if __name__ == "__main__": iteritems.sort(key=entryDateSortKey, reverse=True) for key, entry in iteritems: - if entry.fields['year'] != year: + if entryGetYear(entry) != year: continue print("
") -- 2.39.5 From ad936fd7ae65ffc642d2727c7a1e0c9cd8630942 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Thu, 3 Aug 2023 21:16:47 +0200 Subject: [PATCH 03/16] bib2html.py: Print entry type --- bib2html.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bib2html.py b/bib2html.py index a595f42..309b6c4 100755 --- a/bib2html.py +++ b/bib2html.py @@ -252,10 +252,8 @@ if __name__ == "__main__": continue print("
") - print("[" + key + "]
") - + print("[{}]
{}
".format(key, key, entry.type)) e = format_entry(entry) print(e) print("
\n") - -- 2.39.5 From 9b52797ddadf989219c0f1677ee4f403a1e31030 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Thu, 3 Aug 2023 21:17:05 +0200 Subject: [PATCH 04/16] bib2html.py: Add support for patents --- bib2html.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bib2html.py b/bib2html.py index 309b6c4..b1ba761 100755 --- a/bib2html.py +++ b/bib2html.py @@ -124,6 +124,16 @@ def format_details_book(entry): line = filter(lambda l: l != "", line) return [", ".join(line)] +def format_details_patent(entry): + line = [] + line.append(format_field(entry, 'number', pre='Pat. ')) + line.append(format_field(entry, 'month', post=' ') + \ + format_field(entry, 'year')) + line.append(format_field(entry, 'note')) + + line = filter(lambda l: l != "", line) + return [", ".join(line)] + def format_links(entry): doi = format_field(entry, 'doi', pre='[DOI]') webpdf = format_field(entry, 'webpdf', pre='[PDF]') @@ -145,6 +155,8 @@ def format_entry(entry): lines.extend(format_details_inproceedings(entry)) elif entry.type=='book': lines.extend(format_details_book(entry)) + elif entry.type=='patent': + lines.extend(format_details_patent(entry)) elif entry.type in ['mastersthesis', 'phdthesis']: lines.extend(format_details_thesis(entry)) else: -- 2.39.5 From 336c7c24f3e51c309450450fc2e1304960a14a09 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 17 Dec 2023 10:27:11 +0100 Subject: [PATCH 05/16] X: Add xrandr scripts --- X/xrandr-exttomirror | 19 +++++++++++++++++++ X/xrandr-exttoright | 19 +++++++++++++++++++ X/xrandr-single | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100755 X/xrandr-exttomirror create mode 100755 X/xrandr-exttoright create mode 100755 X/xrandr-single diff --git a/X/xrandr-exttomirror b/X/xrandr-exttomirror new file mode 100755 index 0000000..4f1d3ec --- /dev/null +++ b/X/xrandr-exttomirror @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +MAIN=$(xrandr | grep eDP | cut -f1 -d" ") +if [ "${MAIN}" = "" ]; then + echo "Could not find main display." + exit 1 +fi + +OTHER=$(xrandr | grep "\" | grep -v eDP | cut -f1 -d" ") +if [ "${OTHER}" = "" ]; then + echo "Could not find external display." + exit 1 +fi + +echo "Set ${MAIN} as mirror of ${OTHER}" + +xrandr --output ${OTHER} --auto --output ${MAIN} --same-as ${OTHER} --primary diff --git a/X/xrandr-exttoright b/X/xrandr-exttoright new file mode 100755 index 0000000..fca0aa6 --- /dev/null +++ b/X/xrandr-exttoright @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +MAIN=$(xrandr | grep eDP | cut -f1 -d" ") +if [ "${MAIN}" = "" ]; then + echo "Could not find main display." + exit 1 +fi + +OTHER=$(xrandr | grep "\" | grep -v eDP | cut -f1 -d" ") +if [ "${OTHER}" = "" ]; then + echo "Could not find external display." + exit 1 +fi + +echo "Bring ${OTHER} right of ${MAIN}" + +xrandr --output ${MAIN} --auto --primary; xrandr --output ${OTHER} --auto; xrandr --output ${OTHER} --auto --right-of ${MAIN} diff --git a/X/xrandr-single b/X/xrandr-single new file mode 100755 index 0000000..174a0df --- /dev/null +++ b/X/xrandr-single @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e + +MAIN=$(xrandr | grep eDP | cut -f1 -d" ") +if [ "${MAIN}" = "" ]; then + echo "Could not find main display." + exit 1 +fi + +echo "Set ${MAIN} as primary" +xrandr --output ${MAIN} --auto --primary + +OTHER=$(xrandr | grep "\" | grep -v eDP | cut -f1 -d" ") +if [ "${OTHER}" = "" ]; then + echo "Could not find external display." + exit 1 +fi + +echo "Set ${OTHER} off" +xrandr --output ${OTHER} --off -- 2.39.5 From 11459be7250882eb3328215ec4b200b68dc82077 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 17 Dec 2023 20:25:55 +0100 Subject: [PATCH 06/16] udev: Add xprofile-udevinput-monitor --- udev/input/install.sh | 10 ++++++++++ udev/input/xprofile-udevinput | 7 +++++++ udev/input/xprofile-udevinput-monitor | 10 ++++++++++ udev/input/xprofile-udevinput-monitor.service | 12 ++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 udev/input/install.sh create mode 100755 udev/input/xprofile-udevinput create mode 100755 udev/input/xprofile-udevinput-monitor create mode 100644 udev/input/xprofile-udevinput-monitor.service diff --git a/udev/input/install.sh b/udev/input/install.sh new file mode 100644 index 0000000..59b4c22 --- /dev/null +++ b/udev/input/install.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +cp ./xprofile-udevinput ~/.xprofile-udevinput +echo "You may source ~/.xprofile-udevinput in your ~/.xinitrc or so" + +cp ./xprofile-udevinput-monitor ~/.local/bin/ +cp ./xprofile-udevinput-monitor.service ~/.config/systemd/user/ +systemctl --user daemon-reload + +echo "You may call systemctl --user enable xprofile-udevinput-monitor.service" diff --git a/udev/input/xprofile-udevinput b/udev/input/xprofile-udevinput new file mode 100755 index 0000000..9664326 --- /dev/null +++ b/udev/input/xprofile-udevinput @@ -0,0 +1,7 @@ +#!bin/sh +# Load this script whenever a USB keyboard is attached + +xset r rate 200 60 + +# Barrier needs this on client and server side +setxkbmap -device `xinput list --id-only "Virtual core XTEST keyboard"` de diff --git a/udev/input/xprofile-udevinput-monitor b/udev/input/xprofile-udevinput-monitor new file mode 100755 index 0000000..e48d1ac --- /dev/null +++ b/udev/input/xprofile-udevinput-monitor @@ -0,0 +1,10 @@ +#!/bin/sh + +set -e + +# For each add-event of input subsystem by udev call ~/.xprofile-keyboard +udevadm monitor -u -s input | grep --line-buffered add | while read line; do + echo ">> $line"; + sh ~/.xprofile-udevinput +done + diff --git a/udev/input/xprofile-udevinput-monitor.service b/udev/input/xprofile-udevinput-monitor.service new file mode 100644 index 0000000..09725fb --- /dev/null +++ b/udev/input/xprofile-udevinput-monitor.service @@ -0,0 +1,12 @@ +[Unit] +Description=xprofile-udevinput-monitor daemon +After=multi-user.target + +[Service] +Environment=DISPLAY=:0 +ExecStart=%h/.local/bin/xprofile-udevinput-monitor +Restart=always +RestartSec=10min + +[Install] +WantedBy=default.target -- 2.39.5 From 9afcdc46f956e1b87f65b5016cd2f7034a1ced36 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 17 Dec 2023 21:08:46 +0100 Subject: [PATCH 07/16] udev: Little update --- udev/input/xprofile-udevinput-monitor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/udev/input/xprofile-udevinput-monitor b/udev/input/xprofile-udevinput-monitor index e48d1ac..d9204ad 100755 --- a/udev/input/xprofile-udevinput-monitor +++ b/udev/input/xprofile-udevinput-monitor @@ -4,7 +4,7 @@ set -e # For each add-event of input subsystem by udev call ~/.xprofile-keyboard udevadm monitor -u -s input | grep --line-buffered add | while read line; do - echo ">> $line"; + echo ">> $line" sh ~/.xprofile-udevinput done -- 2.39.5 From e7229e669cf3a00180478c57ad60ba07019e670c Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sat, 30 Dec 2023 09:52:31 +0100 Subject: [PATCH 08/16] xsession-daemon: More robust proc detection Test for running process with given PID was instable. Replace with pid-file feature of pgrep. --- xsession-daemon | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/xsession-daemon b/xsession-daemon index f7edb63..247c903 100755 --- a/xsession-daemon +++ b/xsession-daemon @@ -22,33 +22,29 @@ PIDDIR="${PIDFILE%/*}" LOGDIR="${LOGFILE%/*}" mkdir -p $PIDDIR -if [ $? -ne 0 ]; -then +if [ $? -ne 0 ]; then echo "Session daemon PIDDIR not there: $PIDDIR" >&2 exit 2 fi mkdir -p $LOGDIR -if [ $? -ne 0 ]; -then +if [ $? -ne 0 ]; then echo "Session daemon LOGDIR not there: $LOGDIR" >&2 exit 2 fi -if [ -e "$PIDFILE" ] ; -then - echo "Session daemon '$NAME' PIDFILE found: $PIDFILE" - PID=`cat "$PIDFILE"` +if [ -e "$PIDFILE" ] ; then + PID=`cat "$PIDFILE"` echo "Session daemon '$NAME' PID found: $PID" + + if pgrep -F "$PIDFILE" "${NAME}" >/dev/null ; then + echo "Session daemon '$NAME' was already running with PID $PID" >&2 + exit 3 + fi else echo "Session daemon '$NAME' PIDFILE NOT found: $PIDFILE" fi -if [ "$PID" ] && kill -0 "$PID" 2>/dev/null ; -then - echo "Session daemon '$NAME' was already running with PID $PID" >&2 - exit 3 -fi echo "Session daemon running $COMMAND $* > $LOGFILE 2>&1" $COMMAND $* > "$LOGFILE" 2>&1 & @@ -56,8 +52,7 @@ PID=$! ERR=$? sleep 1 -if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev/null; -then +if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev/null; then echo -n $PID > "$PIDFILE" echo "Session daemon '$NAME' started with PID $PID" else -- 2.39.5 From f522c7a926a5e7e0b8c7270fda156ba9756be362 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 26 Feb 2024 14:10:00 +0100 Subject: [PATCH 09/16] bib2html.py: Add incollection bibtype --- bib2html.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bib2html.py b/bib2html.py index b1ba761..7557cce 100755 --- a/bib2html.py +++ b/bib2html.py @@ -103,6 +103,21 @@ def format_details_inproceedings(entry): line = filter(lambda l: l != "", line) return [where, ", ".join(line)] +def format_details_incollection(entry): + where = format_field(entry, 'booktitle') + + line = [] + line.append(format_field(entry, 'publisher')) + line.append(format_field(entry, 'pages', pre='pp. ')) + line.append(format_field(entry, 'address')) + line.append(format_field(entry, 'month', post=' ') + \ + format_field(entry, 'year')) + line.append(format_field(entry, 'isbn', pre='ISBN ')) + line.append(format_field(entry, 'note')) + + line = filter(lambda l: l != "", line) + return [where, ", ".join(line)] + def format_details_thesis(entry): line = [] line.append(format_field(entry, 'school')) @@ -153,6 +168,8 @@ def format_entry(entry): lines.extend(format_details_article(entry)) elif entry.type=='inproceedings': lines.extend(format_details_inproceedings(entry)) + elif entry.type=='incollection': + lines.extend(format_details_incollection(entry)) elif entry.type=='book': lines.extend(format_details_book(entry)) elif entry.type=='patent': -- 2.39.5 From d7b49a5434e2001d5e04ab8d9ea290982933d037 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 18 Jun 2024 12:48:53 +0200 Subject: [PATCH 10/16] Fix escaping --- bib2html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bib2html.py b/bib2html.py index 7557cce..7a1b7d9 100755 --- a/bib2html.py +++ b/bib2html.py @@ -44,7 +44,7 @@ def format_latex(text): '\\"a': 'ä', '\\"o': 'ö', '\\"u': 'u', - '\mathcal': '', + '\\mathcal': '', '{': '', '}': '', '\\': '', -- 2.39.5 From 8ac4a1dca2f3649a4c2840d5dc8fc561590da2f8 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Fri, 26 Jul 2024 09:27:39 +0200 Subject: [PATCH 11/16] tmux: Fire dragon on double click --- dotfiles/tmux/.tmux.conf | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/dotfiles/tmux/.tmux.conf b/dotfiles/tmux/.tmux.conf index 69be6d4..d6c5773 100644 --- a/dotfiles/tmux/.tmux.conf +++ b/dotfiles/tmux/.tmux.conf @@ -8,16 +8,23 @@ set-window-option -g xterm-keys on # Pass escape immediately to vim set -sg escape-time 0 +# Default word-separators are: "!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~" +# Remove some characters to have sane {mouse_word} on filenames +set-window-option -g word-separators "!\"#$%&'()*+,:;<=>?@[\\]^`{|}~" + # Copy to X11 clipboard -bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' +bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' + +# Fire drag&drop for files +bind-key -n DoubleClick1Pane run-shell -c '#{pane_current_path}' "dragon -x '#{mouse_word}'" -bind-key m set-option -g mouse on \; display 'Mouse: ON' -bind-key M set-option -g mouse off \; display 'Mouse: OFF' +bind-key m "set-option -g mouse on \; display 'Mouse: ON'" +bind-key M "set-option -g mouse off \; display 'Mouse: OFF'" # Let split et alii use the pane's current path as current path of the new pane -bind '"' split-window -c "#{pane_current_path}" -bind % split-window -h -c "#{pane_current_path}" -bind c new-window -c "#{pane_current_path}" +bind-key '"' split-window -c "#{pane_current_path}" +bind-key % split-window -h -c "#{pane_current_path}" +bind-key c new-window -c "#{pane_current_path}" # Pass home and end keys bind-key -n Home send Escape "OH" -- 2.39.5 From 8e48749fb15c8fb371aeb2fed73adbdff33688f6 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 26 Aug 2024 09:32:13 +0200 Subject: [PATCH 12/16] tmux: Set mode-keys vi --- dotfiles/tmux/.tmux.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotfiles/tmux/.tmux.conf b/dotfiles/tmux/.tmux.conf index d6c5773..78ac6ed 100644 --- a/dotfiles/tmux/.tmux.conf +++ b/dotfiles/tmux/.tmux.conf @@ -3,6 +3,8 @@ set -g default-terminal "xterm-256color" set -g mouse on +setw -g mode-keys vi + set-window-option -g xterm-keys on # Pass escape immediately to vim -- 2.39.5 From 7747158a770d8c006dab5dcc0d2c9a9fd13c80fc Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Tue, 3 Sep 2024 09:47:24 +0200 Subject: [PATCH 13/16] bib2html.py: Use journaltitle --- bib2html.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bib2html.py b/bib2html.py index 7a1b7d9..ae64a1c 100755 --- a/bib2html.py +++ b/bib2html.py @@ -76,7 +76,9 @@ def format_authors(entry): def format_details_article(entry): - where = format_field(entry, 'journal') + where = format_field(entry, 'journaltitle') + if where == "": + where = format_field(entry, 'journal') line = [] line.append(format_field(entry, 'pages', pre='pp. ')) -- 2.39.5 From 9330d0c3dc644b6d891a536e62f4786b3afa224a Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sun, 10 Nov 2024 16:04:05 +0100 Subject: [PATCH 14/16] systemd: Add batter script to system-sleep --- systemd/usr/lib/systemd/system-sleep/battery | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 systemd/usr/lib/systemd/system-sleep/battery diff --git a/systemd/usr/lib/systemd/system-sleep/battery b/systemd/usr/lib/systemd/system-sleep/battery new file mode 100755 index 0000000..8730371 --- /dev/null +++ b/systemd/usr/lib/systemd/system-sleep/battery @@ -0,0 +1,24 @@ +#!/bin/sh +# Stefan Huber, 2024-11-10 + +acpi=$(acpi) +date=$(date -Iseconds --utc) +addendum="" + +if [ "$1" = "post" ]; then + lastpre=$(grep pre /var/log/batterstat.log | tail -n1) + + if [ ! -z "${lastpre}" ]; then + preprecent=$(echo "${lastpre}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }') + predate=$(echo "${lastpre}" | grep -o " at .*" | awk '{ print $2 }') + + postpercent=$(echo "${acpi}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }') + + let diffmin=($(date +%s -d ${date})-$(date +%s -d ${predate}))/60 + let diffperc=(prepercent-postprecent) + + addendum=", discharged ${diffperc}% (${preprecent}% -> ${postpercent}%) in ${diffmin} minutes" + fi +fi + +echo "$1: ${acpi} at ${date}${addendum}" >> /var/log/batterstat.log -- 2.39.5 From c0525d6944bc8e8d33964ccd32215ac5cc31c80d Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 11 Nov 2024 17:37:24 +0100 Subject: [PATCH 15/16] systemd: Fix battery script --- systemd/usr/lib/systemd/system-sleep/battery | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/systemd/usr/lib/systemd/system-sleep/battery b/systemd/usr/lib/systemd/system-sleep/battery index 8730371..17cdf3e 100755 --- a/systemd/usr/lib/systemd/system-sleep/battery +++ b/systemd/usr/lib/systemd/system-sleep/battery @@ -3,22 +3,22 @@ acpi=$(acpi) date=$(date -Iseconds --utc) -addendum="" +addendum="." if [ "$1" = "post" ]; then lastpre=$(grep pre /var/log/batterstat.log | tail -n1) if [ ! -z "${lastpre}" ]; then - preprecent=$(echo "${lastpre}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }') - predate=$(echo "${lastpre}" | grep -o " at .*" | awk '{ print $2 }') + prepercent=$(echo "${lastpre}" | grep -o "[0-9]*%" | cut -f1 -d%) + predate=$(echo "${lastpre}" | awk '{ print $1 }') - postpercent=$(echo "${acpi}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }') + postpercent=$(echo "${acpi}" | grep -o "[0-9]*%" | cut -f1 -d%) let diffmin=($(date +%s -d ${date})-$(date +%s -d ${predate}))/60 - let diffperc=(prepercent-postprecent) + let diffperc=(prepercent-postpercent) - addendum=", discharged ${diffperc}% (${preprecent}% -> ${postpercent}%) in ${diffmin} minutes" + addendum="${addendum} Discharged ${diffperc}% (${prepercent}% -> ${postpercent}%) in ${diffmin} minutes." fi fi -echo "$1: ${acpi} at ${date}${addendum}" >> /var/log/batterstat.log +echo "${date} $1: ${acpi}${addendum}" >> /var/log/batterstat.log -- 2.39.5 From d07da7106c44babb0eeeff00057fb9ccc113d986 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Wed, 13 Nov 2024 08:55:35 +0100 Subject: [PATCH 16/16] systemd: Adding days to battery log --- systemd/usr/lib/systemd/system-sleep/battery | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/systemd/usr/lib/systemd/system-sleep/battery b/systemd/usr/lib/systemd/system-sleep/battery index 17cdf3e..778bbd6 100755 --- a/systemd/usr/lib/systemd/system-sleep/battery +++ b/systemd/usr/lib/systemd/system-sleep/battery @@ -14,10 +14,13 @@ if [ "$1" = "post" ]; then postpercent=$(echo "${acpi}" | grep -o "[0-9]*%" | cut -f1 -d%) - let diffmin=($(date +%s -d ${date})-$(date +%s -d ${predate}))/60 + let diffsecs=($(date +%s -d ${date})-$(date +%s -d ${predate})) let diffperc=(prepercent-postpercent) - addendum="${addendum} Discharged ${diffperc}% (${prepercent}% -> ${postpercent}%) in ${diffmin} minutes." + days=$(date -u -d @${diffsecs} +'%j') + let days=($days-1) + + addendum="${addendum} Discharged ${diffperc}% (${prepercent}% -> ${postpercent}%) in time ${days} days $(date -u -d @${diffsecs} +'%T')." fi fi -- 2.39.5