bin: delete unneeded scripts

They're more suited for window manager-specific setups plus I could just
recreate them.
This commit is contained in:
Gabriel Arazas 2023-07-25 18:24:25 +08:00
parent 3928d43a20
commit d56e7c9552
11 changed files with 0 additions and 556 deletions

View File

@ -1,6 +0,0 @@
#!/usr/bin/env sh
# This is the askpass program that `sudo -a` uses.
# This script should be set with the `SUDO_ASKPASS` environment variable.
rofi -theme dmenu -dmenu -p "Password: " -password

View File

@ -1,31 +0,0 @@
#!/usr/bin/env nix-shell
#! nix-shell --pure -i bash -p mktemp wget gnused gawk rofi xclip libnotify
# Simply create a universal emoji selection list.
# The emoji list should be the following file:
# https://unicode.org/Public/emoji/13.0/emoji-test.txt
# Dependencies:
# * mktemp - GNU coreutils 8.31
# * wget - GNU Wget 1.20.3
# * sed - GNU sed 4.8
# * awk - GNU Awk 5.0.1
# * rofi - Version: 1.5.4
# * xclip - version 0.13
emoji_file="${XDG_DATA_HOME:-$HOME/.local/share}/emoji-list.txt"
# Checks if the emoji file is non-existent or past its modification date of at least 30 days ago (2592000 seconds).
if [[ ! -f $emoji_file ]] || test $(expr $(date "+%s") - $(date --reference="$emoji_file" "+%s")) -gt 2592000; then
notify-send "Downloading the emoji data file."
wget --output-document "$emoji_file" https://unicode.org/Public/emoji/latest/emoji-test.txt
touch $emoji_file
fi
selection=$(awk 'match($0, /([0-9A-F ]+)\s+; fully-qualified\s+# (\S+) E[[:digit:]]+.[[:digit:]]+ (.+)$/, a){print a[2], a[3]}' "$emoji_file" \
| rofi -dmenu -i -matching fuzzy -p "Choose an emoji to copy." \
| awk '{print $1}')
if [ -n "$selection" ]; then
printf "%s" "$selection" | xclip -selection clipboard && notify-send "'$(xclip -o -selection clipboard)' has been copied to clipboard."
fi

View File

@ -1,22 +0,0 @@
#!/usr/bin/env sh
# This is based from the `mansplain` script by Luke Smith.
# Video reference is at https://www.youtube.com/watch?v=8E8sUNHdzG8.
# There's not much room for customizability so you'll have to edit the script itself if you want something different.
# Minimum requirements as of writing this script at 2019-12-18:
# * man - v2.9.0
# * xargs - v4.7.0
# * rofi - v1.5.4
# * awk - v5.0.1
# Optional dependencies:
# * zathura - v0.4.4
# * girara - v0.3.3
# * pdf-mupdf - v0.3.5
set -o pipefail
man -k . | rofi -dmenu -p 'Choose a manual' | awk '{print $1}' | xargs --no-run-if-empty "$TERMINAL" --command man

View File

@ -1,51 +0,0 @@
#!/usr/bin/env oil
# Create an interface for select Unicode characters with rofi and copy it into the clipboard.
# The characters are extracted from the Unicode Character Database (https://www.unicode.org/ucd/).
# It requires a tag name or an XPath similarly used for Python's `xml.etree.ElementTree.Element.findall`.
# See the following link for more information.
# (https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.findall)
# Dependencies:
# * Oil shell
# * curl
# * python (at least v3.7)
# * rofi
# * awk
# Set to use Oil features and strictness.
shopt --set strict:all
var QUERY = ARGV[0]
var UCD_VERSION = "13.0.0"
var UCD_XML_URL = "https://www.unicode.org/Public/$UCD_VERSION/ucdxml/ucd.nounihan.grouped.zip"
var CACHE = ${XDG_CACHE_DIR:-$HOME/.cache/unicode-character-database}
mkdir -p $CACHE
if test ! -f $CACHE/ucd.zip {
curl $UCD_XML_URL --output $CACHE/ucd.zip --silent
}
# The remaining thing is coded with Python because I want to use the UCD with no Unihan data and the grouped variation.
# Compared to the other variations, it is only ~6MB compared to ~55MB for the flat variation.
# Also, it requires more conditional handling than a simple shell script at this point.
# I could've made this script entirely in Python but I want to see what Oil shell is capable of.
python <<CODE | rofi -dmenu -p "Choose character" | awk '{ print $1 }' | xclip -selection clipboard
import xml.etree.ElementTree as ET
root = ET.fromstring('''$(unzip -p $CACHE/ucd.zip ucd.nounihan.grouped.xml)''')
# Print '<char>' and recurse into '<group>'.
def print_char(element):
if element.tag == '{http://www.unicode.org/ns/2003/ucd/1.0}char':
alias = element.get('na') if element.get('na') else element.get('na1')
codepoint = int(element.get('cp'), 16)
print("{code} {alias}".format(code=chr(codepoint), alias=alias))
elif element.tag == '{http://www.unicode.org/ns/2003/ucd/1.0}group':
for child in list(element):
print_char(child)
valid_nodes = root.findall('${QUERY}')
for point in valid_nodes:
print_char(point)
CODE

