2 files changed,
48 insertions(+),
0 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-04-17 15:19:30 +0300
Authored at:
2026-04-17 00:00:32 +0300
Parent:
3131b20
jump to
| A | bin/time.sh |
| M | config/tmux/tmux.conf |
A
bin/time.sh
··· 1 +#!/usr/bin/env bash 2 +# hledger -f "$HOME/org/time.timeclock" balance --daily -p 'this week' 3 +# 4 +# sudo groupadd hostblock 5 +# sudo usermod -aG hostblock olex 6 +# sudo chown root:hostblock /etc/hosts 7 +# sudo chmod 664 /etc/hosts 8 + 9 +readonly TC="$HOME/org/time.timeclock" 10 +readonly CATS=$'stop\nWORK\nVIM\nWASTE' 11 +readonly BLOCKED=("news.ycombinator.com" "www.lobste.rs" "www.twitch.tv" "www.reddit.com" "www.chess.com" "www.lichess.org") # "www.youtube.com" "youtube.com" 12 + 13 +now() { date '+%Y-%m-%d %H:%M:%S'; } 14 +current() { awk '/^[io]/ { last_type=$1; last_cat=$4 } END { if (last_type == "i") print last_cat }' "$TC"; } 15 +stop_tracking() { [[ -n "$(current)" ]] && printf 'o %s\n' "$(now)" >>"$TC"; } 16 + 17 +block_sites() { 18 + for domain in "${BLOCKED[@]}"; do 19 + hostess "$1" "$domain" "::1" >/dev/null 2>&1 20 + done 21 +} 22 + 23 +update_tmux() { 24 + [[ -z "${TMUX:-}" ]] && return 25 + local curr=$(tmux show -gqv status-right 2>/dev/null || true) 26 + local clean=${curr#"#(/home/olex/bin/time.sh status)" } 27 + if [[ -n "${1:-}" ]] 28 + then tmux set -gq status-right "#($0 status)${clean:+ $clean}" 29 + else tmux set -gq status-right "$clean" 30 + fi 31 +} 32 + 33 +case "${1:-}" in 34 + status) 35 + open=$(current) 36 + [[ -n "$open" ]] && printf '%s\n' "${open#t:}" 37 + ;; 38 + ""|s) 39 + cat=$(printf '%s\n' "$CATS" | fzf) || exit 40 + [[ -z "$cat" || "$cat" == stop ]] && { stop_tracking; block_sites rm; update_tmux ""; exit; } 41 + 42 + stop_tracking 43 + printf 'i %s t:%s\n' "$(now)" "$cat" >> "$TC" 44 + [[ "$cat" == WASTE ]] && block_sites rm || block_sites add 45 + update_tmux "$cat" 46 + ;; 47 +esac
M
config/tmux/tmux.conf
··· 36 36 unbind -T copy-mode-vi MouseDragEnd1Pane 37 37 38 38 bind R source-file ~/.config/tmux/tmux.conf \; display 'Reloaded tmux config' 39 +bind e run "tmux neww ~/bin/time.sh" 39 40 unbind c; bind t new-window -c "#{pane_current_path}"; 40 41 unbind <; bind < swap-window -t -1; 41 42 unbind >; bind > swap-window -t +1;