Move all scripts to 'src' directory
This commit is contained in:
43
src/autopape.sh
Executable file
43
src/autopape.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
# simple script to loop through each image in a directory and set said image as wallpaper for a specified interval
|
||||
|
||||
command="feh --bg-fill"
|
||||
interval="1m"
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
Usage: autopape.sh [OPTIONS]... [ARGUMENTS]...
|
||||
Iterate over the files in a directory and set them as the desktop wallpaper at a regular interval.
|
||||
Options:
|
||||
-c Specify the command that should be used to set the wallpaper. Defaults to 'feh --bg-fill'
|
||||
-h Print this help message
|
||||
-i Specify the interval between wallpaper changes. Defaults to '1m'
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts 'c:i:h' flag; do
|
||||
case "${flag}" in
|
||||
c)
|
||||
command="${OPTARG}";;
|
||||
|
||||
i)
|
||||
interval="${OPTARG}";;
|
||||
|
||||
h)
|
||||
usage
|
||||
exit 0;;
|
||||
|
||||
*)
|
||||
usage
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
while [ true ]
|
||||
do
|
||||
for img in *
|
||||
do
|
||||
eval "$command '$img'"
|
||||
sleep "$interval"
|
||||
done
|
||||
done
|
9
src/bluetooth-off.sh
Executable file
9
src/bluetooth-off.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# Simple script to disable bluetooth on Void Linux (using the runit init system)
|
||||
|
||||
echo "Attempting to turn off bluetooth via bluetoothctl"
|
||||
bluetoothctl power off
|
||||
|
||||
echo "Attempting to remove the symlink to the bluetoothd service in the /var/service/ directory"
|
||||
# sudo rm /var/service/bluetoothd
|
||||
doas rm /var/service/bluetoothd
|
10
src/bluetooth-on.sh
Executable file
10
src/bluetooth-on.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
# Simple script to enable bluetooth on Void Linux (using the runit init system)
|
||||
|
||||
echo "Attempting to create a symbolic link to the bluetoothd service in /var/service/"
|
||||
# sudo ln --symbolic /etc/sv/bluetoothd /var/service/
|
||||
doas ln --symbolic /etc/sv/bluetoothd /var/service/
|
||||
|
||||
echo "Attempting to turn on bluetooth via bluetoothctl"
|
||||
bluetoothctl power on
|
||||
bluetoothctl
|
34
src/bluetooth_dmenu.pl
Executable file
34
src/bluetooth_dmenu.pl
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/perl
|
||||
# Script that allows the user to select a bluetooth device to connect to via dmenu.
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $script_name = $1 if ($0 =~ /.*\/(.*)$/);
|
||||
my $output = `bluetoothctl devices`;
|
||||
my %devices;
|
||||
|
||||
# assumes devices have unique names
|
||||
foreach my $device (split(/\n/, $output)) {
|
||||
if ($device =~ /Device\s(\S+)\s(.+)/) {
|
||||
my $mac_address = $1;
|
||||
my $name = $2;
|
||||
$devices{$name} = $mac_address;
|
||||
}
|
||||
}
|
||||
|
||||
my $device_list = "";
|
||||
foreach my $name (sort(keys %devices)) {
|
||||
$device_list .= $name . "\n";
|
||||
}
|
||||
|
||||
my $selection = `printf "$device_list" | dmenu -i -p "Connect Bluetooth device:"` or die("No selection made");
|
||||
chomp($selection);
|
||||
`notify-send "$script_name" "Attempting to connect to $selection ($devices{$selection})"`;
|
||||
`bluetoothctl connect $devices{$selection}`;
|
||||
|
||||
if ($? == 0) {
|
||||
`notify-send "$script_name" "Successfully connected to $selection ($devices{$selection})"`;
|
||||
}
|
||||
else {
|
||||
`notify-send "$script_name" "Failed to connect to $selection ($devices{$selection})"`;
|
||||
}
|
17
src/bluetooth_info.pl
Executable file
17
src/bluetooth_info.pl
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/perl -l
|
||||
# Perl script to display information about connected bluetooth devices. Designed to be used with polybar
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $output = `bluetoothctl info` or die("disconnected\n");
|
||||
|
||||
my $mac_address = ($output =~ /^Device\s+(\S+)/) ? "$1" : die("disconnected\n");
|
||||
my $device_name = ($output =~ /Name:\s+(.*)/) ? "$1" : "unknown";
|
||||
my $icon = ($output =~ /Icon:\s+(.*)/) ? "$1" : "";
|
||||
my $battery_percentage = ($output =~ /Battery Percentage:\s+\S+\s\(([0-9]+)\)/) ? "$1" : "?";
|
||||
|
||||
if ($icon eq "audio-headphones") {
|
||||
printf(" ");
|
||||
}
|
||||
printf("$device_name $battery_percentage%%");
|
4
src/bspwm_window_count.sh
Executable file
4
src/bspwm_window_count.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
# Script to list the number of windows on the current desktop (workspace) in bspwm
|
||||
|
||||
bspc query --nodes --node .window --desktop focused | wc --lines
|
7
src/clean_files.sh
Executable file
7
src/clean_files.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# script for looping through each file in a directory, opening it with mimeopen, and upon the closing of the file viewer, asking the user whether or not to delete the image, and deleting if "y" received
|
||||
|
||||
for file in *
|
||||
do
|
||||
mimeopen "$file" && read -p "Delete file? [y/n]: " ans && [ "$ans" = "y" ] && rm "$file"
|
||||
done
|
4
src/defn
Executable file
4
src/defn
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
# Script to look up word in dictionary file in the format: "word:\tdefinition\n"
|
||||
|
||||
printf "$(rg --no-line-number "^$1:" ~/.local/share/dictionary.txt || echo 'No definition found. The searched term may not be in the dictionary file, or the dictionary file may not be present')\n"
|
22
src/ensure_connected.sh
Executable file
22
src/ensure_connected.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# simple script to fix my broken wifi
|
||||
# it checks if wifi is connected at regular intervals, and if not, repeatedly attempts to connect
|
||||
|
||||
trap "echo 'SIGINT received, terminating'; exit" SIGINT
|
||||
|
||||
# source the network & interface names from a file
|
||||
source config.env
|
||||
|
||||
# network="<network_name>"
|
||||
# interface="<interface_name>"
|
||||
interval=1
|
||||
|
||||
while [ true ]; do
|
||||
# if wifi is connected, do nothing for $interval seconds
|
||||
if [ -n "$(nmcli connection show | grep '.*'"$network"'.*'"$interface"'.*')" ]; then
|
||||
sleep $interval
|
||||
# else, wifi is not connected so attempt to connect to wifi network, and keep trying until it succeeds
|
||||
else
|
||||
nmcli con up "$network" || while [ "$?" != "0" ]; do nmcli con up "$network"; done
|
||||
fi
|
||||
done
|
83
src/file_previewer.sh
Executable file
83
src/file_previewer.sh
Executable file
@ -0,0 +1,83 @@
|
||||
#!/bin/sh
|
||||
# File preview handler for lf using the Perl `mimetype` utility.
|
||||
|
||||
preview_image="/tmp/lf_preview_image.png"
|
||||
|
||||
file=$1
|
||||
width="${2:-$(tput cols)}"
|
||||
height="${3:-$(tput lines)}"
|
||||
x=$4
|
||||
y=$5
|
||||
|
||||
mimetype="$(mimetype --brief -- "$file")"
|
||||
|
||||
if [ "$mimetype" = "inode/symlink" ]; then
|
||||
file="$(readlink "$file")"
|
||||
mimetype="$(mimetype --brief -- "$file")"
|
||||
fi
|
||||
|
||||
case "$mimetype" in
|
||||
application/gzip | application/msword | application/x-iso9660-image | application/vnd.openxmlformats-officedocument.wordprocessingml.document | application/vnd.openxmlformats-officedocument.presentationml.presentation | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
|
||||
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/json)
|
||||
jq --color-output . "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/pdf)
|
||||
pdftoppm -jpeg "$file" -singlefile | chafa --size "$(($width-4))"x"$height"
|
||||
pdfinfo "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/vnd.rar)
|
||||
unrar l "$file" | bat --language=java --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/vnd.sqlite3)
|
||||
sqlite3 "$file" "SELECT * FROM sqlite_master WHERE type = 'table';" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/x-compressed-tar)
|
||||
tar --list --ungzip --file "$file" | bat --language=java --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/x-java)
|
||||
javap "$file" | bat --language=java --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/x-pcapng)
|
||||
tshark -r "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;; # the --read-file option does not seem to work
|
||||
|
||||
application/x-zstd-compressed-tar)
|
||||
tar --list --use-compress-program zstd --file "$file" | bat --language=java --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
application/zip)
|
||||
unzip -lv "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
audio/*)
|
||||
exiftool -Picture -b "$file" | chafa --size "$(($width-4))"x"$height" || chafa cover.* --size "$(($width-4))"x"$height"
|
||||
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
image/*)
|
||||
chafa "$file" --size "$(($width-4))"x"$height" --animate off
|
||||
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
text/csv)
|
||||
column --separator "," --table "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization --wrap=never;;
|
||||
|
||||
text/html)
|
||||
lynx -width="$width" -display_charset=utf-8 -dump "$file";;
|
||||
|
||||
text/markdown)
|
||||
markdown-it "$file" | lynx -width="$width" -display_charset=utf-8 -dump -stdin;;
|
||||
|
||||
video/*)
|
||||
ffmpeg -ss 00:00:00 -i "$file" -frames:v 1 -q:v 2 "$preview_image"
|
||||
chafa "$preview_image" --size "$(($width-4))"x"$height"
|
||||
rm "$preview_image" # removing preview file so that lf looks for a new preview image instead of going for an old one
|
||||
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization;;
|
||||
|
||||
*)
|
||||
# check if file is text or binary
|
||||
if file "$file" | grep --silent "text"; then
|
||||
bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization "$file"
|
||||
else
|
||||
exiftool "$file" | bat --theme='base16' --terminal-width "$(($width-4))" --force-colorization
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
13
src/hide_bar.sh
Executable file
13
src/hide_bar.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Simple script to hide Polybar on bspwm
|
||||
|
||||
if [ -f /tmp/polybarhidden ]
|
||||
then
|
||||
bspc config top_padding 30
|
||||
polybar-msg cmd show
|
||||
rm /tmp/polybarhidden
|
||||
else
|
||||
polybar-msg cmd hide
|
||||
bspc config top_padding 0
|
||||
touch /tmp/polybarhidden
|
||||
fi
|
7
src/hugo_post.sh
Executable file
7
src/hugo_post.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Simple script to create a new post in Hugo in the format "/content/posts/Post Title/index.md" as opposed to the default "/content/posts/Post Title.md"
|
||||
|
||||
title="$1"
|
||||
|
||||
mkdir "./content/blog/$title"
|
||||
hugo new content "blog/$title/index.md"
|
7
src/list_manual_pkgs.sh
Executable file
7
src/list_manual_pkgs.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# one-liner to list just the names of packages manually-installed with xbps-install, with no version numbers etc
|
||||
xbps-query --list-manual-pkgs | sed "s/-[0-9].*//g"
|
||||
|
||||
# i originally wrote this using awk, but i realised that sed would allow for a more elegant implementation, although there was no meaningful speed difference during my tests
|
||||
# alternative awk version:
|
||||
# xbps-query --list-manual-pkgs | awk '{gsub(/-[0-9]+.*$/, ""); print $0}'
|
21
src/music_dmenu.sh
Executable file
21
src/music_dmenu.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
# Script to play a specific artist, album, or track selected with dmenu
|
||||
|
||||
music_dir="$HOME/media/music"
|
||||
|
||||
answer="$(printf "Artist\nAlbum\nTrack" | dmenu -p "Play music by:")"
|
||||
|
||||
artist="$(ls "$music_dir" | dmenu -p "Artist:")"
|
||||
|
||||
if [ "$answer" = "Artist" ]; then
|
||||
setsid umpv "$music_dir/$artist" &
|
||||
else
|
||||
album="$(ls "$music_dir/$artist" | dmenu -p "Album:")"
|
||||
|
||||
if [ "$answer" = "Album" ]; then
|
||||
setsid umpv "$music_dir/$artist/$album" &
|
||||
else
|
||||
track="$(ls "$music_dir/$artist/$album" | dmenu -p "Track:")"
|
||||
setsid umpv "$music_dir/$artist/$album/$track" &
|
||||
fi
|
||||
fi
|
6
src/play_music.sh
Executable file
6
src/play_music.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Simple script to play music albums based off the supplied artist & album name
|
||||
artist="$1"
|
||||
album="$2"
|
||||
|
||||
setsid umpv "$HOME/media/music/$artist/$album/" &
|
15
src/qutebrowser_search.sh
Executable file
15
src/qutebrowser_search.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# script to find all the search engines in the qutebrowser configuration file and make them available for searching via dmenu
|
||||
|
||||
input="$(
|
||||
awk '/^c\.url\.searchengines =/,/^}$/{
|
||||
if (!/^c\.url\.searchengines =/ && !/^}$/){
|
||||
gsub(/":?/, ""); print $1
|
||||
}
|
||||
}' ~/.config/qutebrowser/config.py | dmenu
|
||||
)"
|
||||
|
||||
if [ "$input" ]
|
||||
then
|
||||
qutebrowser "$input"
|
||||
fi
|
4
src/repos_checker.sh
Executable file
4
src/repos_checker.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
# script to find all the git repositories in the current directory (& sub-directories) and display their git statuses
|
||||
|
||||
find . -name ".git" -type d -not -path "./.cache/*" -not -path "./.local/*" -exec sh -c '(cd {}/../; echo -e "\n\033[1m$(pwd)\033[0m"; git status)' \;
|
8
src/stdin_to_notis.sh
Executable file
8
src/stdin_to_notis.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# small script to turn the stdout output of a program into notifications line-by-line
|
||||
# intended for use when a script is not being called from a terminal, but from a GUI application so that output can still be seen
|
||||
|
||||
while read line
|
||||
do
|
||||
notify-send "$line"
|
||||
done
|
13
src/stopwatch.sh
Executable file
13
src/stopwatch.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Simple stopwatch script that simply counts the elapsed time in seconds.
|
||||
|
||||
start=$(date +%s)
|
||||
|
||||
stty -echo # hide keyboard input
|
||||
|
||||
while [ true ]
|
||||
do
|
||||
time="$(($(date +%s) - $start))"
|
||||
printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
|
||||
sleep 1s
|
||||
done
|
16
src/sync_music.sh
Executable file
16
src/sync_music.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# Script to sync my Android phone's music library to the contents of my ~/media/music/ directory
|
||||
|
||||
mountpoint="$HOME/mnt"
|
||||
source="$HOME/media/music/"
|
||||
destination="$mountpoint/Internal shared storage/Music/"
|
||||
|
||||
mkdir "$mountpoint"
|
||||
aft-mtp-mount "$mountpoint"
|
||||
|
||||
rsync --archive --compress --partial --append-verify --delete --info=progress2 "$source" "$destination" &&
|
||||
{
|
||||
sync
|
||||
fusermount -u "$mountpoint"
|
||||
rmdir "$mountpoint"
|
||||
}
|
3
src/webcam.sh
Executable file
3
src/webcam.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
# one-liner to use mpv to as a webcam viewer
|
||||
mpv av://v4l2:/dev/video0 --profile=low-latency --untimed
|
8
src/wifi_dmenu.sh
Executable file
8
src/wifi_dmenu.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
# Script to connect to an available WiFi network with a dmenu prompt.
|
||||
|
||||
script_name="$(basename "$0")"
|
||||
notify-send "$script_name" "Scanning for available networks..."
|
||||
|
||||
# cutting the first 9 characters of the nmcli output as it will contain empty fields which will mess up awk parsing
|
||||
notify-send "$script_name" "$( nmcli connection up $( nmcli device wifi list | cut --characters=9- | awk -F ' ' '(NR > 1){ print $2}' | sort | uniq | dmenu -i -p "Connect to network: ") 2>&1 )"
|
13
src/wl_screenshot.sh
Executable file
13
src/wl_screenshot.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Screenshot script with selection using grim and slurp.
|
||||
#
|
||||
filepath="$HOME/media/images/screenshots/$(date +%Y-%m-%d\ %H:%M:%S).png"
|
||||
grim -g "$(slurp)" - | tee "$filepath" | wl-copy
|
||||
|
||||
# if screenshot is cancelled, tee will create an empty file, so checking if the file is empty
|
||||
if [ -s "$filepath" ]; then
|
||||
# send notification with a thumbnail of the screenshot taken, the name of the script, and the filepath
|
||||
notify-send --icon "$filepath" "$(basename "$0")" "Screenshot saved to: $filepath"
|
||||
else
|
||||
rm "$filepath"
|
||||
fi
|
18
src/wl_vimshot.sh
Executable file
18
src/wl_vimshot.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Script to take a wait a few seconds before taking a screenshot to the filepath in the clipboard.
|
||||
# For use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted.
|
||||
|
||||
basename=$(basename "$0")
|
||||
filepath=$(wl-paste)
|
||||
|
||||
# check if the filepath is absolute or relative, and if relative, make absolute
|
||||
if [ "${filepath#\/}" = "$filepath" ] || [ "${filepath#\~}" = "$filepath" ]; then
|
||||
filepath="$(pwd)/$filepath"
|
||||
fi
|
||||
|
||||
notify-send "$basename" "Taking screenshot to $filepath"
|
||||
|
||||
sleep 5
|
||||
grim -g "$(slurp)" "$filepath"
|
||||
|
||||
notify-send --icon "$filepath" "$basename" "Screenshot saved to: $filepath"
|
12
src/x11_screenshot.sh
Executable file
12
src/x11_screenshot.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
# Screenshot script with selection using maim and notification.
|
||||
filepath="$HOME/media/images/screenshots/$(date +%Y-%m-%d\ %H:%M:%S).png"
|
||||
maim --select --hidecursor | tee "$filepath" | xclip -selection clipboard -target image/png
|
||||
|
||||
# if maim is cancelled, tee will create an empty file, so checking if the file is empty
|
||||
if [ -s "$filepath" ]; then
|
||||
# send notification with a thumbnail of the screenshot taken, the name of the script, and the filepath
|
||||
notify-send --icon "$filepath" "$(basename "$0")" "Screenshot saved to: $filepath"
|
||||
else
|
||||
rm "$filepath"
|
||||
fi
|
18
src/x11_vimshot.sh
Executable file
18
src/x11_vimshot.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Script to take a wait a few seconds before taking a screenshot to the filepath in the clipboard.
|
||||
# For use as part of my LaTeX note-taking workflow in Vim: create the figure environment, copy the file name, invoke this script, and select the region in the source material to be screenshotted.
|
||||
|
||||
basename=$(basename "$0")
|
||||
filepath=$(xclip -selection clipboard -out)
|
||||
|
||||
# check if the filepath is absolute or relative, and if relative, make absolute
|
||||
if [ "${filepath#\/}" = "$filepath" ] || [ "${filepath#\~}" = "$filepath" ]; then
|
||||
filepath="$(pwd)/$filepath"
|
||||
fi
|
||||
|
||||
notify-send "$basename" "Taking screenshot to $filepath"
|
||||
|
||||
sleep 5
|
||||
maim --select --hidecursor "$filepath"
|
||||
|
||||
notify-send --icon "$filepath" "$basename" "Screenshot saved to: $filepath"
|
Reference in New Issue
Block a user