dotfiles

My configuration files.
Log | Files | Refs | README

commit a64eab8875b6f0dd7e02479aacbcce6044031db3
parent a3972f188c6d0dbe58cec52d550d3ce0fb4d6f4b
Author: Sven Möller <sven-moeller@outlook.de>
Date:   Sun, 12 Dec 2021 18:01:19 +0100

Add

Diffstat:
Abin/.local/bin/bm | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/.local/bin/timelog | 8++++++++
Abin/.local/bin/urls2epub | 7+++++++
Atermux/bin/termux-url-opener | 3+++
4 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/bin/.local/bin/bm b/bin/.local/bin/bm @@ -0,0 +1,110 @@ +#!/bin/sh + +[ -z "$BM_DIR" ] \ + && echo "No directory specified!" \ + && exit 1 + +urls_file="$BM_DIR/urls.txt" +archive_file="$BM_DIR/archive.txt" + +export GIT_WORK_TREE="$BM_DIR" +export GIT_DIR="$BM_DIR/.git" + +add () { + url="$1" + cat "$urls_file" "$archive_file" | grep "$url" \ + && notify-send "Already saved!" \ + && exit + [ -z "$2" ] \ + && title="$(curl --compressed --location $url \ + | grep -Eo '<title>.*</title>' \ + | sed -E 's-</?title>--g')" \ + || title="$2" + + echo "$url $title" >> "$urls_file" + + notify-send "Bookmark added! ($title)" +} + +list () { + [ -z "$1" ] \ + && file="$urls_file" \ + || file="$1" + cat -n "$file" +} + +archive () { + url="$1" + [ -z "$2" ] \ + && from_file="$urls_file" \ + || from_file="$2" + [ -z "$3" ] \ + && to_file="$archive_file" \ + || to_file="$3" + + sed -n "${url}p" "$from_file" >> "$to_file" + delete "$url" "$from_file" +} + +delete () { + url="$1" + [ -z "$2" ] \ + && file="$urls_file" \ + || file="$2" + + sed -i "${url}d" "$file" +} + +open () { + [ -z "$2" ] \ + && file="$urls_file" \ + || file="$2" + url="$(sed -n "$1p" "$file" | awk '{print $1}')" + + xdg-open "$url" +} + +interactive () { + [ -z "$1" ] \ + && from_file="$urls_file" \ + || from_file="$1" + [ -z "$2" ] \ + && to_file="$archive_file" \ + || to_file="$2" + + line="$(list "$from_file" | fzf | awk '{print $1}')" + [ -z "$line" ] && exit + action="$(printf "open\narchive\ndelete\n" | fzf)" + [ -z "$action" ] && exit + "$action" "$line" "$from_file" "$to_file" +} + +help () { + echo "Usage: $(basename $1) COMMAND" + echo "Commands:" + cat $1 | grep -E "^\s*[a-z|]+)" | awk '{print "\t"$1"\t"$2}' +} + +[ -z "$1" ] && help "$0" && exit 1 + +case $1 in + a) archive "$2" + ;; + d|del) delete "$2" + ;; + l|list) list + ;; + la) list "$archive_file" + ;; + o|open) open "$2" + ;; + i) interactive + ;; + ia) interactive "$archive_file" "$urls_file" + ;; + add) add "$2" + ;; + git) "$@" + ;; + *) add "$1" "$2" +esac diff --git a/bin/.local/bin/timelog b/bin/.local/bin/timelog @@ -0,0 +1,8 @@ +#!/bin/sh + +file=~/documents/documents/timelog.txt +notify=termux-toast + +[ $(grep "$2" $file | sort -k 2,3 | cut -d' ' -f1 | tail -n1) = $1 ] && $notify "Fehler" && exit + +echo "$1 $(date +'%Y-%m-%d %H:%M:%S') $2" >> $file && $notify "Log" diff --git a/bin/.local/bin/urls2epub b/bin/.local/bin/urls2epub @@ -0,0 +1,7 @@ +#!/bin/sh + +while IFS= read -r line; do + url="$(echo "$line" | cut -f1 -d' ')" + hash="$(echo "$url" | sha1sum | cut -f1 -d' ')" + pandoc -o "$HOME/documents/articles/$hash.epub" "$url" +done diff --git a/termux/bin/termux-url-opener b/termux/bin/termux-url-opener @@ -0,0 +1,3 @@ +#!/bin/sh + +BM_DIR="$HOME/documents/bookmarks" "$HOME/bin/bm" "$@"