View File

@ -1,18 +0,0 @@
#!/usr/bin/env bash
# Selects the region, echoes the hex string (in RGBA format) of the average color of the region.
# Depedencies:
# * maim v5.6.3
# * ImageMagick 7.0.10
# It's a small script and the main code is a chain of commands so a pipeline fail is appropriate here.
set -o pipefail
# Make some form of user feedback.
notify-send "Select a region for color picking."
# The color picker code.
# Take note it uses a slop shader named `crosshair` from the shader examples of the official repo at https://github.com/naelstrof/slop.
maim --select --shader crosshair --tolerance 0 --hidecursor | magick convert - -resize 1x1\! -format '%[hex:p{0,0}]' info:-

View File

@ -1,26 +0,0 @@
#!/usr/bin/env sh
# Extracts the archive.
# The process can vary depending on the file extension.
# Dependencies:
# * tar (GNU tar) 1.32
# Extract each given filename.
for f in $@; do
if [ -n "$(file "$f" | grep -i '7-zip archive data')" ]; then
7z x "$f"
elif [ -n "$(file "$f" | grep -i 'zip archive data')" ]; then
unzip "$f"
elif [ -n "$(file "$f" | grep -i 'POSIX tar archive')" ]; then
tar --extract --file $f # or 'tar xf $f'
elif [ -n "$(file "$f" | grep -i 'gzip compressed data')" ]; then
tar --extract --gzip --file "$f" # or 'tar xzf $f'
elif [ -n "$(file "$f" | grep -i 'bzip2 compressed data')" ]; then
tar --extract --bzip2 --file "$f" # or 'tar xjf $f'
elif [ -n "$(file "$f" | grep -i 'RAR archive data')" ]; then
unrar x "$f"
else
echo "unrecognized format."
fi
done

19
bin/ocr
View File

@ -1,19 +0,0 @@
#!/usr/bin/env bash
# A script that utilizes OCR for a screenshot and copies the text to the clipboard.
# Dependencies:
# * tesseract 4.1.1
# * leptonica-1.79.0
# * The Tesseract English data
# * Image libraries (e.g., `libgif`, `libwebp`)
# * xclip - version 0.13
# * maim - version 5.6.3
# It's a small script anyways so why not.
# I feel like this is one of the appropriate solutions especially that there is potential for erreneous feedback.
set -o pipefail
notify-send "Select a region for the OCR"
maim --select --hidecursor | magick mogrify -modulate 100,0 -resize 400% png:- | tesseract - stdout | xclip -selection clipboard

View File

@ -1,16 +0,0 @@
#!/usr/bin/env bash
# Parse various code from image selection with zbarimg and maim.
# Depedencies:
# * maim v5.6.3
# * zbarimg v0.23.1
# * GNU awk v5.1.0
# * perl v5.30.2
# This is a small script so pipeline fails can be accepted here.
set -o pipefail
notify-send "Select a region for the barcode (QR codes, ISBN, bar codes)"
maim --select --hidecursor --quiet | zbarimg - --quiet --oneshot --raw | xclip -selection clipboard

View File

