summaryrefslogtreecommitdiffstats
path: root/.scripts/tools
diff options
context:
space:
mode:
Diffstat (limited to '.scripts/tools')
-rwxr-xr-x.scripts/tools/compiler49
-rwxr-xr-x.scripts/tools/dmenuhandler14
l---------.scripts/tools/ext1
-rwxr-xr-x.scripts/tools/extract41
-rwxr-xr-x.scripts/tools/getbib15
-rwxr-xr-x.scripts/tools/getkeys5
-rwxr-xr-x.scripts/tools/linkhandler25
-rwxr-xr-x.scripts/tools/lmc43
-rwxr-xr-x.scripts/tools/note7
-rwxr-xr-x.scripts/tools/opout11
-rwxr-xr-x.scripts/tools/pauseallmpv4
-rwxr-xr-x.scripts/tools/remaps19
-rwxr-xr-x.scripts/tools/shortcuts38
-rwxr-xr-x.scripts/tools/speedvid7
-rwxr-xr-x.scripts/tools/texclear12
-rwxr-xr-x.scripts/tools/tpb169
-rwxr-xr-x.scripts/tools/transadd12
17 files changed, 472 insertions, 0 deletions
diff --git a/.scripts/tools/compiler b/.scripts/tools/compiler
new file mode 100755
index 0000000..53d6768
--- /dev/null
+++ b/.scripts/tools/compiler
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# This script will compile or run another finishing operation on a document. I
+# have this script run via vim.
+#
+# tex files: Compiles to pdf, including bibliography if necessary
+# md files: Compiles to pdf via pandoc
+# rmd files: Compiles via R Markdown
+# c files: Compiles via whatever compiler is set to cc. Usually gcc.
+# py files: runs via python command
+# go files: compiles and runs with "go run"
+# config.h files: (For suckless utils) recompiles and installs program.
+# all others: run `sent` to show a presentation
+
+file=$(readlink -f "$1")
+dir=$(dirname "$file")
+base="${file%.*}"
+shebang=$(sed -n 1p "$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"
+ }
+
+shebangtest() {
+ case "$shebang" in
+ \#\!*) "$file" ;;
+ *) sent "$file" 2>/dev/null & ;;
+ esac
+}
+
+case "$file" in
+ *\.ms) refer -PS -e "$file" | groff -me -ms -kejpt -T pdf > "$base".pdf ;;
+ *\.rmd) echo "require(rmarkdown); render('$file')" | R --vanilla ;;
+ *\.tex) textype "$file" ;;
+ *\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
+ *config.h) make && sudo make install ;;
+ *\.c) cc "$file" -o "$base" && "$base" ;;
+ *\.py) python "$file" ;;
+ *\.go) go run "$file" ;;
+ *) shebangtest ;;
+esac
diff --git a/.scripts/tools/dmenuhandler b/.scripts/tools/dmenuhandler
new file mode 100755
index 0000000..2a3bc0b
--- /dev/null
+++ b/.scripts/tools/dmenuhandler
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Feed this script a link and it will give dmenu
+# some choice programs to use to open it.
+
+x=$(printf "mpv\\nmpv (loop)\\nwget\\nfeh\\nbrowser\\nw3m\\nmpv (float)" | dmenu -i -p "Open link with what program?")
+case "$x" in
+ mpv) setsid mpv -quiet "$1" >/dev/null 2>&1 & ;;
+ "mpv (loop)") setsid mpv -quiet --loop "$1" >/dev/null 2>&1 & ;;
+ wget) wget "$1" >/dev/null 2>&1 ;;
+ browser) setsid "$TRUEBROWSER" "$1" & ;;
+ feh) setsid feh "$1" >/dev/null 2>&1 & ;;
+ w3m) w3m "$1" >/dev/null 2>&1 ;;
+ "mpv (float)") setsid mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$1" >/dev/null 2>&1 & ;;
+esac
diff --git a/.scripts/tools/ext b/.scripts/tools/ext
new file mode 120000
index 0000000..562d2b3
--- /dev/null
+++ b/.scripts/tools/ext
@@ -0,0 +1 @@
+extract \ No newline at end of file
diff --git a/.scripts/tools/extract b/.scripts/tools/extract
new file mode 100755
index 0000000..c214583
--- /dev/null
+++ b/.scripts/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=${archive%.*} &&
+ 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/.scripts/tools/getbib b/.scripts/tools/getbib
new file mode 100755
index 0000000..0ea30d3
--- /dev/null
+++ b/.scripts/tools/getbib
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+# Give this script a .pdf and it will attempt
+# to return a proper .bib citation via doi.
+# Internet connection required.
+
+# Get the doi from metadata, if not possible, get
+# doi from pdftotext output, if not possible, exit.
+doi=$(pdfinfo "$1" | grep -o doi:.*) ||
+ doi=$(pdftotext "$1" - | grep -o doi.* -m 1) ||
+ exit 1
+
+# Check crossref.org for the bib citation.
+curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\n" |
+ sed -e "/^[^\(\t\|@\|}\)]/d"
diff --git a/.scripts/tools/getkeys b/.scripts/tools/getkeys
new file mode 100755
index 0000000..928e435
--- /dev/null
+++ b/.scripts/tools/getkeys
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+cat ~/.scripts/.getkeys/"$1" 2>/dev/null && exit
+echo Run command with one of the following arguments for info about that program:
+ls ~/.scripts/.getkeys
diff --git a/.scripts/tools/linkhandler b/.scripts/tools/linkhandler
new file mode 100755
index 0000000..86723de
--- /dev/null
+++ b/.scripts/tools/linkhandler
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Feed script a url.
+# If an image, it will view in feh,
+# 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.
+
+# Sci-Hub's domain occasionally changes due to shutdowns:
+scihub="http://sci-hub.tw/"
+
+# If no url given. Opens browser. For using script as $BROWSER.
+[ -z "$1" ] && { "$TRUEBROWSER"; exit; }
+
+case "$1" in
+ *mkv|*webm|*mp4|*gif|*youtube.com*|*hooktube.com*)
+ setsid mpv -quiet "$1" >/dev/null 2>&1 & ;;
+ *png|*jpg|*jpe|*jpeg)
+ setsid feh "$1" >/dev/null 2>&1 & ;;
+ *mp3|*flac|*opus|*mp3?source)
+ setsid tsp wget "$1" >/dev/null 2>&1 & ;;
+ *springer.com*)
+ setsid curl -sO "$(curl -s "$scihub$*" | grep -Po "(?<=location.href=').+.pdf")" >/dev/null 2>&1 & ;;
+ *) setsid "$TRUEBROWSER" "$1" >/dev/null 2>&1 & ;;
+esac
diff --git a/.scripts/tools/lmc b/.scripts/tools/lmc
new file mode 100755
index 0000000..9c92f3f
--- /dev/null
+++ b/.scripts/tools/lmc
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# A general audio interface for LARBS.
+
+newvol="pkill -RTMIN+10 i3blocks"
+
+[ -z "$2" ] && num="2" || num="$2"
+
+case "$1" in
+ u*) pulsemixer --change-volume +"$num" ; $newvol ;;
+ d*) pulsemixer --change-volume -"$num" ; $newvol ;;
+ m*) pulsemixer --toggle-mute ; $newvol ;;
+ truemute) pulsemixer --mute ; $newvol ;;
+ 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
diff --git a/.scripts/tools/note b/.scripts/tools/note
new file mode 100755
index 0000000..a90bff1
--- /dev/null
+++ b/.scripts/tools/note
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# A super basic command. Give it some arguments to use as anotification. It
+# will echo them on the terminal, and if you have `dunst` running, will send a
+# `notify-send` message to it.
+
+echo "$@" && pgrep -x dunst >/dev/null && notify-send "$@"
diff --git a/.scripts/tools/opout b/.scripts/tools/opout
new file mode 100755
index 0000000..1fe3928
--- /dev/null
+++ b/.scripts/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="${1%.*}"
+
+case "$1" in
+ *.tex|*.md|*.rmd|*.ms|*.me) setsid zathura "$basename".pdf >/dev/null 2>&1 & ;;
+ *.html) setsid "$TRUEBROWSER" --new-window "$basename".html >/dev/null 2>&1 & ;;
+ *.sent) setsid sent "$1" >/dev/null 2>&1 & ;;
+esac
diff --git a/.scripts/tools/pauseallmpv b/.scripts/tools/pauseallmpv
new file mode 100755
index 0000000..08241b5
--- /dev/null
+++ b/.scripts/tools/pauseallmpv
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Sends a , key to all mpv instances, pausing them at the last frame.
+
+xdotool search --class mpv | xargs -I % xdotool key --window % comma
diff --git a/.scripts/tools/remaps b/.scripts/tools/remaps
new file mode 100755
index 0000000..95acd90
--- /dev/null
+++ b/.scripts/tools/remaps
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# This script is called by i3 on startup.
+
+# Increase key speed via a rate change
+xset r rate 300 50
+# Map the caps lock key to super...
+setxkbmap -layout us -variant altgr-intl -option caps:super
+# If you don't want a us international keyboard, rather whatever keyboard
+# you set in your installation, comment out the above line and uncomment
+# the one below.
+#setxkbmap -option caps:super
+
+# But when it is pressed only once, treat it as escape.
+killall xcape ; xcape -e 'Super_L=Escape'
+
+# Map the menu button to right super as well.
+xmodmap -e 'keycode 135 = Super_R'
+#keycode 135 = Super_R NoSymbol Super_R
diff --git a/.scripts/tools/shortcuts b/.scripts/tools/shortcuts
new file mode 100755
index 0000000..c53da1d
--- /dev/null
+++ b/.scripts/tools/shortcuts
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# Shell rc file (i.e. bash vs. zsh, etc.)
+shellrc="$HOME/.bashrc"
+
+# Config locations
+folders="$HOME/.key_directories"
+configs="$HOME/.key_files"
+
+# Output locations
+shell_shortcuts="$HOME/.shortcuts"
+ranger_shortcuts="$HOME/.config/ranger/shortcuts.conf"
+qute_shortcuts="$HOME/.config/qutebrowser/shortcuts.py"
+fish_shortcuts="$HOME/.config/fish/shortcuts.fish"
+
+# Remove
+rm -f "$ranger_shortcuts" "$qute_shortcuts"
+echo "abbr \\" > "$fish_shortcuts"
+echo "alias \\" > "$shell_shortcuts"
+
+# Ensure text of argument 1 exists in the file argument 2
+ensure() { (grep "$1" "$2")>/dev/null 2>&1 || echo "$1" >> "$2" ;}
+
+ensure "source $shell_shortcuts" "$shellrc"
+ensure "source $HOME/.config/ranger/shortcuts.conf" "$HOME/.config/ranger/rc.conf"
+ensure "config.source('shortcuts.py')" "$HOME/.config/qutebrowser/config.py"
+ensure "source $HOME/.config/fish/shortcuts.fish" "$HOME/.config/fish/config.fish"
+
+# Format the `folders` file in the correct syntax and sent it to all three configs.
+sed "s/#.*$//;/^$/d" "$folders" | tee >(awk '{print $1"=\"cd "$2" && ls -a\" \\"}' >> "$shell_shortcuts") \
+ >(awk '{print $1, "\"cd " $2 " ; ls -a\" \\"}' >> "$fish_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/#.*$//;/^$/d" "$configs" | tee >(awk '{print $1"=\"$EDITOR "$2"\" \\"}' >> "$shell_shortcuts") \
+ >(awk '{print $1, "\"$EDITOR "$2"\" \\"}' >> "$fish_shortcuts") \
+ | awk '{print "map "$1" shell $EDITOR "$2}' >> "$ranger_shortcuts"
diff --git a/.scripts/tools/speedvid b/.scripts/tools/speedvid
new file mode 100755
index 0000000..ba3a4f6
--- /dev/null
+++ b/.scripts/tools/speedvid
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+base=$(basename $1)
+ext="${base##*.}"
+base="${base%.*}"
+
+ffmpeg -i $1 -vf "setpts=$2*PTS" -an $base'_sped.'$ext
diff --git a/.scripts/tools/texclear b/.scripts/tools/texclear
new file mode 100755
index 0000000..0e08f1d
--- /dev/null
+++ b/.scripts/tools/texclear
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# Clears the build files of a LaTeX/XeLaTeX build.
+# I have vim run this file whenever I exit a .tex file.
+
+[[ "$1" == *.tex ]] || exit
+
+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|nav|out|snm|toc|bcf|run\.xml|synctex\.gz|blg|bbl)" -delete
diff --git a/.scripts/tools/tpb b/.scripts/tools/tpb
new file mode 100755
index 0000000..7a2913a
--- /dev/null
+++ b/.scripts/tools/tpb
@@ -0,0 +1,169 @@
+#!/bin/sh
+#
+# by Sairon Istyar, 2012
+# distributed under the GPLv3 license
+# http://www.opensource.org/licenses/gpl-3.0.html
+#
+
+### CONFIGURATION ###
+# program to use for torrent download
+# magnet link to torrent will be appended
+# you can add -- at the end to indicate end of options
+# (if your program supports it, most do)
+program='/usr/bin/transmission-remote -a'
+daemon='transmission-daemon'
+TPB="https://thepiratebay.org"
+
+# show N first matches by default
+limit=50
+
+# colors
+numbcolor='\x1b[1;35m'
+namecolor='\x1b[1;33m'
+sizecolor='\x1b[1;36m'
+seedcolor='\x1b[1;31m'
+peercolor='\x1b[1;32m'
+errocolor='\x1b[1;31m'
+mesgcolor='\x1b[1;37m'
+nonecolor='\x1b[0m'
+
+# default ordering method
+# 1 - name ascending; 2 - name descending;
+# 3 - recent first; 4 - oldest first;
+# 5 - size descending; 6 - size ascending;
+# 7 - seeds descending; 8 - seeds ascending;
+# 9 - leechers descending; 10 - leechers ascending;
+orderby=7
+### END CONFIGURATION ###
+
+thisfile="$0"
+
+printhelp() {
+ echo -e "Usage:"
+ echo -e "\t$thisfile [options] search query"
+ echo
+ echo
+ echo -e "Available options:"
+ echo -e "\t-h\t\tShow help"
+ echo -e "\t-n [num]\tShow only first N results (default 15; max 100 [top] or 30 [search])"
+ echo -e "\t-C\t\tDo not use colors"
+ echo -e "\t-P [prog]\tSet torrent client command (\`-P torrent-client\` OR \`-P \"torrent-client --options\"\`)"
+ echo
+ echo -e "Current client settings: $program [magnet link]"
+}
+
+# change torrent client
+chex() {
+ sed "s!^program=.*!program=\'$program\'!" -i "$thisfile"
+ if [ $? -eq 0 ] ; then
+ echo "Client changed successfully."
+ exit 0
+ else
+ echo -e "${errocolor}(EE) ${mesgcolor}==> Something went wrong!${nonecolor}"
+ exit 1
+ fi
+}
+
+# script cmdline option handling
+while getopts :hn:CP:: opt ; do
+ case "$opt" in
+ h) printhelp; exit 0;;
+ n) limit="$OPTARG";;
+ C) unset numbcolor namecolor sizecolor seedcolor peercolor nonecolor errocolor mesgcolor;;
+ P) program="$OPTARG"; chex;;
+ *) echo -e "Unknown option(s)."; printhelp; exit 1;;
+ esac
+done
+
+shift `expr $OPTIND - 1`
+
+# correctly encode query
+q=`echo "$*" | tr -d '\n' | od -t x1 -A n | tr ' ' '%'`
+
+# if not searching, show top torrents
+if [ -z "$q" ] ; then
+ url="top/all"
+else
+ url='search/'"$q"'/0/'"$orderby"'/0'
+fi
+
+# get results
+# Here be dragons!
+r=`curl -k -A Mozilla -b "lw=s" -m 15 -s "$TPB/$url" \
+ | grep -Eo '^<td><a href=\"/torrent/[^>]*>.*|^<td><nobr><a href=\"[^"]*|<td align=\"right\">[^<]*' \
+ | sed 's!^<td><a href=\"/torrent/[^>]*>!!; \
+ s!</a>$!!; \
+ s!^<td><nobr><a href=\"!!; \
+ s!^<td [^>]*>!!; \
+ s!&nbsp;!\ !g; \
+ s/|/!/g' \
+ | sed 'N;N;N;N;s!\n!|!g'`
+
+# number of results
+n=`echo "$r" | wc -l`
+
+IFS=$'\n'
+
+# print results
+echo "$r" \
+ | head -n "$limit" \
+ | awk -v N=1 \
+ -v NU="$numbcolor" \
+ -v NA="$namecolor" \
+ -v SI="$sizecolor" \
+ -v SE="$seedcolor" \
+ -v PE="$peercolor" \
+ -v NO="$nonecolor" \
+ -F '|' \
+ '{print NU N ") " NA $1 " " SI $3 " " SE $4 " " PE $5 NO; N++}'
+
+# read ID(s), expand ranges, ignore everything else
+read -p ">> Torrents to download (eg. 1 3 5-7): " selection
+IFS=$'\n\ '
+for num in $selection ; do
+ if [ "$num" = "`echo $num | grep -o '[[:digit:]][[:digit:]]*'`" ] ; then
+ down="$down $num"
+ elif [ "$num" = "`echo $num | grep -o '[[:digit:]][[:digit:]]*-[[:digit:]][[:digit:]]*'`" ] ; then
+ seqstart="${num%-*}"
+ seqend="${num#*-}"
+ if [ $seqstart -le $seqend ] ; then
+ down="$down `seq $seqstart $seqend`"
+ fi
+ fi
+done
+
+# normalize download list, sort it and remove dupes
+down="$(echo $down | tr '\ ' '\n' | sort -n | uniq)"
+IFS=$'\n'
+
+# check whether we're downloading something, else exit
+if [ -z "$down" ] ; then
+ exit 0
+fi
+
+# starts daemon if it was not already running and download all torrents in list
+echo -n "Downloading torrent(s): "
+if ! [ "$(pidof $daemon)" ]; then
+ $daemon
+ for torrent in $down ; do
+ # check if ID is valid and in range of results, download torrent
+ if [ $torrent -ge 1 ] ; then
+ if [ $torrent -le $limit ] ; then
+ echo -n "$torrent "
+ command="$program `echo "$r" | awk -F '|' 'NR=='$torrent'{print $2; exit}'`"
+ status=$(eval "$command" 2>&1)
+ if [ $? -ne 0 ] ; then
+ echo -n '(failed!) '
+ report="$report\n(#$torrent) $status"
+ fi
+ fi
+ fi
+ done
+fi
+
+echo
+if [ -n "$report" ] ; then
+ echo -n "Exited with errors:"
+ echo -e "$report"
+fi
+unset IFS
diff --git a/.scripts/tools/transadd b/.scripts/tools/transadd
new file mode 100755
index 0000000..782f67a
--- /dev/null
+++ b/.scripts/tools/transadd
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# Mimeapp script for adding torrent to transmission-daemon, but will also start
+# the daemon first if not running.
+
+# Optionally requires my `note` script. The sleep of 3 seconds is because the
+# transmission-daemon sometimes fails to take remote requests in its first
+# moments.
+
+pgrep -x transmission-da || (transmission-daemon && note "Starting daemon..." && sleep 3 && pkill -RTMIN+7 i3blocks)
+
+transmission-remote -a "$@" && note "Torrent added."