diff options
Diffstat (limited to '.local/bin/tools')
| -rwxr-xr-x | .local/bin/tools/compiler | 37 | ||||
| -rwxr-xr-x | .local/bin/tools/dmenuhandler | 15 | ||||
| -rwxr-xr-x | .local/bin/tools/dmenupass | 2 | ||||
| l--------- | .local/bin/tools/ext | 1 | ||||
| -rwxr-xr-x | .local/bin/tools/extract | 41 | ||||
| -rwxr-xr-x | .local/bin/tools/getbib | 14 | ||||
| -rwxr-xr-x | .local/bin/tools/getkeys | 4 | ||||
| -rwxr-xr-x | .local/bin/tools/ifinstalled | 3 | ||||
| -rwxr-xr-x | .local/bin/tools/linkhandler | 22 | ||||
| -rwxr-xr-x | .local/bin/tools/lmc | 42 | ||||
| -rwxr-xr-x | .local/bin/tools/opout | 11 | ||||
| -rwxr-xr-x | .local/bin/tools/pauseallmpv | 4 | ||||
| -rwxr-xr-x | .local/bin/tools/podentr | 6 | ||||
| -rwxr-xr-x | .local/bin/tools/qndl | 11 | ||||
| -rwxr-xr-x | .local/bin/tools/queueandnotify | 13 | ||||
| -rwxr-xr-x | .local/bin/tools/remaps | 10 | ||||
| -rwxr-xr-x | .local/bin/tools/rotdir | 4 | ||||
| -rwxr-xr-x | .local/bin/tools/rssadd | 9 | ||||
| -rwxr-xr-x | .local/bin/tools/setbg | 4 | ||||
| -rwxr-xr-x | .local/bin/tools/shortcuts | 26 | ||||
| -rwxr-xr-x | .local/bin/tools/texclear | 14 | ||||
| -rwxr-xr-x | .local/bin/tools/transadd | 9 | ||||
| -rwxr-xr-x | .local/bin/tools/vifmimg | 13 | ||||
| -rwxr-xr-x | .local/bin/tools/vu | 15 |
24 files changed, 330 insertions, 0 deletions
diff --git a/.local/bin/tools/compiler b/.local/bin/tools/compiler new file mode 100755 index 0000000..7d3bf1d --- /dev/null +++ b/.local/bin/tools/compiler @@ -0,0 +1,37 @@ +#!/bin/sh +# This script will compile or run another finishing operation on a document. I +# have this script run via vim. +# +# Compiles .tex. groff (.mom, .ms), .rmd, .md. +# Opens .sent files as sent presentations. +# Runs scripts based on extention or shebang + +file=$(readlink -f "$1") +dir=$(dirname "$file") +base="${file%.*}" + +cd "$dir" || exit + +textype() { \ + command="pdflatex" + ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex" + $command --output-directory="$dir" "$base" && + grep -i addbibresource "$file" >/dev/null && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" + } + +case "$file" in + *\.ms) refer -PS -e "$file" | groff -me -ms -kejpt -T pdf > "$base".pdf ;; + *\.mom) refer -PS -e "$file" | groff -mom -kejpt -T pdf > "$base".pdf ;; + *\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;; + *\.tex) textype "$file" ;; + *\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;; + *config.h) sudo make install ;; + *\.c) cc "$file" -o "$base" && "$base" ;; + *\.py) python "$file" ;; + *\.go) go run "$file" ;; + *\.sent) setsid sent "$file" 2>/dev/null & ;; + *) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; +esac diff --git a/.local/bin/tools/dmenuhandler b/.local/bin/tools/dmenuhandler new file mode 100755 index 0000000..391bdc1 --- /dev/null +++ b/.local/bin/tools/dmenuhandler @@ -0,0 +1,15 @@ +#!/bin/sh +# Feed this script a link and it will give dmenu +# some choice programs to use to open it. + +case "$(printf "copy url\\nmpv\\nmpv (loop)\\nqueue download\\n\\nqueue youtube-dl\\nfeh\\nbrowser\\nw3m\\nmpv (float)" | dmenu -i -p "Open link with what program?")" in + "copy url") echo "$1" | xclip -selection clipboard ;; + mpv) setsid mpv -quiet "$1" >/dev/null 2>&1 & ;; + "mpv (loop)") setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet --loop "$1" >/dev/null 2>&1 & ;; + "queue download") tsp curl -LO "$1" >/dev/null 2>&1 ;; + "queue youtube-dl") tsp youtube-dl --write-metadata -ic "$1" >/dev/null 2>&1 ;; + browser) setsid "$BROWSER" "$1" >/dev/null 2>&1 & ;; + feh) setsid feh "$1" >/dev/null 2>&1 & ;; + w3m) w3m "$1" >/dev/null 2>&1 ;; + "mpv (float)") setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) --geometry=+0-0 --autofit=30% --title="mpvfloat" "$1" >/dev/null 2>&1 & ;; +esac diff --git a/.local/bin/tools/dmenupass b/.local/bin/tools/dmenupass new file mode 100755 index 0000000..4fc464f --- /dev/null +++ b/.local/bin/tools/dmenupass @@ -0,0 +1,2 @@ +#!/bin/sh +dmenu -fn Monospace-18 -sb "#d79921" -sf "#1d2021" -nf "#000000" -nb "#000000" -p "$1" <&- && echo diff --git a/.local/bin/tools/ext b/.local/bin/tools/ext new file mode 120000 index 0000000..562d2b3 --- /dev/null +++ b/.local/bin/tools/ext @@ -0,0 +1 @@ +extract
\ No newline at end of file diff --git a/.local/bin/tools/extract b/.local/bin/tools/extract new file mode 100755 index 0000000..a63ab10 --- /dev/null +++ b/.local/bin/tools/extract @@ -0,0 +1,41 @@ +#!/bin/sh +# A general, all-purpose extraction script. +# +# Default behavior: Extract archive into new directory +# Behavior with `-c` option: Extract contents into current directory + +while getopts "hc" o; do case "${o}" in + c) extracthere="True" ;; + *) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit ;; +esac done + +if [ -z "$extracthere" ]; then + archive="$(readlink -f "$*")" && + directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && + mkdir -p "$directory" && + cd "$directory" || exit +else + archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)")" +fi + +[ "$archive" = "" ] && printf "Give archive to extract as argument.\\n" && exit + +if [ -f "$archive" ] ; then + case "$archive" in + *.tar.bz2|*.tar.xz|*.tbz2) tar xvjf "$archive" ;; + *.tar.gz|*.tgz) tar xvzf "$archive" ;; + *.lzma) unlzma "$archive" ;; + *.bz2) bunzip2 "$archive" ;; + *.rar) unrar x -ad "$archive" ;; + *.gz) gunzip "$archive" ;; + *.tar) tar xvf "$archive" ;; + *.zip) unzip "$archive" ;; + *.Z) uncompress "$archive" ;; + *.7z) 7z x "$archive" ;; + *.xz) unxz "$archive" ;; + *.exe) cabextract "$archive" ;; + *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; + esac +else + printf "File \"%s\" not found.\\n" "$archive" +fi diff --git a/.local/bin/tools/getbib b/.local/bin/tools/getbib new file mode 100755 index 0000000..ed441c5 --- /dev/null +++ b/.local/bin/tools/getbib @@ -0,0 +1,14 @@ +#!/bin/sh +[ -z "$1" ] && echo "Give either a pdf file or a DOI as an argument." && exit + +if [ -f "$1" ]; then + # Try to get DOI from pdfinfo or pdftotext output. + doi=$(pdfinfo "$1" | grep -io "doi:.*") || + doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) || + exit 1 +else + doi="$1" +fi + +# Check crossref.org for the bib citation. +curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n" diff --git a/.local/bin/tools/getkeys b/.local/bin/tools/getkeys new file mode 100755 index 0000000..444f4c0 --- /dev/null +++ b/.local/bin/tools/getkeys @@ -0,0 +1,4 @@ +#!/bin/sh +cat ~/.config/getkeys/"$1" 2>/dev/null && exit +echo "Run command with one of the following arguments for info about that program:" +ls ~/.config/getkeys diff --git a/.local/bin/tools/ifinstalled b/.local/bin/tools/ifinstalled new file mode 100755 index 0000000..b0d23e5 --- /dev/null +++ b/.local/bin/tools/ifinstalled @@ -0,0 +1,3 @@ +#!/bin/sh +# If $1 command is not available, error code and notify. +command -v "$1" >/dev/null || { notify-send "📦 $1" "must be installed for this function." && exit 1 ;} diff --git a/.local/bin/tools/linkhandler b/.local/bin/tools/linkhandler new file mode 100755 index 0000000..c616d04 --- /dev/null +++ b/.local/bin/tools/linkhandler @@ -0,0 +1,22 @@ +#!/bin/sh + +# Feed script a url or file location. +# If an image, it will view in sxiv, +# if a video or gif, it will view in mpv +# if a music file or pdf, it will download, +# otherwise it opens link in browser. + +# If no url given. Opens browser. For using script as $BROWSER. +[ -z "$1" ] && { "$BROWSER"; exit; } + +case "$1" in + *mkv|*webm|*mp4|*youtube.com*|*youtu.be*|*hooktube.com*|*bitchute.com*) + setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet "$1" >/dev/null 2>&1 & ;; + *png|*jpg|*jpe|*jpeg|*gif) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;; + *mp3|*flac|*opus|*mp3?source*) + setsid tsp curl -LO "$1" >/dev/null 2>&1 & ;; + *) + if [ -f "$1" ]; then "$TERMINAL" -e "$EDITOR $1" + else setsid "$BROWSER" "$1" >/dev/null 2>&1 & fi ;; +esac diff --git a/.local/bin/tools/lmc b/.local/bin/tools/lmc new file mode 100755 index 0000000..18cf2c2 --- /dev/null +++ b/.local/bin/tools/lmc @@ -0,0 +1,42 @@ +#!/bin/sh +# A general audio interface for LARBS. + +[ -z "$2" ] && num="2" || num="$2" + +case "$1" in + u*) pulsemixer --change-volume +"$num" ;; + d*) pulsemixer --change-volume -"$num" ;; + m*) pulsemixer --toggle-mute ;; + truemute) pulsemixer --mute ;; + play) mpc play ;; + n*) mpc next ;; + prev) mpc prev ;; + t*) mpc toggle ;; + p*) mpc pause ; pauseallmpv ;; + f*) mpc seek +"$num" ;; + b*) mpc seek -"$num" ;; + r*) mpc seek 0% ;; + *) cat << EOF +lmc: cli music interface for mpd and pulse for those with divine intellect too +grand to remember the mpc/pamixer commands. + +Allowed options: + up NUM Increase volume (2 secs default) + down NUM Decrease volume (2 secs default) + mute Toggle mute + truemute Mute + next Next track + prev Previous track + toggle Toggle pause + truepause Pause + foward NUM Seek foward in song (2 secs default) + back NUM Seek back in song (2 secs default) + restart Restart current song + all else Print this message + +All of these commands, except for \`truemute\`, \`prev\` and \`play\` can be truncated, +i.e. \`lmc r\` for \`lmc restart\`. +EOF +esac + +pkill -RTMIN+10 i3blocks diff --git a/.local/bin/tools/opout b/.local/bin/tools/opout new file mode 100755 index 0000000..c742aa9 --- /dev/null +++ b/.local/bin/tools/opout @@ -0,0 +1,11 @@ +#!/bin/sh +# opout: "open output": A general handler for opening a file's intended output. +# I find this useful especially running from vim. + +basename="$(echo "$1" | sed 's/\.[^\/.]*$//')" + +case "$1" in + *.tex|*.md|*.rmd|*.ms|*.me|*.mom) setsid "$READER" "$basename".pdf >/dev/null 2>&1 & ;; + *.html) setsid "$BROWSER" --new-window "$basename".html >/dev/null 2>&1 & ;; + *.sent) setsid sent "$1" >/dev/null 2>&1 & ;; +esac diff --git a/.local/bin/tools/pauseallmpv b/.local/bin/tools/pauseallmpv new file mode 100755 index 0000000..c5da220 --- /dev/null +++ b/.local/bin/tools/pauseallmpv @@ -0,0 +1,4 @@ +#!/bin/sh +for i in $(ls /tmp/mpvsoc*); do + echo '{ "command": ["set_property", "pause", true] }' | socat - $i; +done diff --git a/.local/bin/tools/podentr b/.local/bin/tools/podentr new file mode 100755 index 0000000..13ab4a8 --- /dev/null +++ b/.local/bin/tools/podentr @@ -0,0 +1,6 @@ +#!/bin/sh +# entr command to run `queueandnotify` when newsboat queue is changed + +[ "$(pgrep -x $(basename $0) | wc -l)" -gt 2 ] && exit + +echo ~/.local/share/newsboat/queue | entr -p queueandnotify 2>/dev/null diff --git a/.local/bin/tools/qndl b/.local/bin/tools/qndl new file mode 100755 index 0000000..a99d37e --- /dev/null +++ b/.local/bin/tools/qndl @@ -0,0 +1,11 @@ +#!/bin/sh +# $1 is a url; $2 is a command +[ -z "$1" ] && exit +base="$(basename "$1")" +notify-send "⏳ Queuing $base..." +cmd="$2" +[ -z "$cmd" ] && cmd="youtube-dl --add-metadata" +idnum="$(tsp $cmd "$1")" +realname="$(echo "$base" | sed "s/?\(source\|dest\).*//;s/%20/ /g")" +tsp -D "$idnum" mv "$base" "$realname" +tsp -D "$idnum" notify-send "👍 $realname done." diff --git a/.local/bin/tools/queueandnotify b/.local/bin/tools/queueandnotify new file mode 100755 index 0000000..a1417ec --- /dev/null +++ b/.local/bin/tools/queueandnotify @@ -0,0 +1,13 @@ +#!/bin/sh +# Podboat sucks. This script replaces it. +# It reads the newsboat queue, queuing downloads with taskspooler. +# It also removes the junk from extentions. +queuefile="$HOME/.local/share/newsboat/queue" + +while read -r line; do + [ -z "$line" ] && continue + url="$(echo "$line" | awk '{print $1}')" + qndl "$url" "curl -LO" +done < "$queuefile" + +echo > "$queuefile" diff --git a/.local/bin/tools/remaps b/.local/bin/tools/remaps new file mode 100755 index 0000000..df7d6c9 --- /dev/null +++ b/.local/bin/tools/remaps @@ -0,0 +1,10 @@ +#!/bin/sh +# This script is called by i3 on startup to remap keys. +# Increase key speed via a rate change +xset r rate 300 50 +# Map the caps lock key to super... +setxkbmap -option caps:super +# But when it is pressed only once, treat it as escape. +killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' +# Map the menu button to right super as well. +xmodmap -e 'keycode 135 = Super_R' diff --git a/.local/bin/tools/rotdir b/.local/bin/tools/rotdir new file mode 100755 index 0000000..e7103db --- /dev/null +++ b/.local/bin/tools/rotdir @@ -0,0 +1,4 @@ +#!/bin/sh +[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1 +base="$(basename $1)" + ls "$PWD" | awk "BEGIN { lines = \"\"; m = 0; } /^$base$/ { m = 1; } { if (!m) { if (lines) { lines = lines\"\n\"; } lines = lines\"\"\$0; } else { print \$0; } } END { print lines; }" diff --git a/.local/bin/tools/rssadd b/.local/bin/tools/rssadd new file mode 100755 index 0000000..8822fc5 --- /dev/null +++ b/.local/bin/tools/rssadd @@ -0,0 +1,9 @@ +#!/bin/sh +! echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" >/dev/null && + notify-send "That doesn't look like a full URL." && exit +RSSFILE="$HOME/.config/newsboat/urls" +if awk '{print $1}' "$RSSFILE" | grep "^$1$" >/dev/null; then + notify-send "You already have this RSS feed." +else + echo "$1" >> "$RSSFILE" && notify-send "RSS feed added." +fi diff --git a/.local/bin/tools/setbg b/.local/bin/tools/setbg new file mode 100755 index 0000000..950ae7c --- /dev/null +++ b/.local/bin/tools/setbg @@ -0,0 +1,4 @@ +#!/bin/sh +# Sets the background. If given an argument, will set file as background. +[ ! -z "$1" ] && cp "$1" ~/.config/wall.png && notify-send -i "$HOME/.config/wall.png" "Wallpaper changed." +xwallpaper --zoom ~/.config/wall.png diff --git a/.local/bin/tools/shortcuts b/.local/bin/tools/shortcuts new file mode 100755 index 0000000..1c4f278 --- /dev/null +++ b/.local/bin/tools/shortcuts @@ -0,0 +1,26 @@ +#!/bin/bash +# Output locations. Unactivated progs should go to /dev/null. +shell_shortcuts="$HOME/.config/shortcutrc" +ranger_shortcuts="/dev/null" +qute_shortcuts="/dev/null" +fish_shortcuts="/dev/null" +vifm_shortcuts="$HOME/.config/vifm/vifmshortcuts" + +# Remove, prepare files +rm -f "$ranger_shortcuts" "$qute_shortcuts" 2>/dev/null +printf "# vim: filetype=sh\\n" > "$fish_shortcuts" +printf "# vim: filetype=sh\\nalias " > "$shell_shortcuts" +printf "\" vim: filetype=vim\\n" > "$vifm_shortcuts" + +# Format the `bmdirs` file in the correct syntax and sent it to all three configs. +sed "s/\s*#.*$//;/^\s*$/d" "$HOME/.config/bmdirs" | tee >(awk '{print $1"=\"cd "$2" && ls -a\" \\"}' >> "$shell_shortcuts") \ + >(awk '{print "abbr", $1, "\"cd " $2 "; and ls -a\""}' >> "$fish_shortcuts") \ + >(awk '{print "map g" $1, ":cd", $2 "<CR>\nmap t" $1, "<tab>:cd", $2 "<CR><tab>\nmap M" $1, "<tab>:cd", $2 "<CR><tab>:mo<CR>\nmap Y" $1, "<tab>:cd", $2 "<CR><tab>:co<CR>" }' >> "$vifm_shortcuts") \ + >(awk '{print "config.bind(\";"$1"\", \"set downloads.location.directory "$2" ;; hint links download\")"}' >> "$qute_shortcuts") \ + | awk '{print "map g"$1" cd "$2"\nmap t"$1" tab_new "$2"\nmap m"$1" shell mv -v %s "$2"\nmap Y"$1" shell cp -rv %s "$2}' >> "$ranger_shortcuts" + +# Format the `configs` file in the correct syntax and sent it to both configs. +sed "s/\s*#.*$//;/^\s*$/d" "$HOME/.config/bmfiles" | tee >(awk '{print $1"=\"$EDITOR "$2"\" \\"}' >> "$shell_shortcuts") \ + >(awk '{print "abbr", $1, "\"$EDITOR "$2"\""}' >> "$fish_shortcuts") \ + >(awk '{print "map", $1, ":e", $2 "<CR>" }' >> "$vifm_shortcuts") \ + | awk '{print "map "$1" shell $EDITOR "$2}' >> "$ranger_shortcuts" diff --git a/.local/bin/tools/texclear b/.local/bin/tools/texclear new file mode 100755 index 0000000..f6a5062 --- /dev/null +++ b/.local/bin/tools/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/tools/transadd b/.local/bin/tools/transadd new file mode 100755 index 0000000..ad2ee7f --- /dev/null +++ b/.local/bin/tools/transadd @@ -0,0 +1,9 @@ +#!/bin/sh + +# Mimeapp script for adding torrent to transmission-daemon, but will also start the daemon first if not running. + +# transmission-daemon sometimes fails to take remote requests in its first moments. + +pgrep -x transmission-da || (transmission-daemon && notify-send "Starting transmission daemon..." && sleep 3 && pkill -RTMIN+7 i3blocks) + +transmission-remote -a "$@" && notify-send "🔽 Torrent added." diff --git a/.local/bin/tools/vifmimg b/.local/bin/tools/vifmimg new file mode 100755 index 0000000..1569962 --- /dev/null +++ b/.local/bin/tools/vifmimg @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +[ -z "$FIFO_UEBERZUG" ] && exit + +readonly ID_PREVIEW="preview" + +if [ "$1" = "draw" ]; then + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" [path]="${PWD}/$6") > "$FIFO_UEBERZUG" +elif [ "$1" = "videopreview" ]; then + [ ! -f "/tmp/$6.png" ] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp/$6.png" -s 0 -q 10 && + declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW" [x]="$2" [y]="$3" [max_width]="$4" [max_height]="$5" [path]="/tmp/$6.png") > "$FIFO_UEBERZUG" +else + declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") > "$FIFO_UEBERZUG" +fi diff --git a/.local/bin/tools/vu b/.local/bin/tools/vu new file mode 100755 index 0000000..778835a --- /dev/null +++ b/.local/bin/tools/vu @@ -0,0 +1,15 @@ +#!/usr/bin/env sh +export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}" + +cleanup() { + rm "$FIFO_UEBERZUG" 2>/dev/null + pkill -P $$ 2>/dev/null +} + +rm "$FIFO_UEBERZUG" 2>/dev/null +mkfifo "$FIFO_UEBERZUG" +trap cleanup EXIT +tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash & + +vifm +cleanup |