@ -1,332 +0,0 @@
#!/usr/bin/env bash
# This is a fork of rofi-screenshot (original at https://github.com/ceuk/rofi-screenshot/), basically a menu for all of your screenshoting and screencasting needs using rofi as the frontend.
# This script is meant to be modified for your specific need so feel free to do that.
# Btw, this script also uses its own Rofi theme so be sure to update it accordingly.
#############
# CONSTANTS #
#############
readonly _script_name=$(basename $0)
readonly _record_process_name='(/\S+)*ffmpeg\s.*\sx11grab\s.*'
readonly _process_id="$$"
readonly screenshot_directory="$(xdg-user-dir PICTURES)/screenshots"
readonly screenshot_msg_header="Screenshot"
readonly video_directory="$(xdg-user-dir VIDEOS)/recordings"
readonly video_msg_header="Screencast"
readonly date_filename_format="+%F-%H-%M-%S"
# Exit the script on USR1 signal.
# This is useful for exiting out of the whole script even in subshells.
trap 'notify-send "rofi-screenshot-menu has exited" && exit 1' 10
mkdir -p $screenshot_directory
mkdir -p $video_directory
#####################
# UTILITY FUNCTIONS #
#####################
# Setting the default command for ffmpeg.
ffmpeg() {
command ffmpeg -hide_banner -loglevel error -nostdin "$@"
}
# Set the default command for rofi.
rofi() {
command rofi -theme themes/fds-center-menu "$@" || kill -USR1 "$_process_id"
}
# Set the default command for slop.
slop() {
command slop "$@" || kill -USR1 "$_process_id"
}
# Convert a video to GIF.
# $1 - The input file.
# $2 - The output file.
video_to_gif() {
local input="$1"
local output="$2"
ffmpeg -i "$input" -vf palettegen -f image2 -c:v png - |
ffmpeg -i "$input" -i - -filter_complex paletteuse "$output"
}
# Create a countdown with desktop notifications.
# $1 - The duration of the countdown.
# $2 - The header of the notification.
_countdown() {
local counter="$((${1:-3}))"
local msg="${2:-Countdown}"
while [[ $counter -ne 0 ]]; do
notify-send "$msg" "Countdown in $counter seconds" --expire-time 1000
sleep 1
counter=$((counter - 1))
done
}
# Check for the recording process.
_check() {
pgrep --full --exact --newest "$_record_process_name" 1>/dev/null
}
# Kill the recording process.
_kill() {
pkill --full --exact --newest "$_record_process_name"
}
######################
# SCREENSHOT OPTIONS #
######################
# Most of the functions here have helpful documentations like the following function.
# Pretty handy, eh?
# Capture region to clipboard.
# $1 - Delay (in seconds) before screenshot.
# If it's >=0, there's no countdown (obviously).
capture_region_to_clipboard() {
notify-send "$screenshot_msg_header" "Select a region to capture"
local geometry=$(slop -n -f '-g %g ')
local delay=${1:-0}
if [ $delay -gt 0 ]; then
_countdown $delay "Screenshot"
fi
ffcast -q "$geometry" png /tmp/screenshot_clip.png
xclip -selection clipboard -t image/png /tmp/screenshot_clip.png && \
notify-send "$screenshot_msg_header" "Region copied to clipboard"
rm /tmp/screenshot_clip.png
}
# Capture region to file.
# $1 - Delay (in seconds) before screenshot.
# If the argument is set >=0, there's no countdown.
capture_region_to_file() {
notify-send "$screenshot_msg_header" "Select a region to capture"
dt=$(date "$date_filename_format")
local image_file="$screenshot_directory/$dt.png"
local geometry=$(slop -n -f '-g %g ')
local delay=${1:-0}
if [ $delay -gt 0 ]; then
_countdown $delay "Screenshot"
fi
ffcast -q "$geometry" png "$image_file"
notify-send "$screenshot_msg_header" "Region saved as $image_file"
}
# Capture screen to clipboard.
# Since delaying a screen capture is pretty easy, there's no delay option.
# Just make one of your own, please.
capture_screen_to_clipboard() {
ffcast -q png /tmp/screenshot_clip.png
xclip -selection clipboard -t image/png /tmp/screenshot_clip.png
rm /tmp/screenshot_clip.png
notify-send "$screenshot_msg_header" "Screenshot copied to clipboard"
}
# Capture screen to file.
# (See, I have written very helpful comments like this one.)
capture_screen_to_file() {
dt=$(date "$date_filename_format")
local image_file="$screenshot_directory/$dt.png"
ffcast -q png "$image_file"
notify-send "Screenshot" "Screenshot saved as $image_file"
}
######################
# SCREENCAST OPTIONS #
######################
# Record region to GIF.
# $1 - Delay (in seconds) before recording.
record_region_to_gif() {
notify-send "$video_msg_header" "Select a region to record"
dt=$(date "$date_filename_format")
local geometry=$(slop -n -f '-g %g ' && _countdown)
local delay=${1:-0}
if [ $delay -gt 0 ]; then
_countdown $delay "Screencast"
fi
ffcast -q rec /tmp/screenshot_gif.mkv
notify-send "$video_msg_header" "Converting to gif... (this can take a while)"
local recording_file="$video_directory/$dt.gif"
video_to_gif /tmp/screenshot_gif.mp4 $recording_file
rm /tmp/screenshot_gif.mp4
notify-send "$video_msg_header" "Recording saved as $recording_file"
}
record_screen_to_gif() {
dt=$(date "$date_filename_format")
ffcast -q rec /tmp/screenshot_gif.mp4
notify-send "$video_msg_header" "Converting to GIF... (this can take a while)"
local recording_file="$video_directory/$dt.gif"
video_to_gif /tmp/screenshot_gif.mp4 "$screenshot_directory/$dt.gif"
rm /tmp/screenshot_gif.mp4
notify-send "$video_msg_header" "Recording saved to $screenshot_directory"
}
# Record region to MKV.
# $1 - Delay (in seconds) before recording.
record_region_to_mkv() {
notify-send "$video_msg_header" "Select a region to record"
dt=$(date "$date_filename_format")
local delay=${1:-0}
if [ $delay -ge 0 ]; then
_countdown $delay "Screencast"
fi
local geometry=$(slop -n -f '-g %g ' && _countdown)
local video_file="$video_directory/$dt.mkv"
ffcast -q "$geometry" rec "$video_file"
notify-send "$video_msg_header" "Recording saved as $video_file"
}
record_screen_to_mkv() {
dt=$(date "$date_filename_format")
local video_file="$video_directory/$dt.mkv"
ffcast -q rec "$video_file"
notify-send "$video_msg_header" "Recording saved as $video_file"
}
######################
# COMMAND LINE STUFF #
######################
get_options() {
echo "Capture Region --> Clip"
echo "Capture Region --> File"
echo "Capture Screen --> Clip"
echo "Capture Screen --> File"
echo "Record Region --> File (GIF)"
echo "Record Screen --> File (GIF)"
echo "Record Region --> File (MKV)"
echo "Record Screen --> File (MKV)"
}
# Checks if the shell has the following binary in $PATH through the `hash` builtin.
# $1 - The utility to look for.
check_deps() {
if ! hash $1 2>/dev/null; then
echo "Error: This script requires $1"
exit 1
fi
}
# The help string.
_help="Usage: $_script_name [OPTIONS]
Launches a Rofi menu for your screenshoting and screencasting needs.
Options:
-h, --help Prints the help section.
--stop Stop if there's an active process (e.g., a recording).
--check Exits successfully if there's an active process.
The 'algorithm' for checking is very naive as it
checks for a specific name so be sure to check the
source code for yourself and update it accordingly.
"
main() {
# Check dependencies.
check_deps slop
check_deps ffcast
check_deps ffmpeg
check_deps xclip
check_deps rofi
# Parsing the arguments.
# Since getopts does not support long options so we'll have to roll our own.
while [[ $# -gt 0 ]];
do
case $1 in
-h|--help)
printf "$_help" && exit 0
;;
--stop)
_kill
exit $!
;;
--check)
_check
exit $!
;;
*)
shift
;;
esac
done
# Get choice from Rofi.
choice=$( (get_options) | rofi -dmenu -i -fuzzy -p "Screenshot and screencast options" )
# If user has not picked anything, exit.
if [[ -z "${choice// }" ]]; then
exit 1
fi
# Run the selected command.
case $choice in
'Capture Region --> Clip')
delay=$(rofi -dmenu -p "How many seconds for delay?")
capture_region_to_clipboard $delay
;;
'Capture Screen --> Clip')
delay=$(rofi -dmenu -p "How many seconds for delay?")
capture_screen_to_clipboard $delay
;;
'Capture Region --> File')
delay=$(rofi -dmenu -p "How many seconds for delay?")
capture_region_to_file $delay
;;
'Capture Screen --> File')
delay=$(rofi -dmenu -p "How many seconds for delay?")
_countdown $delay
capture_screen_to_file
;;
'Record Region --> File (GIF)')
delay=$(rofi -dmenu -p "How many seconds for delay?")
record_region_to_gif $delay
;;
'Record Screen --> File (GIF)')
delay=$(rofi -dmenu -p "How many seconds for delay?")
_countdown $delay
record_screen_to_gif
;;
'Record Region --> File (MKV)')
delay=$(rofi -dmenu -p "How many seconds for delay?")
record_region_to_mkv $delay
;;
'Record Screen --> File (MKV)')
delay=$(rofi -dmenu -p "How many seconds for delay?")
_countdown $delay
record_screen_to_mkv
;;
esac
}
main $1

View File

@ -1,29 +0,0 @@
#!/usr/bin/env sh
# Dependencies:
# * echo
# * kill
# * pgrep from procps-ng 3.3.15
help_usage="Close if the program is already running.
Otherwise, open the specified program.
Useful for programs that should have one instance running
at a time.
Note that it uses pgrep for searching the existance of
the program.
Usage: $0 <BINARY_NAME>
"
if [[ $# -lt 1 ]]; then
echo "$help_usage"
exit 0
fi
kill $(pgrep $1) 2>/dev/null
if [[ $? != 0 ]]; then
$1 2>/dev/null
fi

View File

@ -1,6 +0,0 @@
#!/usr/bin/env sh
# A simple prompt script.
# Based from Luke Smith's prompt script.
# https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/prompt
[ "$(printf "No\\nYes" | rofi -theme themes/dmenu -dmenu -p "$1")" = "Yes" ] && $2