From 75d6e605a64d2f862942afb57f1ff5668d60ae52 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 8 Oct 2021 00:05:34 +0300 Subject: bin: track bunch of scripts --- .local/bin/bukuopener | 7 +++ .local/bin/bukutagexplorer | 4 ++ .local/bin/epub_lander | 14 ++++++ .local/bin/pulse-volume-watcher.py | 48 ++++++++++++++++++ .local/bin/rfv | 14 ++++++ .local/bin/template.sh | 100 +++++++++++++++++++++++++++++++++++++ .local/bin/texclear | 14 ++++++ .local/bin/toggle_notifications.sh | 14 ++++++ .local/bin/type_clipboard.sh | 3 ++ 9 files changed, 218 insertions(+) create mode 100755 .local/bin/bukuopener create mode 100755 .local/bin/bukutagexplorer create mode 100755 .local/bin/epub_lander create mode 100755 .local/bin/pulse-volume-watcher.py create mode 100755 .local/bin/rfv create mode 100644 .local/bin/template.sh create mode 100755 .local/bin/texclear create mode 100755 .local/bin/toggle_notifications.sh create mode 100755 .local/bin/type_clipboard.sh diff --git a/.local/bin/bukuopener b/.local/bin/bukuopener new file mode 100755 index 0000000..0378810 --- /dev/null +++ b/.local/bin/bukuopener @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +url=$(buku -p -f4 | fzf -m --reverse --preview "buku --nostdin -p {1}" --preview-window=wrap | cut -f2) + +if [ -n "$url" ]; then + echo "$url" | xargs brave +fi diff --git a/.local/bin/bukutagexplorer b/.local/bin/bukutagexplorer new file mode 100755 index 0000000..8cfaba2 --- /dev/null +++ b/.local/bin/bukutagexplorer @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# TODO cannot handle tags with multiple tokens +buku -t "$(buku --np -t | fzf --reverse --preview "buku --nostdin --np -t {2}" --preview-window=wrap | awk {'print $2'})" diff --git a/.local/bin/epub_lander b/.local/bin/epub_lander new file mode 100755 index 0000000..3179649 --- /dev/null +++ b/.local/bin/epub_lander @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +mv $HOME/down/*.epub $HOME/docs/epub_landing/ + +if [[ $? -ne 1 ]]; then + notify-send "Moved some epubs" "" --app-name="epub_lander" --icon="emblem_success" +fi + +mv $HOME/down/*.pdf $HOME/docs/pdf_landing/ + +if [[ $? -ne 1 ]]; then + notify-send "Moved some pdfs" "" --app-name="epub_lander" --icon="emblem_success" +fi + diff --git a/.local/bin/pulse-volume-watcher.py b/.local/bin/pulse-volume-watcher.py new file mode 100755 index 0000000..1b0fcd5 --- /dev/null +++ b/.local/bin/pulse-volume-watcher.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +import sys + +from pulsectl import Pulse, PulseLoopStop + +with Pulse() as pulse: + + def callback(ev): + if ev.index == sink_index: + raise PulseLoopStop + + def current_status(sink): + return round(sink.volume.value_flat * 100), sink.mute == 1 + + try: + sinks = {s.index: s for s in pulse.sink_list()} + if len(sys.argv) > 1: + # Sink index from command line argument if provided + sink_index = int(sys.argv[1]) + if sink_index not in sinks: + raise KeyError(f"Sink index {sink_index} not found in list of sinks.") + else: + # Automatic determination of default sink otherwise + default_sink_name = pulse.server_info().default_sink_name + try: + sink_index = next( + index + for index, sink in sinks.items() + if sink.name == default_sink_name + ) + except StopIteration: + raise StopIteration("No default sink was found.") + + pulse.event_mask_set("sink") + pulse.event_callback_set(callback) + last_value, last_mute = current_status(sinks[sink_index]) + + while True: + pulse.event_listen() + sinks = {s.index: s for s in pulse.sink_list()} + value, mute = current_status(sinks[sink_index]) + if value != last_value or mute != last_mute: + print(str(value) + ("!" if mute else "")) + last_value, last_mute = value, mute + sys.stdout.flush() + + except Exception as e: + print(f"ERROR: {e}", file=sys.stderr) diff --git a/.local/bin/rfv b/.local/bin/rfv new file mode 100755 index 0000000..4c9a632 --- /dev/null +++ b/.local/bin/rfv @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# 1. Search for text in files using Ripgrep +# 2. Interactively narrow down the list using fzf +# 3. Open the file in Vim +IFS=: read -ra selected < <( + rg --color=always --line-number --no-heading --smart-case "${*:-}" | + fzf --ansi \ + --color "hl:-1:underline,hl+:-1:underline:reverse" \ + --delimiter : \ + --preview 'bat --color=always {1} --highlight-line {2}' \ + --preview-window='up:60%:+{2}+3/3:~3' +) +[ -n "${selected[0]}" ] && nvim "${selected[0]}" "+${selected[1]}" diff --git a/.local/bin/template.sh b/.local/bin/template.sh new file mode 100644 index 0000000..4afcb5f --- /dev/null +++ b/.local/bin/template.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +# https://betterdev.blog/minimal-safe-bash-script-template/ + +set -Eeuo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 + +trap cleanup SIGINT SIGTERM ERR EXIT + +usage() { + cat <&2 -e "${1-}" +} + +die() { + local msg=$1 + local code=${2-1} # default exit status 1 + msg "$msg" + exit "$code" +} + +parse_params() { + # default values of variables set from params + flag=0 + param='' + + while :; do + case "${1-}" in + -h | --help) + usage + ;; + -v | --verbose) + set -x + ;; + --no-color) + NO_COLOR=1 + ;; + -f | --flag) # example flag + flag=1 + ;; + -p | --param) # example named parameter + param="${2-}" + shift + ;; + -?*) + die "Unknown option: $1" + ;; + *) + break + ;; + esac + shift + done + + args=("$@") + + # check required params and arguments + [[ -z "${param-}" ]] && die "Missing required parameter: param" + [[ ${#args[@]} -eq 0 ]] && die "Missing script arguments" + + return 0 +} + +parse_params "$@" +setup_colors + +# script logic here + +msg "${RED}Read parameters:${NOCOLOR}" +msg "- flag: ${flag}" +msg "- param: ${param}" +msg "- arguments: ${args[*]-}" diff --git a/.local/bin/texclear b/.local/bin/texclear new file mode 100755 index 0000000..f6a5062 --- /dev/null +++ b/.local/bin/texclear @@ -0,0 +1,14 @@ +#!/bin/sh + +# Clears the build files of a LaTeX/XeLaTeX build. +# I have vim run this file whenever I exit a .tex file. + +case "$1" in + *.tex) + file=$(readlink -f "$1") + dir=$(dirname "$file") + base="${file%.*}" + find "$dir" -maxdepth 1 -type f -regextype gnu-awk -regex "^$base\\.(4tc|xref|tmp|pyc|pyo|fls|vrb|fdb_latexmk|bak|swp|aux|log|synctex\\(busy\\)|lof|lot|maf|idx|mtc|mtc0|nav|out|snm|toc|bcf|run\\.xml|synctex\\.gz|blg|bbl)" -delete ;; + *) printf "Give .tex file as argument.\\n" ;; +esac + diff --git a/.local/bin/toggle_notifications.sh b/.local/bin/toggle_notifications.sh new file mode 100755 index 0000000..9b700b5 --- /dev/null +++ b/.local/bin/toggle_notifications.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +TOGGLE=$HOME/.local/share/.pause_notifications + +if [ ! -e $TOGGLE ]; then + touch $TOGGLE + dunstify --appname="notifications" --icon="chronometer-pause" "pausing" -u low + sleep 3 + killall -SIGUSR1 dunst # pause +else + rm $TOGGLE + killall -SIGUSR2 dunst # resume + dunstify --appname="notifications" --icon="chronometer-start" "here's what happened" -u low +fi diff --git a/.local/bin/type_clipboard.sh b/.local/bin/type_clipboard.sh new file mode 100755 index 0000000..3e7e792 --- /dev/null +++ b/.local/bin/type_clipboard.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +xclip -selection clipboard -out | tr \\n \\r | xdotool selectwindow windowfocus type --clearmodifiers --delay 25 --window %@ --file - -- cgit v1.2.3-70-g09d2