diff options
| -rwxr-xr-x | 4viewer | 22 | ||||
| -rwxr-xr-x | ani-cli | 418 | ||||
| -rwxr-xr-x | booksplit | 46 | ||||
| -rwxr-xr-x | compiler | 57 | ||||
| -rw-r--r-- | cron/README.md | 11 | ||||
| -rwxr-xr-x | cron/checkup | 17 | ||||
| -rwxr-xr-x | cron/crontog | 6 | ||||
| -rwxr-xr-x | cron/newsup | 15 | ||||
| -rwxr-xr-x | displayselect | 83 | ||||
| -rwxr-xr-x | dmenuhandler | 21 | ||||
| -rwxr-xr-x | dmenumount | 67 | ||||
| -rwxr-xr-x | dmenumountcifs | 19 | ||||
| -rwxr-xr-x | dmenupass | 6 | ||||
| -rwxr-xr-x | dmenurecord | 123 | ||||
| -rwxr-xr-x | dmenuumount | 44 | ||||
| -rwxr-xr-x | dmenuunicode | 18 | ||||
| -rwxr-xr-x | getbib | 14 | ||||
| -rwxr-xr-x | getkeys | 5 | ||||
| -rwxr-xr-x | ifinstalled | 12 | ||||
| -rwxr-xr-x | lf-select | 9 | ||||
| -rwxr-xr-x | linkhandler | 23 | ||||
| -rwxr-xr-x | maimpick | 14 | ||||
| l--------- | ncmpcpp-ueberzug | 1 | ||||
| -rwxr-xr-x | noisereduce | 81 | ||||
| -rwxr-xr-x | opout | 13 | ||||
| -rwxr-xr-x | passmenu-otp | 30 | ||||
| -rwxr-xr-x | pauseallmpv | 10 | ||||
| -rwxr-xr-x | peertubetorrent | 7 | ||||
| -rwxr-xr-x | podentr | 7 | ||||
| -rwxr-xr-x | prompt | 8 | ||||
| -rwxr-xr-x | qndl | 12 | ||||
| -rwxr-xr-x | queueandnotify | 14 | ||||
| -rwxr-xr-x | remaps | 13 | ||||
| -rwxr-xr-x | rotdir | 12 | ||||
| -rwxr-xr-x | rssadd | 18 | ||||
| -rwxr-xr-x | samedir | 10 | ||||
| -rwxr-xr-x | setbg | 33 | ||||
| -rwxr-xr-x | shortcuts | 40 | ||||
| -rwxr-xr-x | slider | 126 | ||||
| -rwxr-xr-x | statusbar/sb-battery | 37 | ||||
| -rwxr-xr-x | statusbar/sb-clock | 29 | ||||
| -rwxr-xr-x | statusbar/sb-cpu | 12 | ||||
| -rwxr-xr-x | statusbar/sb-cpubars | 44 | ||||
| -rwxr-xr-x | statusbar/sb-disk | 23 | ||||
| -rwxr-xr-x | statusbar/sb-doppler | 206 | ||||
| -rwxr-xr-x | statusbar/sb-forecast | 35 | ||||
| -rwxr-xr-x | statusbar/sb-help-icon | 17 | ||||
| -rwxr-xr-x | statusbar/sb-internet | 26 | ||||
| -rwxr-xr-x | statusbar/sb-iplocate | 10 | ||||
| -rwxr-xr-x | statusbar/sb-kbselect | 16 | ||||
| -rwxr-xr-x | statusbar/sb-mailbox | 20 | ||||
| -rwxr-xr-x | statusbar/sb-memory | 12 | ||||
| -rwxr-xr-x | statusbar/sb-moonphase | 37 | ||||
| -rwxr-xr-x | statusbar/sb-mpdup | 8 | ||||
| -rwxr-xr-x | statusbar/sb-music | 19 | ||||
| -rwxr-xr-x | statusbar/sb-nettraf | 29 | ||||
| -rwxr-xr-x | statusbar/sb-news | 17 | ||||
| -rwxr-xr-x | statusbar/sb-pacpackages | 29 | ||||
| -rwxr-xr-x | statusbar/sb-popupgrade | 9 | ||||
| -rwxr-xr-x | statusbar/sb-price | 50 | ||||
| -rwxr-xr-x | statusbar/sb-tasks | 20 | ||||
| -rwxr-xr-x | statusbar/sb-torrent | 27 | ||||
| -rwxr-xr-x | statusbar/sb-volume | 30 | ||||
| -rwxr-xr-x | sysact | 18 | ||||
| -rwxr-xr-x | tag | 67 | ||||
| -rwxr-xr-x | td-toggle | 12 | ||||
| -rwxr-xr-x | texclear | 16 | ||||
| -rwxr-xr-x | torwrap | 7 | ||||
| -rwxr-xr-x | transadd | 9 | ||||
| -rwxr-xr-x | tutorialvids | 26 | ||||
| -rwxr-xr-x | unix | 26 |
71 files changed, 2428 insertions, 0 deletions
@@ -0,0 +1,22 @@ +#!/bin/bash + +archivegif () { +LINK=$(curl -s "${1}") +title=$(echo "$LINK" | grep -oE post_title.*\<\/h2\> | head -1 | sed 's/post_title">//' | sed 's/<\/h2>//') +urls=$(echo "$LINK" | grep -oP '"\K[^"\047]+(?=["\047])' | grep -E ".gif|.webm" | grep -v "s\." | grep "//" | grep torako | uniq) +} + + +mpv-chan() { + URL=$1 + BOARD=$(echo $URL| grep -Po '([\w\d]+)\/thread' |cut -d'/' -f1) + title=$(curl -sL "${URL}.json" | jq -cr '.posts[0].sub') + urls=$(curl -sL "${URL}.json"|jq -cr '.posts[]|("https://i.4cdn.org/'${BOARD}'/"+(.tim|tostring) + .ext )'|grep -v null|paste -sd ' ') +} + +if [[ "$1" == *"boards"* ]]; then + mpv-chan "$1" + else + archivegif "$1" +fi +mpv --quiet --prefetch-playlist=yes --no-pause --force-media-title="$title" --demuxer-cache-wait=no $urls @@ -0,0 +1,418 @@ +#!/bin/sh + +# dependencies: grep sed curl video_player +# video_player ( needs to be able to play urls ) +player_fn="mpv" + +prog="ani-cli" +logfile="${XDG_CACHE_HOME:-$HOME/.cache}/ani-hsts" +base_url="https://gogoanime.cm" + +c_red="\033[1;31m" +c_green="\033[1;32m" +c_yellow="\033[1;33m" +c_blue="\033[1;34m" +c_magenta="\033[1;35m" +c_cyan="\033[1;36m" +c_reset="\033[0m" + + +help_text () { + while IFS= read line; do + printf "%s\n" "$line" + done <<-EOF + USAGE: $prog <query> + -h show this help text + -d download episode + -H continue where you left off + -D delete history + -q set video quality (best/worst/360/480/720/..) + --dub play the dub version if present + EOF +} + + +die () { + printf "$c_red%s$c_reset\n" "$*" >&2 + exit 1 +} + +err () { + printf "$c_red%s$c_reset\n" "$*" >&2 +} + +search_anime () { + # get anime name along with its id + search=$(printf '%s' "$1" | tr ' ' '-' ) + titlepattern='<a href="/category/' + + curl -s "$base_url//search.html" \ + -G \ + -d "keyword=$search" | + sed -n -E ' + s_^[[:space:]]*<a href="/category/([^"]*)" title="([^"]*)".*_\1_p + ' +} + +search_eps () { + # get available episodes for anime_id + anime_id=$1 + + curl -s "$base_url/category/$anime_id" | + sed -n -E ' + /^[[:space:]]*<a href="#" class="active" ep_start/{ + s/.* '\''([0-9]*)'\'' ep_end = '\''([0-9]*)'\''.*/\2/p + q + } + ' +} + +get_embedded_video_link() { + # get the download page url + anime_id=$1 + ep_no=$2 + + # credits to fork: https://github.com/Dink4n/ani-cli for the fix + # dub prefix takes the value "-dub" when dub is needed else is empty + curl -s "$base_url/$anime_id${dub_prefix}-episode-$ep_no" | + sed -n -E ' + /^[[:space:]]*<a href="#" rel="100"/{ + s/.*data-video="([^"]*)".*/https:\1/p + q + }' +} + +get_video_quality() { + embedded_video_url=$1 + video_url=$2 + + video_file=$(curl -s --referer "$embedded_video_url" "$video_url") + available_qualities=$(printf '%s' "$video_file" | sed -n -E 's/.*NAME="([^p]*)p"/\1/p') + case $quality in + best) + printf '%s' "$available_qualities" | tail -n 1 + ;; + + worst) + printf '%s' "$available_qualities" | head -n 1 + ;; + + *) + is_quality_avail=$(printf '%s' "$available_qualities" | grep "$quality") + video_quality="$quality" + if [ -z "$is_quality_avail" ]; then + printf "$c_red%s$c_reset\n" "Current video quality is not available (defaulting to highest quality)" >&2 + quality=best + video_quality=$(printf '%s' "$available_qualities" | tail -n 1) + fi + printf '%s' "$video_quality" + ;; + esac + +} + +get_links () { + embedded_video_url="$1" + video_url=$(curl -s "$embedded_video_url" | + sed -n -E ' + /^[[:space:]]*sources:/{ + s/.*(https[^'\'']*).*/\1/p + q + } + ') + + video_quality=$(get_video_quality "$embedded_video_url" "$video_url") + + # Replace the video with highest quality video + printf '%s' "$video_url" | sed -n -E "s/(.*)\.m3u8/\1.$video_quality.m3u8/p" +} + +dep_ch () { + for dep; do + if ! command -v "$dep" >/dev/null ; then + die "Program \"$dep\" not found. Please install it." + fi + done +} + +# get query +get_search_query () { + if [ -z "$*" ]; then + printf "Search Anime: " + read -r query + else + query=$* + fi +} + +# create history file +[ -f "$logfile" ] || : > "$logfile" + +##################### +## Anime selection ## +##################### + +anime_selection () { + search_results=$* + menu_format_string='[%d] %s\n' + menu_format_string_c1="$c_blue[$c_cyan%d$c_blue] $c_reset%s\n" + menu_format_string_c2="$c_blue[$c_cyan%d$c_blue] $c_yellow%s$c_reset\n" + + count=1 + while read anime_id; do + # alternating colors for menu + [ $((count % 2)) -eq 0 ] && + menu_format_string=$menu_format_string_c1 || + menu_format_string=$menu_format_string_c2 + + printf "$menu_format_string" "$count" "$anime_id" + count=$((count+1)) + done <<-EOF + $search_results + EOF + + # User input + printf "$c_blue%s$c_green" "Enter number: " + read choice + printf "$c_reset" + + # Check if input is a number + [ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered" + + # Select respective anime_id + count=1 + while read anime_id; do + if [ $count -eq $choice ]; then + selection_id=$anime_id + break + fi + count=$((count+1)) + done <<-EOF + $search_results + EOF + + [ -z "$selection_id" ] && die "Invalid number entered" + + read last_ep_number <<-EOF + $(search_eps "$selection_id") + EOF +} + +################## +## Ep selection ## +################## + +episode_selection () { + ep_choice_start="1" + if [ $last_ep_number -gt 1 ] + then + [ $is_download -eq 1 ] && + printf "Range of episodes can be specified: start_number end_number\n" + + printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number + read ep_choice_start ep_choice_end + printf "$c_reset" + fi +} + +check_input() { + [ "$ep_choice_start" -eq "$ep_choice_start" ] 2>/dev/null || die "Invalid number entered" + episodes=$ep_choice_start + if [ -n "$ep_choice_end" ]; then + [ "$ep_choice_end" -eq "$ep_choice_end" ] 2>/dev/null || die "Invalid number entered" + # create list of episodes to download/watch + episodes=$(seq $ep_choice_start $ep_choice_end) + fi +} + +append_history () { + grep -q -w "${selection_id}" "$logfile" || + printf "%s\t%d\n" "$selection_id" $((episode+1)) >> "$logfile" +} + +open_selection() { + for ep in $episodes + do + open_episode "$selection_id" "$ep" + done + episode=${ep_choice_end:-$ep_choice_start} +} + +open_episode () { + anime_id=$1 + episode=$2 + + # Cool way of clearing screen + tput reset + while [ "$episode" -lt 1 ] || [ "$episode" -gt "$last_ep_number" ] + do + err "Episode out of range" + printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number + read episode + printf "$c_reset" + done + + printf "Getting data for episode %d\n" $episode + + embedded_video_url=$(get_embedded_video_link "$anime_id" "$episode") + video_url=$(get_links "$embedded_video_url") + + case $video_url in + *streamtape*) + # If direct download not available then scrape streamtape.com + BROWSER=${BROWSER:-firefox} + printf "scraping streamtape.com\n" + video_url=$(curl -s "$video_url" | sed -n -E ' + /^<script>document/{ + s/^[^"]*"([^"]*)" \+ '\''([^'\'']*).*/https:\1\2\&dl=1/p + q + } + ');; + esac + + if [ $is_download -eq 0 ]; then + # write anime and episode number + sed -E " + s/^${selection_id}\t[0-9]+/${selection_id}\t$((episode+1))/ + " "$logfile" > "${logfile}.new" && mv "${logfile}.new" "$logfile" + + setsid -f $player_fn --http-header-fields="Referer: $embedded_video_url" "$video_url" >/dev/null 2>&1 + else + printf "Downloading episode $episode ...\n" + printf "%s\n" "$video_url" + # add 0 padding to the episode name + episode=$(printf "%03d" $episode) + { + ffmpeg -headers "Referer: $embedded_video_url" -i "$video_url" \ + -c copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 && + printf "${c_green}Downloaded episode: %s${c_reset}\n" "$episode" || + printf "${c_red}Download failed episode: %s${c_reset}\n" "$episode" + } + fi +} + +############ +# Start Up # +############ + +# to clear the colors when exited using SIGINT +trap "printf '$c_reset'" INT HUP + +dep_ch "$player_fn" "curl" "sed" "grep" + +# option parsing +is_download=0 +quality=best +scrape=query +while getopts 'hdHDq:-:' OPT; do + case $OPT in + h) + help_text + exit 0 + ;; + d) + is_download=1 + ;; + H) + scrape=history + ;; + + D) + : > "$logfile" + exit 0 + ;; + q) + quality=$OPTARG + ;; + -) + case $OPTARG in + dub) + dub_prefix="-dub" + ;; + esac + ;; + esac +done +shift $((OPTIND - 1)) + +######## +# main # +######## + +case $scrape in + query) + get_search_query "$*" + search_results=$(search_anime "$query") + [ -z "$search_results" ] && die "No search results found" + anime_selection "$search_results" + episode_selection + ;; + history) + search_results=$(sed -n -E 's/\t[0-9]*//p' "$logfile") + [ -z "$search_results" ] && die "History is empty" + anime_selection "$search_results" + ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" "$logfile") + ;; +esac + +check_input +append_history +open_selection + +while :; do + printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number + if [ "$episode" -ne "$last_ep_number" ]; then + printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "n" "next episode" + fi + if [ "$episode" -ne "1" ]; then + printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "p" "previous episode" + fi + if [ "$last_ep_number" -ne "1" ]; then + printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "s" "select episode" + fi + printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "r" "replay current episode" + printf "$c_blue[${c_cyan}%s$c_blue] $c_cyan%s$c_reset\n" "a" "search for another anime" + printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit" + printf "${c_blue}Enter choice:${c_green} " + read choice + printf "$c_reset" + case $choice in + n) + episode=$((episode + 1)) + ;; + p) + episode=$((episode - 1)) + ;; + + s) printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number + read episode + printf "$c_reset" + [ "$episode" -eq "$episode" ] 2>/dev/null || die "Invalid number entered" + ;; + + r) + episode=$((episode)) + ;; + a) + tput reset + get_search_query "" + search_results=$(search_anime "$query") + [ -z "$search_results" ] && die "No search results found" + anime_selection "$search_results" + episode_selection + check_input + append_history + open_selection + continue + ;; + + q) + break;; + + *) + die "invalid choice" + ;; + esac + + open_episode "$selection_id" "$episode" +done diff --git a/booksplit b/booksplit new file mode 100755 index 0000000..7730ac2 --- /dev/null +++ b/booksplit @@ -0,0 +1,46 @@ +#!/bin/sh + +# Requires ffmpeg (audio splitting) and my `tag` wrapper script. + +[ ! -f "$2" ] && printf "The first file should be the audio, the second should be the timecodes.\\n" && exit + +echo "Enter the album/book title:"; read -r booktitle + +echo "Enter the artist/author:"; read -r author + +echo "Enter the publication year:"; read -r year + +inputaudio="$1" + +# Get a safe file name from the book. +escbook="$(echo "$booktitle" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + +! mkdir -p "$escbook" && echo "Do you have write access in this directory?" && exit 1 + +# As long as the extension is in the tag script, it'll work. +ext="opus" +#ext="${1#*.}" + +# Get the total number of tracks from the number of lines. +total="$(wc -l < "$2")" + +while read -r x; +do + end="$(echo "$x" | cut -d' ' -f1)" + + [ -n "$start" ] && + echo "From $start to $end; $track $title" + file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" + [ -n "$start" ] && echo "Splitting \"$title\"..." && + ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -to "$end" -vn -c copy "$file" && + echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file" + title="$(echo "$x" | cut -d' ' -f 2-)" + esctitle="$(echo "$title" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g")" + track="$((track+1))" + start="$end" +done < "$2" +# The last track must be done outside the loop. +echo "From $start to the end: $title" +file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" +echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -vn -c copy "$file" && + echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file"
\ No newline at end of file diff --git a/compiler b/compiler new file mode 100755 index 0000000..faf37c9 --- /dev/null +++ b/compiler @@ -0,0 +1,57 @@ +#!/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, .org. Opens .sent files as sent +# presentations. Runs scripts based on extention or shebang. +# +# Note that .tex files which you wish to compile with XeLaTeX should have the +# string "xelatex" somewhere in a comment/command in the first 5 lines. + +file=$(readlink -f "$1") +dir=${file%/*} +base="${file%.*}" +ext="${file##*.}" + +cd "$dir" || exit 1 + +textype() { \ + command="pdflatex" + ( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex" + $command --output-directory="$dir" "$base" && + grep -qi addbibresource "$file" && + biber --input-directory "$dir" "$base" && + $command --output-directory="$dir" "$base" && + $command --output-directory="$dir" "$base" +} + +case "$ext" in + # Try to keep these cases in alphabetical order. + [0-9]) preconv "$file" | refer -PS -e | groff -mandoc -T pdf > "$base".pdf ;; + c) cc "$file" -o "$base" && "$base" ;; + cpp) g++ "$file" -o "$base" && "$base" ;; + cs) mcs "$file" && mono "$base".exe ;; + go) go run "$file" ;; + h) sudo make install ;; + java) javac -d classes "$file" && java -cp classes "${1%.*}" ;; + m) octave "$file" ;; + md) if [ -x "$(command -v lowdown)" ]; then + lowdown -d nointem -e super "$file" -Tms | groff -mpdfmark -ms -kept > "$base".pdf + elif [ -x "$(command -v groffdown)" ]; then + groffdown -i "$file" | groff > "$base.pdf" + else + pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file" + fi ; ;; + mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;; + ms) preconv "$file" | refer -PS -e | groff -me -ms -kept -T pdf > "$base".pdf ;; + org) emacs "$file" --batch -u "$USER" -f org-latex-export-to-pdf ;; + py) python "$file" ;; + [rR]md) Rscript -e "rmarkdown::render('$file', quiet=TRUE)" ;; + rs) cargo build ;; + sass) sassc -a "$file" "$base.css" ;; + scad) openscad -o "$base".stl "$file" ;; + sent) setsid -f sent "$file" 2>/dev/null ;; + tex) textype "$file" ;; + *) sed -n '/^#!/s/^#!//p; q' "$file" | xargs -r -I % "$file" ;; +esac diff --git a/cron/README.md b/cron/README.md new file mode 100644 index 0000000..fa0c354 --- /dev/null +++ b/cron/README.md @@ -0,0 +1,11 @@ +# Important Note + +These cronjobs have components that require information about your current display to display notifications correctly. + +When you add them as cronjobs, I recommend you precede the command with commands as those below: + +``` +export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus; export DISPLAY=:0; . $HOME/.zprofile; then_command_goes_here +``` + +This ensures that notifications will display, xdotool commands will function and environmental variables will work as well. diff --git a/cron/checkup b/cron/checkup new file mode 100755 index 0000000..bd3c634 --- /dev/null +++ b/cron/checkup @@ -0,0 +1,17 @@ +#!/bin/sh + +# Syncs repositories and downloads updates, meant to be run as a cronjob. + +notify-send "π¦ Repository Sync" "Checking for package updates..." + +sudo pacman -Syyuw --noconfirm || notify-send "Error downloading updates. + +Check your internet connection, if pacman is already running, or run update manually to see errors." +pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}" + +if pacman -Qu | grep -v "\[ignored\]" +then + notify-send "π Repository Sync" "Updates available. Click statusbar icon (π¦) for update." +else + notify-send "π¦ Repository Sync" "Sync complete. No new packages for update." +fi diff --git a/cron/crontog b/cron/crontog new file mode 100755 index 0000000..5aba5e6 --- /dev/null +++ b/cron/crontog @@ -0,0 +1,6 @@ +#!/bin/sh + +# Toggles all cronjobs off/on. +# Stores disabled crontabs in ~/.consaved until restored. + +([ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved ] && crontab - < "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && rm "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && notify-send "π Cronjobs re-enabled.") || ( crontab -l > "${XDG_CONFIG_HOME:-$HOME/.config}"/cronsaved && crontab -r && notify-send "π Cronjobs saved and disabled.") diff --git a/cron/newsup b/cron/newsup new file mode 100755 index 0000000..ed266d7 --- /dev/null +++ b/cron/newsup @@ -0,0 +1,15 @@ +#!/bin/sh + +# Set as a cron job to check for new RSS entries for newsboat. +# If newsboat is open, sends it an "R" key to refresh. + +/usr/bin/notify-send "π° Updating RSS feeds..." + +pgrep -f newsboat$ && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name "^newsboat$")" R && exit + +echo π > /tmp/newsupdate +pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}" +/usr/bin/newsboat -x reload +rm -f /tmp/newsupdate +pkill -RTMIN+6 "${STATUSBAR:-dwmblocks}" +/usr/bin/notify-send "π° RSS feed update complete." diff --git a/displayselect b/displayselect new file mode 100755 index 0000000..f9e8062 --- /dev/null +++ b/displayselect @@ -0,0 +1,83 @@ +#!/bin/sh + +# A UI for detecting and selecting all displays. Probes xrandr for connected +# displays and lets user select one to use. User may also select "manual +# selection" which opens arandr. + +twoscreen() { # If multi-monitor is selected and there are two screens. + + mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") + # Mirror displays using native resolution of external display and a scaled + # version for the internal display + if [ "$mirror" = "yes" ]; then + external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:") + internal=$(echo "$screens" | grep -v "$external") + + res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ + tail -n 1 | awk '{print $1}') + + res_ext_x=$(echo "$res_external" | sed 's/x.*//') + res_ext_y=$(echo "$res_external" | sed 's/.*x//') + res_int_x=$(echo "$res_internal" | sed 's/x.*//') + res_int_y=$(echo "$res_internal" | sed 's/.*x//') + + scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l) + scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l) + + xrandr --output "$external" --auto --scale 1.0x1.0 \ + --output "$internal" --auto --same-as "$external" \ + --scale "$scale_x"x"$scale_y" + else + + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0 + fi + } + +morescreen() { # If multi-monitor is selected and there are more than two screens. + primary=$(echo "$screens" | dmenu -i -p "Select primary display:") + secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:") + direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") + tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:") + xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto + } + +multimon() { # Multi-monitor handler. + case "$(echo "$screens" | wc -l)" in + 2) twoscreen ;; + *) morescreen ;; + esac ;} + +onescreen() { # If only one output available or chosen. + xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -) + } + +postrun() { # Stuff to run to clean up. + setbg # Fix background if screen size/arangement has changed. + remaps # Re-remap keys if keyboard added (for laptop bases) + { killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen + } + +# Get all possible displays +allposs=$(xrandr -q | grep "connected") + +# Get all connected screens. +screens=$(echo "$allposs" | awk '/ connected/ {print $1}') + +# If there's only one screen +[ "$(echo "$screens" | wc -l)" -lt 2 ] && + { onescreen "$screens"; postrun; notify-send "π» Only one screen detected." "Using it in its optimal settings..."; exit ;} + +# Get user choice including multi-monitor and manual selection: +chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") && +case "$chosen" in + "manual selection") arandr ; exit ;; + "multi-monitor") multimon ;; + *) onescreen "$chosen" ;; +esac + +postrun diff --git a/dmenuhandler b/dmenuhandler new file mode 100755 index 0000000..e5de8ef --- /dev/null +++ b/dmenuhandler @@ -0,0 +1,21 @@ +#!/bin/sh + +# Feed this script a link and it will give dmenu +# some choice programs to use to open it. +feed="${1:-$(printf "%s" | dmenu -p 'Paste URL or file path')}" + +case "$(printf "Copy URL\\nsxiv\\nsetbg\\nPDF\\nbrowser\\nlynx\\nvim\\nmpv\\nmpv loop\\nmpv float\\nqueue download\\nqueue yt-dl\\nqueue yt-dl audio" | dmenu -i -p "Open it with?")" in + "copy url") echo "$feed" | xclip -selection clipboard ;; + mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;; + "mpv loop") setsid -f mpv -quiet --loop "$feed" >/dev/null 2>&1 ;; + "mpv float") setsid -f "$TERMINAL" -e mpv --geometry=+0-0 --autofit=30% --title="mpvfloat" "$feed" >/dev/null 2>&1 ;; + "queue yt-dl") qndl "$feed" >/dev/null 2>&1 ;; + "queue yt-dl audio") qndl "$feed" 'youtube-dl --add-metadata -icx -f bestaudio/best' >/dev/null 2>&1 ;; + "queue download") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;; + PDF) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + sxiv) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + setbg) curl -L "$feed" > $XDG_CACHE_HOME/pic ; xwallpaper --zoom $XDG_CACHE_HOME/pic >/dev/null 2>&1 ;; + browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;; + lynx) lynx "$feed" >/dev/null 2>&1 ;; +esac diff --git a/dmenumount b/dmenumount new file mode 100755 index 0000000..3cb1f81 --- /dev/null +++ b/dmenumount @@ -0,0 +1,67 @@ +#!/bin/sh + +# Gives a dmenu prompt to mount unmounted drives and Android phones. If +# they're in /etc/fstab, they'll be mounted automatically. Otherwise, you'll +# be prompted to give a mountpoint from already existsing directories. If you +# input a novel directory, it will prompt you to create that directory. + +getmount() { \ + [ -z "$chosen" ] && exit 1 + # shellcheck disable=SC2086 + mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1 + test -z "$mp" && exit 1 + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi + } + +mountusb() { \ + chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + sudo -A mount "$chosen" 2>/dev/null && notify-send "π» USB mounting" "$chosen mounted." && exit 0 + alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') + getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted" + partitiontype="$(lsblk -no "fstype" "$chosen")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; + "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; + *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + notify-send "π» USB mounting" "$chosen mounted to $mp." + } + +mountandroid() { \ + chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1 + chosen="$(echo "$chosen" | cut -d : -f 1)" + getmount "$HOME -maxdepth 3 -type d" + simple-mtpfs --device "$chosen" "$mp" + echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + simple-mtpfs --device "$chosen" "$mp" + notify-send "π€ Android Mounting" "Android device mounted to $mp." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 + case $choice in + USB) mountusb ;; + Android) mountandroid ;; + esac + } + +anddrives=$(simple-mtpfs -l 2>/dev/null) +usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" + +if [ -z "$usbdrives" ]; then + [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit + echo "Android device(s) detected." + mountandroid +else + if [ -z "$anddrives" ]; then + echo "USB drive(s) detected." + mountusb + else + echo "Mountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/dmenumountcifs b/dmenumountcifs new file mode 100755 index 0000000..46c2b57 --- /dev/null +++ b/dmenumountcifs @@ -0,0 +1,19 @@ +#!/bin/sh +# Gives a dmenu prompt to mount unmounted local NAS shares for read/write. +# Requirements - "%wheel ALL=(ALL) NOPASSWD: ALL" +# +# Browse for mDNS/DNS-SD services using the Avahi daemon... +srvname=$(avahi-browse _smb._tcp -t | awk '{print $4}' | dmenu -i -p "Which NAS?") || exit 1 +notify-send "Searching for network shares..." "Please wait..." +# Choose share disk... +share=$(smbclient -L "$srvname" -N | grep Disk | awk '{print $1}' | dmenu -i -p "Mount which share?") || exit 1 +# Format URL... +share2mnt=//"$srvname".local/"$share" + +sharemount() { + mounted=$(mount -v | grep "$share2mnt") || ([ ! -d /mnt/"$share" ] && sudo mkdir /mnt/"$share") + [ -z "$mounted" ] && sudo mount -t cifs "$share2mnt" -o user=nobody,password="",noperm /mnt/"$share" && notify-send "Netshare $share mounted" && exit 0 + notify-send "Netshare $share already mounted"; exit 1 +} + +sharemount diff --git a/dmenupass b/dmenupass new file mode 100755 index 0000000..2c14e6f --- /dev/null +++ b/dmenupass @@ -0,0 +1,6 @@ +#!/bin/sh + +# This script is the SUDO_ASKPASS variable, meaning that it will be used as a +# password prompt if needed. + +dmenu -fn Monospace-18 -P -p "$1" <&- && echo diff --git a/dmenurecord b/dmenurecord new file mode 100755 index 0000000..b83a7c5 --- /dev/null +++ b/dmenurecord @@ -0,0 +1,123 @@ +#!/bin/sh + +# Usage: +# `$0`: Ask for recording type via dmenu +# `$0 screencast`: Record both audio and screen +# `$0 video`: Record only screen +# `$0 audio`: Record only audio +# `$0 kill`: Kill existing recording +# +# If there is already a running instance, user will be prompted to end it. + +updateicon() { \ + echo "$1" > /tmp/recordingicon + pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" + } + +killrecording() { + recpid="$(cat /tmp/recordingpid)" + # kill with SIGTERM, allowing finishing touches. + kill -15 "$recpid" + rm -f /tmp/recordingpid + updateicon "" + pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" + # even after SIGTERM, ffmpeg may still run, so SIGKILL it. + sleep 3 + kill -9 "$recpid" + exit + } + +screencast() { \ + ffmpeg -y \ + -f x11grab \ + -framerate 60 \ + -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ + -i "$DISPLAY" \ + -f alsa -i default \ + -r 30 \ + -c:v h264 -crf 0 -preset ultrafast -c:a aac \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈποΈ" + } + +video() { ffmpeg \ + -f x11grab \ + -s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \ + -i "$DISPLAY" \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈ" + } + +webcamhidef() { ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 1920x1080 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "π₯" + } + +webcam() { ffmpeg \ + -f v4l2 \ + -i /dev/video0 \ + -video_size 640x480 \ + "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "π₯" + } + + +audio() { \ + ffmpeg \ + -f alsa -i default \ + -c:a flac \ + "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & + echo $! > /tmp/recordingpid + updateicon "ποΈ" + } + +askrecording() { \ + choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:") + case "$choice" in + screencast) screencast;; + audio) audio;; + video) video;; + *selected) videoselected;; + webcam) webcam;; + "webcam (hi-def)") webcamhidef;; + esac + } + +asktoend() { \ + response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") && + [ "$response" = "Yes" ] && killrecording + } + +videoselected() +{ + slop -f "%x %y %w %h" > /tmp/slop + read -r X Y W H < /tmp/slop + rm /tmp/slop + + ffmpeg \ + -f x11grab \ + -framerate 60 \ + -video_size "$W"x"$H" \ + -i :0.0+"$X,$Y" \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "βΊοΈ" +} + +case "$1" in + screencast) screencast;; + audio) audio;; + video) video;; + *selected) videoselected;; + kill) killrecording;; + *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; +esac diff --git a/dmenuumount b/dmenuumount new file mode 100755 index 0000000..946d12c --- /dev/null +++ b/dmenuumount @@ -0,0 +1,44 @@ +#!/bin/sh + +# A dmenu prompt to unmount drives. +# Provides you with mounted partitions, select one to unmount. +# Drives mounted at /, /boot and /home will not be options to unmount. + +unmountusb() { + [ -z "$drives" ] && exit + chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + [ -z "$chosen" ] && exit + sudo -A umount "$chosen" && notify-send "π» USB unmounting" "$chosen unmounted." + } + +unmountandroid() { \ + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 + [ -z "$chosen" ] && exit + sudo -A umount -l "$chosen" && notify-send "π€ Android unmounting" "$chosen unmounted." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 + case "$choice" in + USB) unmountusb ;; + Android) unmountandroid ;; + esac + } + +drives=$(lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}') + +if ! grep simple-mtpfs /etc/mtab; then + [ -z "$drives" ] && echo "No drives to unmount." && exit + echo "Unmountable USB drive detected." + unmountusb +else + if [ -z "$drives" ] + then + echo "Unmountable Android device detected." + unmountandroid + else + echo "Unmountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/dmenuunicode b/dmenuunicode new file mode 100755 index 0000000..7d9a4ea --- /dev/null +++ b/dmenuunicode @@ -0,0 +1,18 @@ +#!/bin/sh + +# The famous "get a menu of emojis to copy" script. + +# Get user selection via dmenu from emoji file. +chosen=$(cut -d ';' -f1 ~/.local/share/larbs/emoji | dmenu -i -l 30 | sed "s/ .*//") + +# Exit if none chosen. +[ -z "$chosen" ] && exit + +# If you run this command with an argument, it will automatically insert the +# character. Otherwise, show a message that the emoji has been copied. +if [ -n "$1" ]; then + xdotool type "$chosen" +else + printf "$chosen" | xclip -selection clipboard + notify-send "'$chosen' copied to clipboard." & +fi @@ -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 "https://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n" @@ -0,0 +1,5 @@ +#!/bin/sh + +cat "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys/"$1" 2>/dev/null && exit +echo "Run command with one of the following arguments for info about that program:" +ls "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys diff --git a/ifinstalled b/ifinstalled new file mode 100755 index 0000000..c192eba --- /dev/null +++ b/ifinstalled @@ -0,0 +1,12 @@ +#!/bin/sh + +# Some optional functions in LARBS require programs not installed by default. I +# use this little script to check to see if a command exists and if it doesn't +# it informs the user that they need that command to continue. This is used in +# various other scripts for clarity's sake. + +for x in "$@"; do + if ! which "$x" >/dev/null 2>&1 && ! pacman -Qq "$x" >/dev/null 2>&1; then + notify-send "π¦ $x" "must be installed for this function." && exit 1 ; + fi +done diff --git a/lf-select b/lf-select new file mode 100755 index 0000000..3b2a17a --- /dev/null +++ b/lf-select @@ -0,0 +1,9 @@ +#!/bin/sh + +# Reads file names from stdin and selects them in lf. + +while read -r file; do + [ -z "$file" ] && continue + lf -remote "send select \"$file\"" + lf -remote "send toggle" +done diff --git a/linkhandler b/linkhandler new file mode 100755 index 0000000..fa74caf --- /dev/null +++ b/linkhandler @@ -0,0 +1,23 @@ +#!/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/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*) + setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;; + *png|*jpg|*jpe|*jpeg|*gif) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; + *pdf|*cbz|*cbr) + curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;; + *mp3|*flac|*opus|*mp3?source*) + qndl "$1" 'curl -LO' >/dev/null 2>&1 ;; + *) + [ -f "$1" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$1" >/dev/null 2>&1 || setsid -f "$BROWSER" "$1" >/dev/null 2>&1 +esac diff --git a/maimpick b/maimpick new file mode 100755 index 0000000..7125e61 --- /dev/null +++ b/maimpick @@ -0,0 +1,14 @@ +#!/bin/sh + +# This is bound to Shift+PrintScreen by default, requires maim. It lets you +# choose the kind of screenshot to take, including copying the image or even +# highlighting an area to copy. scrotcucks on suicidewatch right now. + +case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)" | dmenu -l 6 -i -p "Screenshot which area?")" in + "a selected area") maim -s pic-selected-"$(date '+%y%m%d-%H%M-%S').png" ;; + "current window") maim -i "$(xdotool getactivewindow)" pic-window-"$(date '+%y%m%d-%H%M-%S').png" ;; + "full screen") maim pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;; + "a selected area (copy)") maim -s | xclip -selection clipboard -t image/png ;; + "current window (copy)") maim -i "$(xdotool getactivewindow)" | xclip -selection clipboard -t image/png ;; + "full screen (copy)") maim | xclip -selection clipboard -t image/png ;; +esac diff --git a/ncmpcpp-ueberzug b/ncmpcpp-ueberzug new file mode 120000 index 0000000..1f74a45 --- /dev/null +++ b/ncmpcpp-ueberzug @@ -0,0 +1 @@ +/home/tyler/.config/ncmpcpp/ncmpcpp-ueberzug/ncmpcpp-ueberzug
\ No newline at end of file diff --git a/noisereduce b/noisereduce new file mode 100755 index 0000000..c344760 --- /dev/null +++ b/noisereduce @@ -0,0 +1,81 @@ +#!/usr/bin/sh + +usage () +{ + printf "Usage : noisereduce <input video file> <output video file>\n" + exit +} + +# Tests for requirements +ifinstalled ffmpeg || { echo >&2 "We require 'ffmpeg' but it's not installed."; exit 1; } +ifinstalled sox || { echo >&2 "We require 'ffmpeg' but it's not installed."; exit 1; } + +if [ "$#" -ne 2 ] +then + usage +fi + +if [ ! -e "$1" ] +then + printf "File not found: %s\n" "$1" + exit +fi + +if [ -e "$2" ] +then + printf "File %s already exists, overwrite? [y/N]\n: " "$2" + read -r yn + case $yn in + [Yy]* ) ;; + * ) exit;; + esac +fi + +inBasename=$(basename "$1") +inExt="${inBasename##*.}" + +isVideoStr=$(ffprobe -v warning -show_streams "$1" | grep codec_type=video) +if [ -n "$isVideoStr" ] +then + isVideo=1 + printf "Detected %s as a video file\n" "$inBasename" +else + isVideo=0 + printf "Detected %s as an audio file\n" "$inBasename" +fi + +printf "Sample noise start time [00:00:00]: " +read -r sampleStart +if [ -z "$sampleStart" ] ; then sampleStart="00:00:00"; fi +printf "Sample noise end time [00:00:00.900]: " +read -r sampleEnd +if [ -z "$sampleEnd" ] ; then sampleEnd="00:00:00.900"; fi +printf "Noise reduction amount [0.21]: " +read -r sensitivity +if [ -z "$sensitivity" ] ; then sensitivity="0.21"; fi + + +tmpVidFile="/tmp/noiseclean_tmpvid.$inExt" +tmpAudFile="/tmp/noiseclean_tmpaud.wav" +noiseAudFile="/tmp/noiseclean_noiseaud.wav" +noiseProfFile="/tmp/noiseclean_noise.prof" +tmpAudCleanFile="/tmp/noiseclean_tmpaud-clean.wav" + +printf "Cleaning noise on %s...\n" "$1" + +if [ $isVideo -eq "1" ]; then + ffmpeg -v warning -y -i "$1" -qscale:v 0 -vcodec copy -an "$tmpVidFile" + ffmpeg -v warning -y -i "$1" -qscale:a 0 "$tmpAudFile" +else + cp "$1" "$tmpAudFile" +fi +ffmpeg -v warning -y -i "$1" -vn -ss "$sampleStart" -t "$sampleEnd" "$noiseAudFile" +sox "$noiseAudFile" -n noiseprof "$noiseProfFile" +sox "$tmpAudFile" "$tmpAudCleanFile" noisered "$noiseProfFile" "$sensitivity" +if [ $isVideo -eq "1" ]; then + ffmpeg -v warning -y -i "$tmpAudCleanFile" -i "$tmpVidFile" -vcodec copy -qscale:v 0 -qscale:a 0 "$2" +else + cp "$tmpAudCleanFile" "$2" +fi + +printf "Done" @@ -0,0 +1,13 @@ +#!/bin/sh + +# opout: "open output": A general handler for opening a file's intended output, +# usually the pdf of a compiled document. I find this useful especially +# running from vim. + +basename="$(echo "${*}" | sed 's/\.[^\/.]*$//')" + +case "${*}" in + *.tex|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) setsid -f xdg-open "$basename".pdf >/dev/null 2>&1 ;; + *.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;; + *.sent) setsid -f sent "$1" >/dev/null 2>&1 ;; +esac diff --git a/passmenu-otp b/passmenu-otp new file mode 100755 index 0000000..9466f32 --- /dev/null +++ b/passmenu-otp @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +shopt -s nullglob globstar + +typeit=0 +if [[ $1 == "--type" ]]; then + typeit=1 + shift +fi + +prefix=${PASSWORD_STORE_DIR-~/.password-store} +password_files=( "$prefix"/**/*.gpg ) +password_files=( "${password_files[@]#"$prefix"/}" ) +password_files=( "${password_files[@]%.gpg}" ) + +password=$(printf '%s\n' "${password_files[@]}" | dmenu -i "$@") + +[[ -n $password ]] || exit + +pass_cmd=show +if pass show "$password" | grep -q '^otpauth://'; then + pass_cmd=otp +fi + +if [[ $typeit -eq 0 ]]; then + pass $pass_cmd -c "$password" 2>/dev/null +else + pass $pass_cmd "$password" | { IFS= read -r pass; printf %s "$pass"; } | + xdotool type --clearmodifiers --file - +fi diff --git a/pauseallmpv b/pauseallmpv new file mode 100755 index 0000000..d69a414 --- /dev/null +++ b/pauseallmpv @@ -0,0 +1,10 @@ +#!/bin/sh + +# You might notice all mpv commands are aliased to have this input-ipc-server +# thing. That's just for this particular command, which allows us to pause +# every single one of them with one command! This is bound to super + shift + p +# (with other things) by default and is used in some other places. + +for i in $(ls /tmp/mpvSockets/*); do + echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"; +done diff --git a/peertubetorrent b/peertubetorrent new file mode 100755 index 0000000..7a7a483 --- /dev/null +++ b/peertubetorrent @@ -0,0 +1,7 @@ +#!/bin/sh +# torrent peertube videos, requires the transadd script +# first argument is the video link, second is the quality (480 or 1080) +# 13/07/20 - Arthur Bais + +link="$(echo "$1" | sed "s/w/download\/torrents/")""-$2.torrent" +transadd "$link" @@ -0,0 +1,7 @@ +#!/bin/sh + +# entr command to run `queueandnotify` when newsboat queue is changed + +[ "$(pgrep -x "$(basename "$0")" | wc -l)" -gt 2 ] && exit + +echo "${XDG_DATA_HOME:-$HOME/.local/share}"/newsboat/queue | entr -p queueandnotify 2>/dev/null @@ -0,0 +1,8 @@ +#!/bin/sh + +# A dmenu binary prompt script. +# Gives a dmenu prompt labeled with $1 to perform command $2. +# For example: +# `./prompt "Do you want to shutdown?" "shutdown -h now"` + +[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2 @@ -0,0 +1,12 @@ +#!/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 -ic" +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/queueandnotify b/queueandnotify new file mode 100755 index 0000000..54b2c2a --- /dev/null +++ b/queueandnotify @@ -0,0 +1,14 @@ +#!/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="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/queue" + +while read -r line; do + [ -z "$line" ] && continue + url="${line%%[ ]*}" + qndl "$url" "curl -LO" +done < "$queuefile" + +echo > "$queuefile" @@ -0,0 +1,13 @@ +#!/bin/sh + +# This script is called 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' +# Turn off the caps lock if on since there is no longer a key for it. +xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock @@ -0,0 +1,12 @@ +#!/bin/sh + +# When I open an image from the file manager in sxiv (the image viewer), I want +# to be able to press the next/previous keys to key through the rest of the +# images in the same directory. This script "rotates" the content of a +# directory based on the first chosen file, so that if I open the 15th image, +# if I press next, it will go to the 16th etc. Autistic, I know, but this is +# one of the reasons that sxiv is great for being able to read standard input. + +[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1 +base="$(basename "$1")" +ls "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }' @@ -0,0 +1,18 @@ +#!/bin/sh + +if echo "$1" | grep -q "https*://\S\+\.[A-Za-z]\+\S*" ; then + url="$1" +else + url="$(grep -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | + grep -o "https?://[^\" ]")" + + echo "$url" | grep -q "https*://\S\+\.[A-Za-z]\+\S*" || + notify-send "That doesn't look like a full URL." && exit 1 +fi + +RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" +if awk '{print $1}' "$RSSFILE" | grep "^$url$" >/dev/null; then + notify-send "You already have this RSS feed." +else + echo "$url" >> "$RSSFILE" && notify-send "RSS feed added." +fi @@ -0,0 +1,10 @@ +#!/bin/sh + +# Open a terminal window in the same directory as the currently active window. + +PID=$(xprop -id "$(xprop -root | xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p") +PID="$(pstree -lpA "$PID")" +PID="${PID##*(}" +PID="${PID%)}" +cd "$(readlink /proc/"$PID"/cwd)" || return 1 +"$TERMINAL" @@ -0,0 +1,33 @@ +#!/bin/sh + +# This script does the following: +# Run by itself, set the wallpaper (at X start). +# If given a file, set that as the new wallpaper. +# If given a directory, choose random file in it. +# If wal is installed, also generates a colorscheme. + +# Location of link to wallpaper link. +bgloc="${XDG_DATA_HOME:-$HOME/.local/share/}/bg" + +# Configuration files of applications that have their themes changed by pywal. +dunstconf="${XDG_CONFIG_HOME:-$HOME/.config}/dunst/dunstrc" +zathuraconf="${XDG_CONFIG_HOME:-$HOME/.config}/zathura/zathurarc" + +trueloc="$(readlink -f "$1")" && +case "$(file --mime-type -b "$trueloc")" in + image/* ) ln -sf "$(readlink -f "$1")" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..." ;; + inode/directory ) ln -sf "$(find "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && notify-send -i "$bgloc" "Random Wallpaper chosen." ;; + *) notify-send "Error" "Not a valid image." ; exit 1;; +esac + +# If pywal is installed, use it. +if command -v wal >/dev/null 2>&1 ; then + wal -i "$(readlink -f $bgloc)" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" >/dev/null 2>&1 && + pidof dwm >/dev/null && xdotool key super+F12 +# If pywal is removed, return config files to normal. +else + [ -f "$dunstconf.bak" ] && unlink "$dunstconf" && mv "$dunstconf.bak" "$dunstconf" + [ -f "$zathuraconf.bak" ] && unlink "$zathuraconf" && mv "$zathuraconf.bak" "$zathuraconf" +fi + +xwallpaper --zoom "$bgloc" diff --git a/shortcuts b/shortcuts new file mode 100755 index 0000000..253aff0 --- /dev/null +++ b/shortcuts @@ -0,0 +1,40 @@ +#!/bin/sh + +bmdirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" +bmfiles="${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-files" + +# Output locations. Unactivated progs should go to /dev/null. +shell_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc" +zsh_named_dirs="${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" +lf_shortcuts="${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc" +ranger_shortcuts="/dev/null" +qute_shortcuts="/dev/null" +fish_shortcuts="/dev/null" +vifm_shortcuts="/dev/null" + +# Remove, prepare files +rm -f "$lf_shortcuts" "$ranger_shortcuts" "$qute_shortcuts" "$zsh_named_dirs" 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 `directories` file in the correct syntax and sent it to all three configs. +eval "echo \"$(cat "$bmdirs")\"" | \ +awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42cd %s && ls -a\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42cd %s; and ls -a\42\n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map g%s :cd %s<CR>\nmap t%s <tab>:cd %s<CR><tab>\nmap M%s <tab>:cd %s<CR><tab>:mo<CR>\nmap Y%s <tab>:cd %s<CR><tab>:co<CR> \n\",\$1,\$2, \$1, \$2, \$1, \$2, \$1, \$2) >> \"$vifm_shortcuts\" ; + printf(\"config.bind(';%s', \42set downloads.location.directory %s ;; hint links download\42) \n\",\$1,\$2) >> \"$qute_shortcuts\" ; + printf(\"map g%s cd %s\nmap t%s tab_new %s\nmap m%s shell mv -v %%s %s\nmap Y%s shell cp -rv %%s %s \n\",\$1,\$2,\$1,\$2, \$1, \$2, \$1, \$2) >> \"$ranger_shortcuts\" ; + printf(\"map C%s cd \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" }" + +# Format the `files` file in the correct syntax and sent it to both configs. +eval "echo \"$(cat "$bmfiles")\"" | \ +awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); + printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; + printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; + printf(\"abbr %s \42\$EDITOR %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ; + printf(\"map %s :e %s<CR> \n\",\$1,\$2) >> \"$vifm_shortcuts\" ; + printf(\"map %s shell \$EDITOR %s \n\",\$1,\$2) >> \"$ranger_shortcuts\" ; + printf(\"map E%s \$\$EDITOR \42%s\42 \n\",\$1,\$2) >> \"$lf_shortcuts\" }" @@ -0,0 +1,126 @@ +#!/bin/sh + +# Give a file with images and timecodes and creates a video slideshow of them. +# +# Timecodes must be in format 00:00:00. +# +# Imagemagick and ffmpeg required. + +# Application cache if not stated elsewhere. +cache="${XDG_CACHE_HOME:-$HOME/.cache}/slider" + +while getopts "hvrpi:c:a:o:d:f:t:e:x:" o; do case "${o}" in + c) bgc="$OPTARG" ;; + t) fgc="$OPTARG" ;; + f) font="$OPTARG" ;; + i) file="$OPTARG" ;; + a) audio="$OPTARG" ;; + o) outfile="$OPTARG" ;; + d) prepdir="$OPTARG" ;; + r) redo="$OPTARG" ;; + s) ppt="$OPTARG" ;; + e) endtime="$OPTARG" ;; + x) res="$OPTARG" + echo "$res" | grep -qv "^[0-9]\+x[0-9]\+$" && + echo "Resolution must be dimensions separated by a 'x': 1280x720, etc." && + exit 1 ;; + p) echo "Purge old build files in $cache? [y/N]" + read -r confirm + echo "$confirm" | grep -iq "^y$" && rm -rf "$cache" && echo "Done." + exit ;; + v) verbose=True ;; + *) echo "$(basename "$0") usage: + -i input timecode list (required) + -a audio file + -c color of background (use html names, black is default) + -t text color for text slides (white is default) + -s text font size for text slides (150 is default) + -f text font for text slides (sans serif is default) + -o output video file + -e if no audio given, the time in seconds that the last slide will be shown (5 is default) + -x resolution (1920x1080 is default) + -d tmp directory + -r rerun imagemagick commands even if done previously (in case files or background has changed) + -p purge old build files instead of running + -v be verbose" && exit 1 + +esac done + +# Check that the input file looks like it should. +{ head -n 1 "$file" 2>/dev/null | grep -q "^00:00:00 " ;} || { + echo "Give an input file with -i." && + echo "The file should look as this example: + +00:00:00 first_image.jpg +00:00:03 otherdirectory/next_image.jpg +00:00:09 this_image_starts_at_9_seconds.jpg +etc... + +Timecodes and filenames must be separated by Tabs." && + exit 1 + } + +if [ -n "${audio+x}" ]; then + # Check that the audio file looks like an actual audio file. + case "$(file --dereference --brief --mime-type -- "$audio")" in + audio/*) ;; + *) echo "That doesn't look like an audio file."; exit 1 ;; + esac + totseconds="$(date '+%s' -d $(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//))" + endtime="$((totseconds-seconds))" +fi + +prepdir="${prepdir:-$cache/$file}" +outfile="${outfile:-$file.mp4}" +prepfile="$prepdir/$file.prep" + +[ -n "${verbose+x}" ] && echo "Preparing images... May take a while depending on the number of files." +mkdir -p "$prepdir" + +{ +while read -r x; +do + # Get the time from the first column. + time="${x%% *}" + seconds="$(date '+%s' -d "$time")" + # Duration is not used on the first looped item. + duration="$((seconds - prevseconds))" + + # Get the filename/text content from the rest. + content="${x#* }" + base="$(basename "$content")" + base="${base%.*}.jpg" + + if [ -f "$content" ]; then + # If images have already been made in a previous run, do not recreate + # them unless -r was given. + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && + convert -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base" + else + { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && + convert -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -font "${font:-Sans}" -pointsize "${ppt:-150}" -gravity center label:"$content" "$prepdir/$base" + fi + + # If the first line, do not write yet. + [ "$time" = "00:00:00" ] || echo "file '$prevbase' +duration $duration" + + # Keep the information required for the next file. + prevbase="$base" + prevtime="$time" + prevseconds="$(date '+%s' -d "$prevtime")" +done < "$file" +# Do last file which must be given twice as follows +echo "file '$base' +duration ${endtime:-5} +file '$base'" +} > "$prepfile" +if [ -n "${audio+x}" ]; then + ffmpeg -hide_banner -y -f concat -safe 0 -i "$prepfile" -i "$audio" -c:a aac -vsync vfr -c:v libx264 -pix_fmt yuv420p "$outfile" +else + ffmpeg -hide_banner -y -f concat -safe 0 -i "$prepfile" -vsync vfr -c:v libx264 -pix_fmt yuv420p "$outfile" +fi + +# Might also try: +# -vf "fps=${fps:-24},format=yuv420p" "$outfile" +# but has given some problems. diff --git a/statusbar/sb-battery b/statusbar/sb-battery new file mode 100755 index 0000000..93cbe08 --- /dev/null +++ b/statusbar/sb-battery @@ -0,0 +1,37 @@ +#!/bin/sh + +# Prints all batteries, their percentage remaining and an emoji corresponding +# to charge status (π for plugged up, π for discharging on battery, etc.). + +case $BLOCK_BUTTON in + 3) notify-send "π Battery module" "π: discharging +π: not charging +β»: stagnant charge +π: charging +β‘: charged +β: battery very low! +- Scroll to change adjust xbacklight." ;; + 4) xbacklight -inc 10 ;; + 5) xbacklight -dec 10 ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + # If non-first battery, print a space separator. + [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + case "$(cat "$battery/status" 2>&1)" in + "Full") status="β‘" ;; + "Discharging") status="π" ;; + "Charging") status="π" ;; + "Not charging") status="π" ;; + "Unknown") status="β»οΈ" ;; + *) exit 1 ;; + esac + capacity="$(cat "$battery/capacity" 2>&1)" + # Will make a warn variable if discharging and low + [ "$status" = "π" ] && [ "$capacity" -le 25 ] && warn="β" + # Prints the info + printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn +done && printf "\\n" diff --git a/statusbar/sb-clock b/statusbar/sb-clock new file mode 100755 index 0000000..28ce0c7 --- /dev/null +++ b/statusbar/sb-clock @@ -0,0 +1,29 @@ +#!/bin/sh + +clock=$(date '+%I') + +case "$clock" in + "00") icon="π" ;; + "01") icon="π" ;; + "02") icon="π" ;; + "03") icon="π" ;; + "04") icon="π" ;; + "05") icon="π" ;; + "06") icon="π" ;; + "07") icon="π" ;; + "08") icon="π" ;; + "09") icon="π" ;; + "10") icon="π" ;; + "11") icon="π" ;; + "12") icon="π" ;; +esac + +case $BLOCK_BUTTON in + 1) notify-send "This Month" "$(cal --color=always | sed "s/..7m/<b><span color=\"red\">/;s/..27m/<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -d3)" ;; + 2) setsid -f "$TERMINAL" -e calcurse ;; + 3) notify-send "π
Time/date module" "\- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\` +- Middle click opens calcurse if installed" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +date "+%Y %b %d (%a) $icon%R" diff --git a/statusbar/sb-cpu b/statusbar/sb-cpu new file mode 100755 index 0000000..1572b52 --- /dev/null +++ b/statusbar/sb-cpu @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "π₯ CPU hogs" "$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)\\n(100% per core)" ;; + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "π₯ CPU module " "\- Shows CPU temperature. +- Click to show intensive processes. +- Middle click to open htop." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +sensors | awk '/Core 0/ {print "π‘" $3}' diff --git a/statusbar/sb-cpubars b/statusbar/sb-cpubars new file mode 100755 index 0000000..297424e --- /dev/null +++ b/statusbar/sb-cpubars @@ -0,0 +1,44 @@ +#!/bin/sh + +# Module showing CPU load as a changing bars. +# Just like in polybar. +# Each bar represents amount of load on one core since +# last run. + +# Cache in tmpfs to improve speed and reduce SSD load +cache=/tmp/cpubarscache + +case $BLOCK_BUTTON in + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "πͺ¨ CPU load module" "Each bar represents +one CPU core";; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# id total idle +stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) +[ ! -f $cache ] && echo "$stats" > "$cache" +old=$(cat "$cache") +printf "πͺ¨" +echo "$stats" | while read -r row; do + id=${row%% *} + rest=${row#* } + total=${rest%% *} + idle=${rest##* } + + case "$(echo "$old" | awk '{if ($1 == id) + printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ + id="$id" total="$total" idle="$idle")" in + + "0") printf "β";; + "1") printf "β";; + "2") printf "β";; + "3") printf "β";; + "4") printf "β
";; + "5") printf "β";; + "6") printf "β";; + "7") printf "β";; + "8") printf "β";; + esac +done; printf "\\n" +echo "$stats" > "$cache" diff --git a/statusbar/sb-disk b/statusbar/sb-disk new file mode 100755 index 0000000..e947509 --- /dev/null +++ b/statusbar/sb-disk @@ -0,0 +1,23 @@ +#!/bin/sh + +# Status bar module for disk space +# $1 should be drive mountpoint, otherwise assumed /. + +location=${1:-/} + +[ -d "$location" ] || exit + +case $BLOCK_BUTTON in + 1) notify-send "π½ Disk space" "$(df -h --output=target,used,size)" ;; + 3) notify-send "π½ Disk module" "\- Shows used hard drive space. +- Click to show all disk info." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$location" in + "/home"* ) icon="π " ;; + "/mnt"* ) icon="πΎ" ;; + *) icon="π₯";; +esac + +printf "%s: %s\n" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" diff --git a/statusbar/sb-doppler b/statusbar/sb-doppler new file mode 100755 index 0000000..dc93db0 --- /dev/null +++ b/statusbar/sb-doppler @@ -0,0 +1,206 @@ +#!/bin/sh + +# Show a Doppler RADAR of an American user's preferred location. + +secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds. +radarloc="${XDG_CACHE_HOME:-$HOME/.cache}/radar" +doppler="${XDG_CACHE_HOME:-$HOME/.cache}/doppler.gif" + +pickloc() { chosen="$(echo "Northeast +Southeast +PacNorthWest +PacSouthWest +UpperMissVly +SouthMissVly +SouthPlains +NorthRockies +SouthRockies +Alaska +Carib +Hawaii +CentGrLakes +Conus-Large +KABR: Aberdeen, SD +KBIS: Bismarck, ND +KFTG: Denver/Boulder, CO +KDMX: Des Moines, IA +KDTX: Detroit, MI +KDDC: Dodge City, KS +KDLH: Duluth, MN +KCYS: Cheyenne, WY +KLOT: Chicago, IL +KGLD: Goodland, KS +KUEX: Hastings, NE +KGJX: Grand Junction, CO +KGRR: Grand Rapids, MI +KMVX: Fargo/Grand Forks, ND +KGRB: Green Bay, WI +KIND: Indianapolis, IN +KJKL: Jackson, KY +KARX: La Crosse, WI +KILX: Lincoln/Central Illinois, IL +KLVX: Louisville, KY +KMQT: Marquette +KMKX: Milwaukee, WI +KMPX: Minneapolis, MN +KAPX: Gaylord/Alpena, MI +KLNX: North Platte, NE +KIWX: N. Webster/Northern, IN +KOAX: Omaha, NE +KPAH: Paducah, KY +KEAX: Pleasant Hill, MO +KPUX: Pueblo, CO +KDVN: Quad Cities, IA +KUDX: Rapid City, SD +KRIW: Riverton, WY +KSGF: Springfield, MO +KLSX: St. LOUIS, MO +KFSD: Sioux Falls, IA +KTWX: Topeka, KS +KICT: Wichita, KS +KVWX: Paducah, KY +ICAO: Responsible Wfo +KLTX: WILMINGTON, NC +KCCX: State College/Central, PA +KLWX: Sterling, VA +KFCX: Blacksburg/Roanoke, VA +KRAX: Raleigh/Durham, NC +KGYX: Portland, ME +KDIX: Mt Holly/Philadelphia, PA +KPBZ: Pittsburgh, PA +KAKQ: Wakefield, VA +KMHX: Morehead City, NC +KGSP: Greer/Greenville/Sprtbg, SC +KILN: Wilmington/Cincinnati, OH +KCLE: Cleveland, OH +KCAE: Columbia, SC +KBGM: Binghamton, NY +KENX: Albany, NY +KBUF: Buffalo, NY +KCXX: Burlington, VT +KCBW: Caribou, ME +KBOX: Boston /Taunton, MA +KOKX: New York City, NY +KCLX: Charleston, SC +KRLX: Charleston, WV +ICAO: Responsible WFO +KBRO: Brownsville, TX +KABX: Albuquerque, NM +KAMA: Amarillo, TX +KFFC: Peachtree City/Atlanta, GA +KEWX: Austin/Sanantonio, TX +KBMX: Birmingham, AL +KCRP: Corpus Christi, TX +KFWS: Dallas / Ft. Worth, TX +KEPZ: El Paso, TX +KHGX: Houston/ Galveston, TX +KJAX: Jacksonville, FL +KBYX: Key West, FL +KMRX: Morristown/knoxville, TN +KLBB: Lubbock, TX +KLZK: Little Rock, AR +KLCH: Lake Charles, LA +KOHX: Nashville, TN +KMLB: Melbourne, FL +KNQA: Memphis, TN +KAMX: Miami, FL +KMAF: Midland/odessa, TX +KTLX: Norman, OK +KHTX: Huntsville, AL +KMOB: Mobile, AL +KTLH: Tallahassee, FL +KTBW: Tampa Bay Area, FL +KSJT: San Angelo, TX +KINX: Tulsa, OK +KSRX: Tulsa, OK +KLIX: New Orleans/slidell, LA +KDGX: Jackson, MS +KSHV: Shreveport, LA +ICAO: Responsible WFO +KLGX: Seattle / Tacoma, WA +KOTX: Spokane, WA +KEMX: Tucson, AZ +KYUX: Phoenix, AZ +KNKX: San Diego, CA +KMUX: Monterey/san Francisco, CA +KHNX: San Joaquin/hanford, CA +KSOX: San Diego, CA +KATX: Seattle / Tacoma, WA +KIWA: Phoenix, AZ +KRTX: Portland, OR +KSFX: Pocatello, ID +KRGX: Reno, NV +KDAX: Sacramento, CA +KMTX: Salt Lake City, UT +KPDT: Pendleton, OR +KMSX: Missoula, MT +KESX: Las Vegas, NV +KVTX: Los Angeles, CA +KMAX: Medford, OR +KFSX: Flagstaff, AZ +KGGW: Glasgow, MT +KLRX: Elko, NV +KBHX: Eureka, CA +KTFX: Great Falls, MT +KCBX: Boise, ID +KBLX: Billings, MT +KICX: Salt Lake City, UT +ICAO: Responsible Wfo W/ MSCF +PABC: Anchorage, AK +PAPD: Fairbanks, AK +PHKM: Honolulu, HI +PAHG: Anchorage, AK +PAKC: Anchorage, AK +PAIH: Anchorage, AK +PHMO: Honolulu, HI +PAEC: Fairbanks, AK +TJUA: San Juan, PR +PACG: Juneau, AK +PHKI: Honolulu, HI +PHWA: Honolulu, HI +ICAO: Responsible Wfo W/ MSCF +KFDR: Norman, OK +PGUA: Guam +KBBX: Sacramento, CA +KFDX: Albuquerque, NM +KGWX: Jackson, MS +KDOX: Wakefield, VA +KDYX: San Angelo, TX +KEYX: Las Vegas, NV +KEVX: Mobile, AL +KHPX: Paducah, KY +KTYX: Burlington, VT +KGRK: Dallas / Ft. Worth, TX +KPOE: Lake Charles, LA +KEOX: Tallahassee, FL +KHDX: El Paso, TX +KDFX: San Antonio, TX +KMXX: Birmingham, AL +KMBX: Bismarck, ND +KVAX: Jacksonville, FL +KJGX: Peachtree City/atlanta, GA +KVNX: Norman, OK +KVBX: Vandenberg Afb: Orcutt, CA" | dmenu -r -i -l 50 -p "Select a National Weather Service radar to use as default:" | sed "s/:.*//" | tr "[:lower:]" "[:upper:]")" + +# Sanity check of selection and ensure user did not escape. +echo "$chosen" | grep -q "^[A-Z]\+$" && echo "$chosen" > "$radarloc" ;} + +getdoppler() { + loc="$(cat "$radarloc")" + notify-send "π¦οΈ Doppler RADAR" "Pulling most recent Doppler RADAR for $loc." + curl -sL "https://radar.weather.gov/ridge/lite/${loc}_loop.gif" > "$doppler" ;} + +showdoppler() { setsid -f mpv --no-osc --loop=inf --no-terminal "$doppler" ;} + +case $BLOCK_BUTTON in + 1) [ ! -f "$radarloc" ] && pickloc && getdoppler + [ $(($(date '+%s') - $(stat -c %Y "$doppler"))) -gt "$secs" ] && getdoppler + showdoppler ;; + 2) pickloc && getdoppler && showdoppler ;; + 3) notify-send "πΊοΈ Doppler RADAR module" "\- Left click for local Doppler RADAR. +- Middle click to update change RADAR location. +After $secs seconds, new clicks will also automatically update the doppler RADAR." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +echo πΊοΈ diff --git a/statusbar/sb-forecast b/statusbar/sb-forecast new file mode 100755 index 0000000..7b8416e --- /dev/null +++ b/statusbar/sb-forecast @@ -0,0 +1,35 @@ +#!/bin/sh + +# Displays todays precipication chance (β) and daily low (π₯Ά) and high (π). +# Usually intended for the statusbar. + +# If we have internet, get a weather report from wttr.in and store it locally. +# You could set up a shell alias to view the full file in a pager in the +# terminal if desired. This function will only be run once a day when needed. +weatherreport="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" +getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;} + +# Some very particular and terse stream manipulation. We get the maximum +# precipitation chance and the daily high and low from the downloaded file and +# display them with coresponding emojis. +showweather() { printf "%s" "$(sed '16q;d' "$weatherreport" | + grep -wo "[0-9]*%" | sort -rn | sed "s/^/β/g;1q" | tr -d '\n')" +sed '13q;d' "$weatherreport" | grep -o "m\\([-+]\\)*[0-9]\\+" | sed 's/+//g' | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " π₯Ά" $1 "Β°","π" $2 "Β°"}' ;} + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;; + 2) getforecast && showweather ;; + 3) notify-send "π Weather module" "\- Left click for full forecast. +- Middle click to update forecast. +β: Chance of rain/snow +π₯Ά: Daily low +π: Daily high" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# The test if our forcecast is updated to the day. If it isn't download a new +# weather report from wttr.in with the above function. +[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || + getforecast + +showweather diff --git a/statusbar/sb-help-icon b/statusbar/sb-help-icon new file mode 100755 index 0000000..8fa4a52 --- /dev/null +++ b/statusbar/sb-help-icon @@ -0,0 +1,17 @@ +#!/bin/sh + +# The clickable help menu. Middle click to restart wm. + +# If dwm is running, use dwm's readme and restart. +pidof dwm >/dev/null && + READMEFILE=/usr/local/share/dwm/larbs.mom + restartwm() { pkill -HUP dwm ;} || + restartwm() { i3 restart ;} + +case $BLOCK_BUTTON in + 1) groff -mom "${READMEFILE:-${XDG_DATA_HOME:-$HOME/.local/share}/larbs/readme.mom}" -Tpdf | zathura - ;; + 2) restartwm ;; + 3) notify-send "β Help module" "\- Left click to open LARBS guide. +- Middle click to refresh window manager." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac; echo "β" diff --git a/statusbar/sb-internet b/statusbar/sb-internet new file mode 100755 index 0000000..311da78 --- /dev/null +++ b/statusbar/sb-internet @@ -0,0 +1,26 @@ +#!/bin/sh + +# Show wifi πΆ and percent strength or π‘ if none. +# Show π if connected to ethernet or β if none. +# Show π if a vpn connection is active + +case $BLOCK_BUTTON in + 1) connman-gtk; pkill -RTMIN+4 dwmblocks ;; + 3) notify-send "π Internet module" "\- Click to connect +β: wifi disabled +π‘: no wifi connection +πΆ: wifi connection with quality +β: no ethernet +π: ethernet working +π: vpn is active +" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +if grep -xq 'up' /sys/class/net/w*/operstate 2>/dev/null ; then + wifiicon="$(awk '/^\s*w/ { print "πΆ", int($3 * 100 / 70) "% " }' /proc/net/wireless)" +elif grep -xq 'down' /sys/class/net/w*/operstate 2>/dev/null ; then + grep -xq '0x1003' /sys/class/net/w*/flags && wifiicon="π‘ " || wifiicon="β " +fi + +printf "%s%s%s\n" "$wifiicon" "$(sed "s/down/β/;s/up/π/" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/π/" /sys/class/net/tun*/operstate 2>/dev/null)" diff --git a/statusbar/sb-iplocate b/statusbar/sb-iplocate new file mode 100755 index 0000000..02adab8 --- /dev/null +++ b/statusbar/sb-iplocate @@ -0,0 +1,10 @@ +#!/bin/sh + +# Gets your public ip address checks which country you are in and +# displays that information in the statusbar +# +# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ + +ifinstalled "geoip" || exit +addr="$(curl ifconfig.me 2>/dev/null)" || exit +grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//" diff --git a/statusbar/sb-kbselect b/statusbar/sb-kbselect new file mode 100755 index 0000000..f0c923f --- /dev/null +++ b/statusbar/sb-kbselect @@ -0,0 +1,16 @@ +#!/bin/sh +# works on any init system +# requirements: dmenu, xorg-setxkbmap +kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1 + +case $BLOCK_BUTTON in + 1) kb_choice="$(awk '/! layout/{flag=1; next} /! variant/{flag=0} flag {print $2, "- " $1}' /usr/share/X11/xkb/rules/base.lst | dmenu -l 15)" + kb="$(echo "$kb_choice" | awk '{print $3}')" + setxkbmap "$kb" + pkill -RTMIN+30 "${STATUSBAR:-dwmblocks}";; + 3) notify-send "β¨ Keyboard/language module" "$(printf "%s" "\- Current layout: $(setxkbmap -query | grep -oP 'layout:\s*\K\w+')") +- Left click to change keyboard.";; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +echo "$kb" diff --git a/statusbar/sb-mailbox b/statusbar/sb-mailbox new file mode 100755 index 0000000..2132184 --- /dev/null +++ b/statusbar/sb-mailbox @@ -0,0 +1,20 @@ +#!/bin/sh + +# Displays number of unread mail and an loading icon if updating. +# When clicked, brings up `neomutt`. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e neomutt ;; + 2) setsid -f mw -Y >/dev/null ;; + 3) notify-send "π¬ Mail module" "\- Shows unread mail +- Shows π if syncing mail +- Left click opens neomutt +- Middle click syncs mail" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +unread="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l 2>/dev/null)" + +pidof mbsync >/dev/null 2>&1 && icon="π" + +[ "$unread" = "0" ] && [ "$icon" = "" ] || echo "π¬$unread$icon" diff --git a/statusbar/sb-memory b/statusbar/sb-memory new file mode 100755 index 0000000..01d3daf --- /dev/null +++ b/statusbar/sb-memory @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "π§ Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;; + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "π§ Memory module" "\- Shows Memory Used/Total. +- Click to show memory hogs. +- Middle click to open htop." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +free --mebi | sed -n '2{p;q}' | awk '{printf ("π§ %2.2fGiB/%2.2fGiB\n", ( $3 / 1024), ($2 / 1024))}' diff --git a/statusbar/sb-moonphase b/statusbar/sb-moonphase new file mode 100755 index 0000000..fab8b4d --- /dev/null +++ b/statusbar/sb-moonphase @@ -0,0 +1,37 @@ +#!/bin/sh + +# Shows the current moon phase. + +moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" + +[ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || + { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;} + +icon="$(cat "$moonfile")" + +case "$icon" in + π) name="New" ;; + π) name="Waxing Crescent" ;; + π) name="First Quarter" ;; + π) name="Waxing Gibbous" ;; + π) name="Full" ;; + π) name="Waning Gibbous" ;; + π) name="Last Quarter" ;; + π) name="Waning Crescent" ;; + *) exit 1 ;; +esac + +echo "${icon-?}" + +case $BLOCK_BUTTON in + 3) notify-send "π Moon phase module" "Displays current moon phase. +- π: New +- π: Waxing Crescent +- π: First Quarter +- π: Waxing Gibbous +- π: Full +- π: Waning Gibbous +- π: Last Quarter +- π: Waning Crescent" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac diff --git a/statusbar/sb-mpdup b/statusbar/sb-mpdup new file mode 100755 index 0000000..af81a7d --- /dev/null +++ b/statusbar/sb-mpdup @@ -0,0 +1,8 @@ +#!/bin/sh + +# This loop will update the mpd statusbar module whenever a command changes the +# music player's status. mpd must be running on X's start for this to work. + +while : ; do + mpc idle >/dev/null && kill -45 "$(pidof "${STATUSBAR:-dwmblocks}")" || break +done diff --git a/statusbar/sb-music b/statusbar/sb-music new file mode 100755 index 0000000..7ea7032 --- /dev/null +++ b/statusbar/sb-music @@ -0,0 +1,19 @@ +#!/bin/sh + +filter() { mpc | sed "/^volume:/d;s/\\&/&/g;s/\\[paused\\].*/βΈ/g;/\\[playing\\].*/d;/^ERROR/Q" | paste -sd ' ' -;} + +pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & + +case $BLOCK_BUTTON in + 1) mpc status | filter ; setsid -f "$TERMINAL" -e ncmpcpp ;; # right click, pause/unpause + 2) mpc toggle | filter ;; # right click, pause/unpause + 3) mpc status | filter ; notify-send "π΅ Music module" "\- Shows mpd song playing. +- βΈ when paused. +- Left click opens ncmpcpp. +- Middle click pauses. +- Scroll changes track.";; # right click, pause/unpause + 4) mpc prev | filter ;; # scroll up, previous + 5) mpc next | filter ;; # scroll down, next + 6) mpc status | filter ; "$TERMINAL" -e "$EDITOR" "$0" ;; + *) mpc status | filter ;; +esac diff --git a/statusbar/sb-nettraf b/statusbar/sb-nettraf new file mode 100755 index 0000000..eb7a73b --- /dev/null +++ b/statusbar/sb-nettraf @@ -0,0 +1,29 @@ +#!/bin/sh + +# Module showing network traffic. Shows how much data has been received (RX) or +# transmitted (TX) since the previous time this script ran. So if run every +# second, gives network traffic per second. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e bmon ;; + 3) notify-send "π Network traffic module" "π»: Traffic received +πΊ: Traffic transmitted" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +update() { + sum=0 + for arg; do + read -r i < "$arg" + sum=$(( sum + i )) + done + cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/} + [ -f "$cache" ] && read -r old < "$cache" || old=0 + printf %d\\n "$sum" > "$cache" + printf %d\\n $(( sum - old )) +} + +rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) +tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) + +printf "π»%4sB πΊ%4sB\\n" $(numfmt --to=iec $rx) $(numfmt --to=iec $tx) diff --git a/statusbar/sb-news b/statusbar/sb-news new file mode 100755 index 0000000..fe701db --- /dev/null +++ b/statusbar/sb-news @@ -0,0 +1,17 @@ +#!/bin/sh + +# Displays number of unread news items and an loading icon if updating. +# When clicked, brings up `newsboat`. + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e newsboat ;; + 2) setsid -f newsup >/dev/null exit ;; + 3) notify-send "π° News module" "\- Shows unread news items +- Shows π if updating with \`newsup\` +- Left click opens newsboat +- Middle click syncs RSS feeds +<b>Note:</b> Only one instance of newsboat (including updates) may be running at a time." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + + cat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ if($1>0) print "π°" $1}')$(cat "${XDG_CONFIG_HOME:-$HOME/.config}"/newsboat/.update 2>/dev/null)" diff --git a/statusbar/sb-pacpackages b/statusbar/sb-pacpackages new file mode 100755 index 0000000..37ebed3 --- /dev/null +++ b/statusbar/sb-pacpackages @@ -0,0 +1,29 @@ +#!/bin/sh + +# Displays number of upgradeable packages. +# For this to work, have a `pacman -Sy` command run in the background as a +# cronjob every so often as root. This script will then read those packages. +# When clicked, it will run an upgrade via pacman. +# +# Add the following text as a file in /usr/share/libalpm/hooks/statusbar.hook: +# +# [Trigger] +# Operation = Upgrade +# Type = Package +# Target = * +# +# [Action] +# Description = Updating statusbar... +# When = PostTransaction +# Exec = /usr/bin/pkill -RTMIN+8 dwmblocks # Or i3blocks if using i3. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e sb-popupgrade ;; + 2) notify-send "$(/usr/bin/pacman -Qu)" ;; + 3) notify-send "π Upgrade module" "π¦: number of upgradable packages +- Left click to upgrade packages +- Middle click to show upgradable packages" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +pacman -Qu | grep -Fcv "[ignored]" | sed "s/^/π¦/;s/^π¦0$//g" diff --git a/statusbar/sb-popupgrade b/statusbar/sb-popupgrade new file mode 100755 index 0000000..29d6230 --- /dev/null +++ b/statusbar/sb-popupgrade @@ -0,0 +1,9 @@ +#!/bin/sh + +printf "Beginning upgrade.\\n" + +yay -Syu +pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}" + +printf "\\nUpgrade complete.\\nPress <Enter> to exit window.\\n\\n" +read -r _ diff --git a/statusbar/sb-price b/statusbar/sb-price new file mode 100755 index 0000000..42c84c1 --- /dev/null +++ b/statusbar/sb-price @@ -0,0 +1,50 @@ +#!/bin/sh + +# Usage: +# price <url> <Name of currency> <icon> <Price to show in> +# price bat "Basic Attention Token" π¦ +# When the name of the currency is multi-word, put it in quotes. + +[ -z "$3" ] && exit 1 + +# use $4 as currency, if not passed in use "usd" as default +currency="${4:-usd}" +interval="@14d" # History contained in chart preceded by '@' (7d = 7 days) +dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices" +pricefile="$dir/$1-$currency" +chartfile="$dir/$1-$currency-chart" + +updateprice() { temp="$(mktemp)" + curl -s "$currency.rate.sx/1$1" > "$temp" && + mv -f "$temp" "$pricefile" && + curl -s "$currency.rate.sx/$1$interval" > "$temp" && + mv -f "$temp" "$chartfile" ;} + +[ -d "$dir" ] || mkdir -p "$dir" + +[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && + updateprice "$1" + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; + 2) notify-send -u low "$3 Updating..." "Updating $2 price..." + updateprice "$1" && notify-send "$3 Update complete." "$2 price is now +\$$(cat "$pricefile")" ;; + 3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")" + notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b> +- Left click for chart of changes. +- Middle click to update. +- Shows π if updating prices. +- <b>Last updated: + $uptime</b>" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +case "$currency" in + usd) symb="$" ;; + gbp) symb="Β£" ;; + eur) symb="β¬" ;; + btc) symb="βΏ" ;; +esac + +printf "$3$symb%0.2f$after" "$(cat "$pricefile")" diff --git a/statusbar/sb-tasks b/statusbar/sb-tasks new file mode 100755 index 0000000..586300e --- /dev/null +++ b/statusbar/sb-tasks @@ -0,0 +1,20 @@ +#!/bin/sh + +# Originally by Andr3as07 <https://github.com/Andr3as07> +# Some changes by Luke +# Rebuild by Tenyun + +# This block displays the number running background tasks. Requires tsp. + +num=$(tsp -l | awk -v numr=0 -v numq=0 '{if (/running/)numr++; if (/queued/)numq++} END{print numr+numq"("numq")"}') + +# Handle mouse clicks +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e tsp -l ;; + 3) notify-send "Tasks module" "π€: number of running/queued background tasks +- Left click opens tsp" ;; # Right click + 2) $EDITOR "$0" ;; # Middle click +esac + +[ "$num" != "0(0)" ] && + echo "π€$num" diff --git a/statusbar/sb-torrent b/statusbar/sb-torrent new file mode 100755 index 0000000..6527005 --- /dev/null +++ b/statusbar/sb-torrent @@ -0,0 +1,27 @@ +#!/bin/sh + +transmission-remote -l | grep % | + sed " # The letters are for sorting and will not appear. + s/.*Stopped.*/A π/; + s/.*Seeding.*/Z π±/; + s/.*100%.*/N β
/; + s/.*Idle.*/B π°οΈ/; + s/.*Uploading.*/L β¬οΈ/; + s/.*%.*/M β¬οΈ/" | + sort -h | uniq -c | awk '{print $3 $1}' | paste -sd ' ' - + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e tremc ;; + 2) td-toggle ;; + 3) notify-send "π± Torrent module" "\- Left click to open tremc. +- Middle click to toggle transmission. +- Shift click to edit script. +Module shows number of torrents: +π: paused +π°: idle (seeds needed) +πΌ: uploading (unfinished) +π½: downloading +β
: done +π±: done and seeding" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac diff --git a/statusbar/sb-volume b/statusbar/sb-volume new file mode 100755 index 0000000..3cfdc45 --- /dev/null +++ b/statusbar/sb-volume @@ -0,0 +1,30 @@ +#!/bin/sh + +# Prints the current volume or π if muted. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e pulsemixer ;; + 2) pamixer -t ;; + 4) pamixer --allow-boost -i 1 ;; + 5) pamixer --allow-boost -d 1 ;; + 3) notify-send "π’ Volume module" "\- Shows volume π, π if muted. +- Middle click to mute. +- Scroll to change." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +[ $(pamixer --get-mute) = true ] && echo π && exit + +vol="$(pamixer --get-volume)" + +if [ "$vol" -gt "70" ]; then + icon="π" +elif [ "$vol" -gt "30" ]; then + icon="π" +elif [ "$vol" -gt "0" ]; then + icon="π" +else + echo π && exit +fi + +echo "$icon$vol%" @@ -0,0 +1,18 @@ +#!/bin/sh +# A dmenu wrapper script for system functions. +case "$(readlink -f /sbin/init)" in + *systemd*) ctl='systemctl' ;; + *) ctl='loginctl' ;; +esac + +case "$(printf "π lock\nπͺ leave dwm\nβ»οΈ renew dwm\nπ» hibernate\nπ€ sleep\nπ reboot\nπ₯οΈshutdown\nπΊ display off" | dmenu -i -p 'Action: ')" in + 'π lock') slock ;; + 'πͺ leave dwm') kill -TERM "$(pgrep -u "$USER" "\bdwm$")" ;; + 'β»οΈ renew dwm') kill -HUP "$(pgrep -u "$USER" "\bdwm$")" ;; + 'π» hibernate') slock $ctl hibernate ;; + 'π€ sleep') slock $ctl suspend -i ;; + 'π reboot') $ctl reboot ;; + 'π₯οΈshutdown') $ctl poweroff ;; + 'πΊ display off') xset dpms force off ;; + *) exit 1 ;; +esac @@ -0,0 +1,67 @@ +#!/bin/sh + +err() { echo "Usage: + tag [OPTIONS] file +Options: + -a: artist/author + -t: song/chapter title + -A: album/book title + -n: track/chapter number + -N: total number of tracks/chapters + -d: year of publication + -g: genre + -c: comment +You will be prompted for title, artist, album and track if not given." && exit 1 ;} + +while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in + a) artist="${OPTARG}" ;; + t) title="${OPTARG}" ;; + A) album="${OPTARG}" ;; + n) track="${OPTARG}" ;; + N) total="${OPTARG}" ;; + d) date="${OPTARG}" ;; + g) genre="${OPTARG}" ;; + c) comment="${OPTARG}" ;; + f) file="${OPTARG}" ;; + *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; +esac done + +shift $((OPTIND - 1)) + +file="$1" + +[ ! -f "$file" ] && echo "Provide file to tag." && err + +[ -z "$title" ] && echo "Enter a title." && read -r title +[ -z "$artist" ] && echo "Enter an artist." && read -r artist +[ -z "$album" ] && echo "Enter an album." && read -r album +[ -z "$track" ] && echo "Enter a track number." && read -r track + +case "$file" in + *.ogg) echo "Title=$title +Artist=$artist +Album=$album +Track=$track +Total=$total +Date=$date +Genre=$genre +Comment=$comment" | vorbiscomment -w "$file" ;; + *.opus) echo "Title=$title +Artist=$artist +Album=$album +Track=$track +Total=$total +Date=$date +Genre=$genre +Comment=$comment" | opustags -i -S "$file" ;; + *.mp3) eyeD3 -Q --remove-all -a "$artist" -A "$album" -t "$title" -n "$track" -N "$total" -Y "$date" "$file" ;; + *.flac) echo "TITLE=$title +ARTIST=$artist +ALBUM=$album +TRACKNUMBER=$track +TOTALTRACKS=$total +DATE=$date +GENRE=$genre +DESCRIPTION=$comment" | metaflac --remove-all-tags --import-tags-from=- "$file" ;; + *) echo "File type not implemented yet." ;; +esac diff --git a/td-toggle b/td-toggle new file mode 100755 index 0000000..3c20ea1 --- /dev/null +++ b/td-toggle @@ -0,0 +1,12 @@ +#!/bin/sh + +# If transmission-daemon is running, will ask to kill, else will ask to start. + +if pidof transmission-daemon >/dev/null ; +then + [ "$(printf "No\\nYes" | dmenu -i -p "Turn off transmission-daemon?")" = "Yes" ] && killall transmission-da && notify-send "transmission-daemon disabled." +else + ifinstalled transmission-cli || exit + [ "$(printf "No\\nYes" | dmenu -i -p "Turn on transmission daemon?")" = "Yes" ] && transmission-daemon && notify-send "transmission-daemon enabled." +fi +sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" diff --git a/texclear b/texclear new file mode 100755 index 0000000..f38f7be --- /dev/null +++ b/texclear @@ -0,0 +1,16 @@ +#!/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|pyg|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 + rm -rdf "$dir/_minted-$(basename -- $base)" + ;; + *) printf "Give .tex file as argument.\\n" ;; +esac + @@ -0,0 +1,7 @@ +#!/bin/sh + +ifinstalled tremc transmission-cli || exit + +! pidof transmission-daemon >/dev/null && transmission-daemon && notify-send "Starting torrent daemon..." + +$TERMINAL -e tremc; pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" diff --git a/transadd b/transadd new file mode 100755 index 0000000..a598fad --- /dev/null +++ b/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, hence the sleep. + +pidof transmission-daemon >/dev/null || (transmission-daemon && notify-send "Starting transmission daemon..." && sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}") + +transmission-remote -a "$@" && notify-send "π½ Torrent added." diff --git a/tutorialvids b/tutorialvids new file mode 100755 index 0000000..91ad5b0 --- /dev/null +++ b/tutorialvids @@ -0,0 +1,26 @@ +#!/bin/sh + +# This gives the user a list of videos they can select and watch without a +# browser. If you want to check a tutorial video, it makes it easy. I'll +# add/remove videos from this list as I go on. + +vidlist=" +dwm (window manager) https://videos.lukesmith.xyz/videos/watch/f6b78db7-b368-4647-bc64-28c08fff1988 +pacman (installing/managing programs) https://videos.lukesmith.xyz/videos/watch/8e7cadb9-0fed-47ce-a2a8-6635fa48614b +status bar https://videos.lukesmith.xyz/videos/watch/a4d5326b-0aac-496e-bfc3-5acd5cee89f0 +sxiv (image viewer) https://videos.lukesmith.xyz/videos/watch/ad4c8d85-90c3-4f3d-a1f3-89129e64a3c2 +st (terminal) https://videos.lukesmith.xyz/videos/watch/efddd39d-bac5-4599-b572-177beb4ce6e8 +i3 (old window manager) https://videos.lukesmith.xyz/videos/watch/b861525c-7ada-40ee-a2bb-b5e1ffe0f48b +neomutt (email) https://videos.lukesmith.xyz/videos/watch/83122e83-52d9-4278-ae1a-7d1beeb50c8e +ncmpcpp (music player) https://videos.lukesmith.xyz/videos/watch/b5ac6f0d-a220-4433-88e3-e98fc791dc0a +newsboat (RSS reader) https://videos.lukesmith.xyz/videos/watch/bd2c3fff-40fa-47ea-aa98-5b1ec0c903b6 +ranger (file manager) https://videos.lukesmith.xyz/videos/watch/785d914f-8cbd-4a3d-a1f6-d75675fc7549 +zathura (pdf viewer) https://videos.lukesmith.xyz/videos/watch/c780f75a-11f6-48a9-a191-d079ebc36ea4 +gpg keys https://videos.lukesmith.xyz/videos/watch/040f5530-4830-4583-9ddc-2080b421531b +calcurse (calendar) https://videos.lukesmith.xyz/videos/watch/4b937e8b-7654-46e3-8d01-79392ec5b3d1 +urlview https://videos.lukesmith.xyz/videos/watch/31a4918f-633b-4bd6-b08e-956ac75d0324 +colorschemes with pywal https://videos.lukesmith.xyz/videos/watch/1b476003-61b2-4609-ac4b-820c3d128643 +vi mode in shell https://videos.lukesmith.xyz/videos/watch/228aa50c-836f-456f-9f0d-a45157fe4313 +pass (password manager) https://videos.lukesmith.xyz/videos/watch/432fc942-5e28-4682-9beb-f5cb237a1dd6 +" +echo "$vidlist" | grep -P "^$(echo "$vidlist" | grep "https:" | sed 's/\t.*//g' | dmenu -i -p "Learn about what? (ESC to cancel)" -l 20 | awk '{print $1}')\s" | sed 's/.*\t//' | xargs -r mpv @@ -0,0 +1,26 @@ +#!/bin/sh + +#original artwork by http://www.sanderfocus.nl/#/portfolio/tech-heroes +#converted to shell by #nixers @ irc.unix.chat + +cat << 'eof' + [38;5;255m,_ ,_==ββ[0m + [38;5;255m, βββββ
β
[48;5;240mβ
[48;5;20mβ[48;5;240mβ
ΒΎ[0m. [38;5;199m/ [38;5;20m/[0m + [38;5;255m[48;5;20mβ[0m[38;5;255m[48;5;199mβ[38;5;16m[48;5;255m<Β΄ [38;5;32m"[38;5;34mΒ»[38;5;255mββ[48;5;32mβ[48;5;240m%[0m\ [38;5;199m/ [38;5;20m/ [38;5;45m/ [38;5;118m/[0m + [38;5;255m,[38;5;255m[48;5;240mβ
[38;5;16m[48;5;255m7" [38;5;160mΒ΄[38;5;34m>[38;5;255m[48;5;39mββ[38;5;199m[48;5;255mβ[0m[38;5;255m% [38;5;20m/ [38;5;118m/ [38;5;199m> [38;5;118m/ [38;5;199m>[38;5;255m/[38;5;45m%[0m + [38;5;255mβ[48;5;240m[38;5;255mΒΆ[48;5;240m[38;5;255mβ[48;5;255m [38;5;196m,[38;5;34mΒ»[48;5;201m[38;5;255mββ[0m[38;5;255mΒΎΒ΄[0m [38;5;199m/[38;5;255m> %[38;5;199m/[38;5;118m%[38;5;255m/[38;5;199m/ [38;5;45m/ [38;5;199m/[0m + [38;5;255m[48;5;240mβ[48;5;255m[38;5;16mβ[48;5;16m[38;5;255mβ
β
[38;5;16m[48;5;255mβ
β,,[38;5;32mβ[38;5;16mβ
[38;5;255m[48;5;16mβ
β
[38;5;255m[48;5;20mΓ[0m[38;5;255m\[0m[38;5;20m/[38;5;118m/[38;5;255m /[38;5;118m/[38;5;199m/[38;5;255m>[38;5;45m// [38;5;255m/[38;5;118m>[38;5;199m/ [38;5;20m/[0m + [48;5;20m[38;5;255mV[48;5;255m[38;5;16mβ[48;5;20m[38;5;255mΒ«[0m[38;5;255mΒΌ.;[48;5;240m[38;5;255mβ[48;5;255m[38;5;16m β[0m[38;5;255m<Β«.,[48;5;25m[38;5;255m`[48;5;240m=[0m[38;5;20m/[38;5;199m/ [38;5;255m/>[38;5;45m/[38;5;118m/[38;5;255m%/[38;5;199m% / [38;5;20m/[0m + [38;5;20m//[48;5;255m[38;5;16mβ <Β΄ -Β²,)[48;5;16m[38;5;255m(β[48;5;255m[38;5;16m~"-[38;5;199mβ/[0m[38;5;255mΒΎ[0m[38;5;199m/ [38;5;118m%[38;5;255m/[38;5;118m>[38;5;45m/ [38;5;118m/[38;5;199m>[0m + [38;5;20m/ / [38;5;118m/ [48;5;20m[38;5;255mβ[48;5;240m[38;5;16m%[48;5;255m -./βββ[48;5;16m[38;5;255mβ
[48;5;255m[38;5;16mβ[48;5;255m[38;5;16m, [38;5;199m/[48;5;199m[38;5;255m7[0m[38;5;20m/[38;5;199m/[38;5;255m;/[38;5;199m/[38;5;118m% [38;5;20m/ /[0m + [38;5;20m/ [38;5;199m/[38;5;255m/[38;5;45m/[38;5;118m/[38;5;255m[48;5;240m`[48;5;20m[38;5;255mβ[48;5;20m[38;5;255mβ[48;5;255m[38;5;16m %z[0m[38;5;255mWv xX[48;5;20m[38;5;255mβ[48;5;34m[38;5;255mβ[48;5;199m[38;255mβ[0m[38;5;20m/[38;5;199m/[38;5;255m&;[38;5;20m% [38;5;199m/ [38;5;20m/[0m + [38;5;20m/ / [38;5;255m/ [38;5;118m%[38;5;199m/[38;5;255m/%/[48;5;240m[38;5;255mΒΎ[48;5;255m[38;5;16mΒ½Β΄[38;5;255m[48;5;16mβ[0m[38;5;246mββ[38;5;255mββ[38;5;246mβββ[0m[48;5;16m[38;5;255mβ[38;5;255m[48;5;199mΒΆ[48;5;20m[38;5;255m\[0m[38;5;20m/[0m[48;5;255m[38;5;240m&[0m [38;5;20m/[0m + [38;5;199m<[38;5;118m/ [38;5;45m/[38;5;255m</[38;5;118m%[38;5;255m/[38;5;45m/[38;5;255m`[48;5;16mβ[48;5;255m[38;5;16m