commit 5524a87b0d5b2bfcdeb073ef1e1cdd9d7c9f5193 Author: Solomon Laing Date: Wed Aug 25 14:16:40 2021 +0930 Initial commit diff --git a/dec-sink-volume b/dec-sink-volume new file mode 100755 index 0000000..0767bf6 --- /dev/null +++ b/dec-sink-volume @@ -0,0 +1,11 @@ +#!/bin/bash + +default_loc=/tmp/pactl-default-sink + +if [ ! -f "$default_loc" ] ; then + /home/solomon/.local/bin/set-default-sink +fi + +default=$(cat $default_loc) + +pactl set-sink-volume $default -5% diff --git a/dec-source-volume b/dec-source-volume new file mode 100755 index 0000000..f742674 --- /dev/null +++ b/dec-source-volume @@ -0,0 +1,11 @@ +#!/bin/bash + +default_loc=/tmp/pactl-default-source + +if [ ! -f "$default_loc" ] ; then + /home/solomon/.local/bin/set-default-source +fi + +default=$(cat $default_loc) + +pactl set-source-volume $default -5% diff --git a/dmenumount b/dmenumount new file mode 100755 index 0000000..b98b6a3 --- /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 + [ "$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/dmenusearch b/dmenusearch new file mode 100755 index 0000000..015e37c --- /dev/null +++ b/dmenusearch @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +# +# Script name: dmenusearch +# Description: Search various search engines (inspired by surfraw). +# Dependencies: dmenu and a web browser +# Usage: dmenusearch +# where engine is amazon, duckduckgo, etc. +# without engine all options will be listed + +# Pilfered from Derek Taylor @ https://www.gitlab.com/dwt1/dmscripts + +# Contributors: Derek Taylor +# Ali Furkan Yıldız + +# Defining our web browser. +DMBROWSER="${BROWSER:-surf}" + +# An array of search engines. You can edit this list to add/remove +# search engines. The format must be: "engine_name]="url". +# The url format must allow for the search keywords at the end of the url. +# For example: https://www.amazon.com/s?k=XXXX searches Amazon for 'XXXX'. +declare -A options +options[amazon]="https://www.amazon.com/s?k=" +options[archaur]="https://aur.archlinux.org/packages/?O=0&K=" +options[archpkg]="https://archlinux.org/packages/?sort=&q=" +options[archwiki]="https://wiki.archlinux.org/index.php?search=" +options[arxiv]="https://arxiv.org/search/?searchtype=all&source=header&query=" +options[bbcnews]="https://www.bbc.co.uk/search?q=" +options[bing]="https://www.bing.com/search?q=" +options[cliki]="https://www.cliki.net/site/search?query=" +options[cnn]="https://www.cnn.com/search?q=" +options[coinbase]="https://www.coinbase.com/price?query=" +options[debianpkg]="https://packages.debian.org/search?suite=default§ion=all&arch=any&searchon=names&keywords=" +options[discogs]="https://www.discogs.com/search/?&type=all&q=" +options[duckduckgo]="https://duckduckgo.com/?q=" +options[ebay]="https://www.ebay.com/sch/i.html?&_nkw=" +options[github]="https://github.com/search?q=" +options[gitlab]="https://gitlab.com/search?search=" +options[imdb]="https://www.imdb.com/find?q=" +options[lbry]="https://lbry.tv/$/search?q=" +options[odysee]="https://odysee.com/$/search?q=" +options[reddit]="https://www.reddit.com/search/?q=" +options[slashdot]="https://slashdot.org/index2.pl?fhfilter=" +options[socialblade]="https://socialblade.com/youtube/user/" +options[sourceforge]="https://sourceforge.net/directory/?q=" +options[stack]="https://stackoverflow.com/search?q=" +options[startpage]="https://www.startpage.com/do/dsearch?query=" +options[stockquote]="https://finance.yahoo.com/quote/" +options[thesaurus]="https://www.thesaurus.com/misspelling?term=" +options[translate]="https://translate.google.com/?sl=auto&tl=en&text=" +options[urban]="https://www.urbandictionary.com/define.php?term=" +options[wayback]="https://web.archive.org/web/*/" +options[webster]="https://www.merriam-webster.com/dictionary/" +options[wikipedia]="https://en.wikipedia.org/wiki/" +options[wiktionary]="https://en.wiktionary.org/wiki/" +options[wolfram]="https://www.wolframalpha.com/input/?i=" +options[youtube]="https://www.youtube.com/results?search_query=" +options[google]="https://www.google.com/search?q=" +options[googleimages]="https://www.google.com/search?hl=en&tbm=isch&q=" +options[googlenews]="https://news.google.com/search?q=" +options[googleSupport]="https://support.google.com/search?q=" +options[googleSupportAdmin]="https://support.google.com/a/search?q=" +options[googleStructuredData]="https://search.google.com/structured-data/testing-tool#url=" +options[googleRichResults]="https://search.google.com/test/rich-results??url=" +options[googlePagespeed]="https://developers.google.com/speed/pagespeed/insights/?url=" +options[googleDevelopers]="https://developers.google.com/s/results?q=" +options[googleOpenSource]="https://opensource.google/projects/search?q=" +options[googleExperimentswithGoogle]="https://experiments.withgoogle.com/search?q=" +options[googleDataset]="https://datasetsearch.research.google.com/search?query=" + +if [ -z "$1" ]; then + # Picking a search engine. + # shellcheck disable=SC2154 + while [ -z "$engine" ]; do + engine=$(printf '%s\n' "${!options[@]}" | sort | dmenu -i -p 'Choose search engine:') "$@" || exit + url="${options["${engine}"]}" || exit + done +else + engine="$1" +fi + +url="${options["${engine}"]}" || exit + +# Searching the chosen engine. +# shellcheck disable=SC2154 +while [ -z "$query" ]; do + query=$(echo "$engine" | dmenu -p 'Enter search query:') || exit +done + +# Display search results in web browser +$DMBROWSER "$url""$query" diff --git a/dmenuumount b/dmenuumount new file mode 100755 index 0000000..26612ef --- /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" | awk '$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') + +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/ext b/ext new file mode 100755 index 0000000..927fb5b --- /dev/null +++ b/ext @@ -0,0 +1,45 @@ +#!/bin/sh + +# A general, all-purpose extraction script. Not all extraction programs here +# are installed by LARBS automatically. +# +# 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 1 ;; +esac done + +if [ -z "$extracthere" ]; then + archive="$(readlink -f "$*")" && + directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && + mkdir -p "$directory" && + cd "$directory" || exit 1 +else + archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)" +fi + +[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1 + +if [ -f "$archive" ] ; then + case "$archive" in + *.tar.bz2|*.tbz2) tar xvjf "$archive" ;; + *.tar.xz) tar -xf "$archive" ;; + *.tar.gz|*.tgz) tar xvzf "$archive" ;; + *.tar.zst) tar -I zstd -xf "$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/inc-sink-volume b/inc-sink-volume new file mode 100755 index 0000000..002d960 --- /dev/null +++ b/inc-sink-volume @@ -0,0 +1,11 @@ +#!/bin/bash + +default_loc=/tmp/pactl-default-sink + +if [ ! -f "$default_loc" ] ; then + /home/solomon/.local/bin/set-default-sink +fi + +default=$(cat $default_loc) + +pactl set-sink-volume $default +5% diff --git a/inc-source-volume b/inc-source-volume new file mode 100755 index 0000000..32176d7 --- /dev/null +++ b/inc-source-volume @@ -0,0 +1,11 @@ +#!/bin/bash + +default_loc=/tmp/pactl-default-source + +if [ ! -f "$default_loc" ] ; then + /home/solomon/.local/bin/set-default-source +fi + +default=$(cat $default_loc) + +pactl set-source-volume $default +5% diff --git a/mod_backlight b/mod_backlight new file mode 100755 index 0000000..116b7c7 --- /dev/null +++ b/mod_backlight @@ -0,0 +1,5 @@ +#!/bin/bash + +if command -v backlight_control &> /dev/null; then + backlight_control $1 +fi \ No newline at end of file diff --git a/prompt b/prompt new file mode 100755 index 0000000..afb24a4 --- /dev/null +++ b/prompt @@ -0,0 +1,21 @@ +#!/bin/bash + +# A dmenu binary prompt script. +# Gives a dmenu prompt labelled with $1 to perform command $2. +# To invert the options, simply provide a thrid parameter $3. +# For example: +# `./prompt "Do you want to shutdown?" "shutdown now"` + +# Taken shamelessly from Luke Smith + +if [ -n "$3" ] +then + choice=$(echo -e "Yes\nNo" | dmenu -bw 0 -i -p "$1") +else + choice=$(echo -e "No\nYes" | dmenu -bw 0 -i -p "$1") +fi + +if [ $choice = "Yes" ] +then + $2 +fi diff --git a/rssadd b/rssadd new file mode 100755 index 0000000..fb60be8 --- /dev/null +++ b/rssadd @@ -0,0 +1,18 @@ +#!/bin/sh + +if echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" >/dev/null; then + url="$1" +else + url="$(grep -Eom1 '<[^>]+(rel="self"|application/[a-z]+\+xml)[^>]+>' "$1" | + sed -E 's_^.*href="(https?://[^"]+)".*$_\1_')" + + ! grep "https*://\S\+\.[A-Za-z]\+\S*" <<<"$url" && + 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 diff --git a/set-default-sink b/set-default-sink new file mode 100755 index 0000000..212bae9 --- /dev/null +++ b/set-default-sink @@ -0,0 +1,13 @@ +#!/bin/bash + +choice=$(pactl list short sinks | awk '{print $2}' | dmenu -i -p "which sink should be default?") + +if [ -z "$choice" ] ; then + exit 0; +fi + + +rm /tmp/pactl-default-sink --force # to ignore if it isn't there +touch /tmp/pactl-default-sink +echo "$choice" > /tmp/pactl-default-sink +pactl set-default-sink $choice # make sure that the chosen sink is the \ No newline at end of file diff --git a/set-default-source b/set-default-source new file mode 100755 index 0000000..a5f6f62 --- /dev/null +++ b/set-default-source @@ -0,0 +1,13 @@ +#!/bin/bash + +choice=$(pactl list short sources | awk '{print $2}' | dmenu -i -p "which source should be default?") + +if [ -z "$choice" ] ; then + exit 0; +fi + + +rm /tmp/pactl-default-source --force # to ignore if it isn't there +touch /tmp/pactl-default-source +echo "$choice" > /tmp/pactl-default-source +pactl set-default-source $choice # make sure that the chosen sink is the \ No newline at end of file diff --git a/toggle-sink-mute b/toggle-sink-mute new file mode 100755 index 0000000..50d9281 --- /dev/null +++ b/toggle-sink-mute @@ -0,0 +1,11 @@ +#!/bin/bash + +default_loc=/tmp/pactl-default-sink + +if [ ! -f "$default_loc" ] ; then + /home/solomon/.local/bin/set-default-card +fi + +default=$(cat $default_loc) + +pactl set-sink-mute $default toggle diff --git a/toggle-source-mute b/toggle-source-mute new file mode 100755 index 0000000..d819318 --- /dev/null +++ b/toggle-source-mute @@ -0,0 +1,11 @@ +#!/bin/bash + +default_loc=/tmp/pactl-default-source + +if [ ! -f "$default_loc" ] ; then + /home/solomon/.local/bin/set-default-source +fi + +default=$(cat $default_loc) + +pactl set-source-mute $default toggle diff --git a/xmonad-keys b/xmonad-keys new file mode 100755 index 0000000..1916947 --- /dev/null +++ b/xmonad-keys @@ -0,0 +1,12 @@ +#!/bin/bash + +sed -n '/--START_KEYS/,/--END_KEYS/p' $HOME/.xmonad/xmonad.hs | \ + grep -e ', ("' \ + -e '\[ ("' \ + -e '--NOTE' | \ + grep -v '\-\- , ' |\ + sed -e 's/^[ \t,]*//' \ + -e 's/\[ (/(/' \ + -e 's/--NOTE /\n/' \ + -e 's/, / --> /' | \ + yad --text-info --back=#121e32 --fore=#dfdfef --geometry=1200x800 \ No newline at end of file