Cohesive shell script formatting

- Format all shell scripts using [shfmt]
  (https://github.com/mvdan/sh).

Options used:

* `-bn`: binary ops like && and | may start a line
* `-sr`: redirect operators will be followed by a space
* `-ci`: indent switch cases
* `-i 4`: indent 4 spaces
* `-s`: simplify the code
* `-p`: parse for posix compliance

- Add Github action to lint changes to scripts and enforce formatting
  going forward

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
This commit is contained in:
vlad doster 2021-03-13 00:13:26 -06:00 committed by Vladislav Doster
parent 87c2950039
commit eed099b954
64 changed files with 878 additions and 769 deletions

View File

@ -2,7 +2,8 @@
set -C -f -u set -C -f -u
#IFS=$'\n' #IFS=$'\n'
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" IFS="$(printf '%b_' '\n')"
IFS="${IFS%_}"
# ANSI color codes are supported. # ANSI color codes are supported.
# STDIN is disabled, so interactive scripts won't work properly # STDIN is disabled, so interactive scripts won't work properly
@ -28,31 +29,31 @@ HIGHLIGHT_SIZE_MAX=262143 # 256KiB
HIGHLIGHT_TABWIDTH=8 HIGHLIGHT_TABWIDTH=8
HIGHLIGHT_STYLE='pablo' HIGHLIGHT_STYLE='pablo'
handle_mime() { handle_mime() {
local mimetype="${1}" local mimetype="${1}"
case "${mimetype}" in case "${mimetype}" in
text/html) w3m -dump "${FILE_PATH}" ;; text/html) w3m -dump "${FILE_PATH}" ;;
text/troff) man ./ "${FILE_PATH}" | col -b ;; text/troff) man ./ "${FILE_PATH}" | col -b ;;
text/* | */xml) text/* | */xml)
if [ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]; then if [ "$(stat --printf='%s' -- "${FILE_PATH}")" -gt "${HIGHLIGHT_SIZE_MAX}" ]; then
exit 2 exit 2
fi fi
if [ "$( tput colors )" -ge 256 ]; then if [ "$(tput colors)" -ge 256 ]; then
local highlight_format='xterm256' local highlight_format='xterm256'
else else
local highlight_format='ansi' local highlight_format='ansi'
fi fi
highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \ highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \
--style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}" ;; --style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}"
;;
application/zip) atool --list -- "${FILE_PATH}" ;; application/zip) atool --list -- "${FILE_PATH}" ;;
image/*) chafa --fill=block --symbols=block -c 256 -s 80x"${HEIGHT}" "${FILE_PATH}" || exit 1;; image/*) chafa --fill=block --symbols=block -c 256 -s 80x"${HEIGHT}" "${FILE_PATH}" || exit 1 ;;
video/* | audio/*|application/octet-stream) mediainfo "${FILE_PATH}" || exit 1;; video/* | audio/* | application/octet-stream) mediainfo "${FILE_PATH}" || exit 1 ;;
*/pdf) pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - ;; */pdf) pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - ;;
*opendocument*) odt2txt "${FILE_PATH}" ;; *opendocument*) odt2txt "${FILE_PATH}" ;;
esac esac
} }
MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )" MIMETYPE="$(file --dereference --brief --mime-type -- "${FILE_PATH}")"
handle_mime "${MIMETYPE}" handle_mime "${MIMETYPE}"
exit 1 exit 1

View File

@ -7,7 +7,7 @@
[ -f "$XINITRC" ] && alias startx="startx $XINITRC" [ -f "$XINITRC" ] && alias startx="startx $XINITRC"
# sudo not required for some system commands # sudo not required for some system commands
for x in mount umount sv pacman updatedb su ; do for x in mount umount sv pacman updatedb su; do
alias $x="sudo $x" alias $x="sudo $x"
done done
@ -47,4 +47,4 @@ alias \
alias \ alias \
magit="nvim -c MagitOnly" \ magit="nvim -c MagitOnly" \
ref="shortcuts >/dev/null; source ${XDG_CONFIG_HOME:-$HOME/.config}/shortcutrc ; source ${XDG_CONFIG_HOME:-$HOME/.config}/zshnameddirrc" \ ref="shortcuts >/dev/null; source ${XDG_CONFIG_HOME:-$HOME/.config}/shortcutrc ; source ${XDG_CONFIG_HOME:-$HOME/.config}/zshnameddirrc" \
weath="less -S ${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" \ weath="less -S ${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport"

View File

@ -1,6 +1,5 @@
#!/bin/sh #!/bin/sh
while read file while read file; do
do
case "$1" in case "$1" in
"w") setbg "$file" & ;; "w") setbg "$file" & ;;
"c") "c")
@ -14,19 +13,25 @@ do
mv "$file" "$destdir" && notify-send -i "$(readlink -f "$file")" "$file moved to $destdir." & mv "$file" "$destdir" && notify-send -i "$(readlink -f "$file")" "$file moved to $destdir." &
;; ;;
"r") "r")
convert -rotate 90 "$file" "$file" ;; convert -rotate 90 "$file" "$file"
;;
"R") "R")
convert -rotate -90 "$file" "$file" ;; convert -rotate -90 "$file" "$file"
;;
"f") "f")
convert -flop "$file" "$file" ;; convert -flop "$file" "$file"
;;
"y") "y")
echo -n "$file" | tr -d '\n' | xclip -selection clipboard && echo -n "$file" | tr -d '\n' | xclip -selection clipboard \
notify-send "$file copied to clipboard" & ;; && notify-send "$file copied to clipboard" &
;;
"Y") "Y")
readlink -f "$file" | tr -d '\n' | xclip -selection clipboard && readlink -f "$file" | tr -d '\n' | xclip -selection clipboard \
notify-send "$(readlink -f "$file") copied to clipboard" & ;; && notify-send "$(readlink -f "$file") copied to clipboard" &
;;
"d") "d")
[ "$(printf "No\\nYes" | dmenu -i -p "Really delete $file?")" = "Yes" ] && rm "$file" && notify-send "$file deleted." ;; [ "$(printf 'No\nYes' | dmenu -i -p "Really delete $file?")" = "Yes" ] && rm "$file" && notify-send "$file deleted."
;;
"g") ifinstalled gimp && setsid -f gimp "$file" ;; "g") ifinstalled gimp && setsid -f gimp "$file" ;;
"i") notify-send "File information" "$(mediainfo "$file")" ;; "i") notify-send "File information" "$(mediainfo "$file")" ;;
esac esac

View File

@ -14,14 +14,14 @@ fix_sequences() {
background_color="$(echo -e "${sequences}\c" | grep --color=never -Eo "${e}]11[^${e}\\\\]*?${e}\\\\" | grep --color=never -Eo "#[0-9A-Fa-f]{6}")" background_color="$(echo -e "${sequences}\c" | grep --color=never -Eo "${e}]11[^${e}\\\\]*?${e}\\\\" | grep --color=never -Eo "#[0-9A-Fa-f]{6}")"
cursor_color="$(echo -e "${sequences}\c" | grep --color=never -Eo "${e}]12[^${e}\\\\]*?${e}\\\\" | grep --color=never -Eo "#[0-9A-Fa-f]{6}")" cursor_color="$(echo -e "${sequences}\c" | grep --color=never -Eo "${e}]12[^${e}\\\\]*?${e}\\\\" | grep --color=never -Eo "#[0-9A-Fa-f]{6}")"
for term in /dev/pts/{0..9}* for term in /dev/pts/{0..9}*; do
do echo -e "\e]4;256;${cursor_color}\a\c" > "${term}" 2> /dev/null
echo -e "\e]4;256;${cursor_color}\a\c" > "${term}" 2>/dev/null echo -e "\e]4;258;${background_color}\a\c" > "${term}" 2> /dev/null
echo -e "\e]4;258;${background_color}\a\c" > "${term}" 2>/dev/null echo -e "\e]4;259;${foreground_color}\a\c" > "${term}" 2> /dev/null
echo -e "\e]4;259;${foreground_color}\a\c" > "${term}" 2>/dev/null done
done
} }
fix_sequences <"${HOME}/.cache/wal/sequences" fix_sequences < "${HOME}/.cache/wal/sequences"
pkill dunst; dunst & pkill dunst
dunst &

View File

@ -15,6 +15,6 @@ unclutter & # Remove mouse when idle
# This line autostarts an instance of Pulseaudio that does not exit on idle. # This line autostarts an instance of Pulseaudio that does not exit on idle.
# This is "necessary" on Artix due to a current bug between PA and # This is "necessary" on Artix due to a current bug between PA and
# Chromium-based browsers where they fail to start PA and use dummy output. # Chromium-based browsers where they fail to start PA and use dummy output.
pidof -s runit && pidof -s runit \
! pidof -s pulseaudio >/dev/null 2>&1 && && ! pidof -s pulseaudio > /dev/null 2>&1 \
setsid -f pulseaudio --start --exit-idle-time=-1 >/dev/null 2>&1 && setsid -f pulseaudio --start --exit-idle-time=-1 > /dev/null 2>&1

38
.github/workflows/linter.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: shfmt-linter
on:
pull_request:
branches:
- master
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: update system
run: |
sudo apt-get upgrade --install-suggests --yes
- name: install dependencies
run: |
sudo apt-get install git \
make
- name: apply shfmt fixes
run: |
docker run --volume "$PWD":/mnt \
--rm \
mvdan/shfmt -bn -ci -d -i 4 -p -s -sr -w /mnt
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: (maint) apply shfmt formatting
commit_options: '--cleanup=default --no-verify --signoff'
push_options: '--force'
skip_dirty_check: false

View File

@ -2,13 +2,16 @@
# Requires ffmpeg (audio splitting) and my `tag` wrapper script. # 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 [ ! -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 album/book title:"
read -r booktitle
echo "Enter the artist/author:"; read -r author echo "Enter the artist/author:"
read -r author
echo "Enter the publication year:"; read -r year echo "Enter the publication year:"
read -r year
inputaudio="$1" inputaudio="$1"
@ -24,23 +27,22 @@ ext="opus"
# Get the total number of tracks from the number of lines. # Get the total number of tracks from the number of lines.
total="$(wc -l < "$2")" total="$(wc -l < "$2")"
while read -r x; while read -r x; do
do
end="$(echo "$x" | cut -d' ' -f1)" end="$(echo "$x" | cut -d' ' -f1)"
[ -n "$start" ] && [ -n "$start" ] \
echo "From $start to $end; $track $title" && echo "From $start to $end; $track $title"
file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext"
[ -n "$start" ] && echo "Splitting \"$title\"..." && [ -n "$start" ] && echo "Splitting \"$title\"..." \
ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -to "$end" -vn -c copy "$file" && && 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" && echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file"
title="$(echo "$x" | cut -d' ' -f 2-)" 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")" 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))" track="$((track + 1))"
start="$end" start="$end"
done < "$2" done < "$2"
# The last track must be done outside the loop. # The last track must be done outside the loop.
echo "From $start to the end: $title" echo "From $start to the end: $title"
file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext" file="$escbook/$(printf "%.2d" "$track")-$esctitle.$ext"
echo "Splitting \"$title\"..." && ffmpeg -nostdin -y -loglevel -8 -i "$inputaudio" -ss "$start" -vn -c copy "$file" && 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" && echo "Tagging \"$title\"..." && tag -a "$author" -A "$booktitle" -t "$title" -n "$track" -N "$total" -d "$year" "$file"

View File

@ -16,14 +16,14 @@ ext="${file##*.}"
cd "$dir" || exit 1 cd "$dir" || exit 1
textype() { \ textype() {
command="pdflatex" command="pdflatex"
( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex" (head -n5 "$file" | grep -qi 'xelatex') && command="xelatex"
$command --output-directory="$dir" "$base" && $command --output-directory="$dir" "$base" \
grep -qi addbibresource "$file" && && grep -qi addbibresource "$file" \
biber --input-directory "$dir" "$base" && && biber --input-directory "$dir" "$base" \
$command --output-directory="$dir" "$base" && && $command --output-directory="$dir" "$base" \
$command --output-directory="$dir" "$base" && $command --output-directory="$dir" "$base"
} }
case "$ext" in case "$ext" in
@ -42,7 +42,7 @@ case "$ext" in
groffdown -i "$file" | groff > "$base.pdf" groffdown -i "$file" | groff > "$base.pdf"
else else
pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file" pandoc -t ms --highlight-style=kate -s -o "$base".pdf "$file"
fi ; ;; fi ;;
mom) preconv "$file" | refer -PS -e | groff -mom -kept -T pdf > "$base".pdf ;; 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 ;; 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 ;; org) emacs "$file" --batch -u "$USER" -f org-latex-export-to-pdf ;;
@ -51,7 +51,7 @@ case "$ext" in
rs) cargo build ;; rs) cargo build ;;
sass) sassc -a "$file" "$base.css" ;; sass) sassc -a "$file" "$base.css" ;;
scad) openscad -o "$base".stl "$file" ;; scad) openscad -o "$base".stl "$file" ;;
sent) setsid -f sent "$file" 2>/dev/null ;; sent) setsid -f sent "$file" 2> /dev/null ;;
tex) textype "$file" ;; tex) textype "$file" ;;
*) head -n1 "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;; *) head -n1 "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
esac esac

View File

@ -11,8 +11,7 @@ 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." Check your internet connection, if pacman is already running, or run update manually to see errors."
pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}" pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}"
if pacman -Qu | grep -v "\[ignored\]" if pacman -Qu | grep -v "\[ignored\]"; then
then
notify-send "🎁 Repository Sync" "Updates available. Click statusbar icon (📦) for update." notify-send "🎁 Repository Sync" "Updates available. Click statusbar icon (📦) for update."
else else
notify-send "📦 Repository Sync" "Sync complete. No new packages for update." notify-send "📦 Repository Sync" "Sync complete. No new packages for update."

View File

@ -3,4 +3,4 @@
# Toggles all cronjobs off/on. # Toggles all cronjobs off/on.
# Stores disabled crontabs in ~/.consaved until restored. # 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.") ([ -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.")

View File

@ -6,17 +6,17 @@
twoscreen() { # If multi-monitor is selected and there are two screens. twoscreen() { # If multi-monitor is selected and there are two screens.
mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?") mirror=$(printf 'no\nyes' | dmenu -i -p "Mirror displays?")
# Mirror displays using native resolution of external display and a scaled # Mirror displays using native resolution of external display and a scaled
# version for the internal display # version for the internal display
if [ "$mirror" = "yes" ]; then if [ "$mirror" = "yes" ]; then
external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:") external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:")
internal=$(echo "$screens" | grep -v "$external") internal=$(echo "$screens" | grep -v "$external")
res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \ res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" \
tail -n 1 | awk '{print $1}') | tail -n 1 | awk '{print $1}')
res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \ res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" \
tail -n 1 | awk '{print $1}') | tail -n 1 | awk '{print $1}')
res_ext_x=$(echo "$res_external" | sed 's/x.*//') res_ext_x=$(echo "$res_external" | sed 's/x.*//')
res_ext_y=$(echo "$res_external" | sed 's/.*x//') res_ext_y=$(echo "$res_external" | sed 's/.*x//')
@ -33,34 +33,38 @@ twoscreen() { # If multi-monitor is selected and there are two screens.
primary=$(echo "$screens" | dmenu -i -p "Select primary display:") primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
secondary=$(echo "$screens" | grep -v "$primary") secondary=$(echo "$screens" | grep -v "$primary")
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?") 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 xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi fi
} }
morescreen() { # If multi-monitor is selected and there are more than two screens. morescreen() { # If multi-monitor is selected and there are more than two screens.
primary=$(echo "$screens" | dmenu -i -p "Select primary display:") primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary 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?") 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:") 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 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. multimon() { # Multi-monitor handler.
case "$(echo "$screens" | wc -l)" in case "$(echo "$screens" | wc -l)" in
2) twoscreen ;; 2) twoscreen ;;
*) morescreen ;; *) morescreen ;;
esac ;} esac
}
onescreen() { # If only one output available or chosen. 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 ' ' -) 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. postrun() { # Stuff to run to clean up.
setbg # Fix background if screen size/arangement has changed. setbg # Fix background if screen size/arangement has changed.
remaps # Re-remap keys if keyboard added (for laptop bases) 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 {
} killall dunst
setsid -f dunst
} > /dev/null 2>&1 # Restart dunst to ensure proper location on screen
}
# Get all possible displays # Get all possible displays
allposs=$(xrandr -q | grep "connected") allposs=$(xrandr -q | grep "connected")
@ -69,15 +73,23 @@ allposs=$(xrandr -q | grep "connected")
screens=$(echo "$allposs" | awk '/ connected/ {print $1}') screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
# If there's only one screen # If there's only one screen
[ "$(echo "$screens" | wc -l)" -lt 2 ] && [ "$(echo "$screens" | wc -l)" -lt 2 ] \
{ onescreen "$screens"; postrun; notify-send "💻 Only one screen detected." "Using it in its optimal settings..."; exit ;} && {
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: # Get user choice including multi-monitor and manual selection:
chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") && chosen=$(printf '%s\nmulti-monitor\nmanual selection' "$screens" | dmenu -i -p "Select display arangement:") \
case "$chosen" in && case "$chosen" in
"manual selection") arandr ; exit ;; "manual selection")
arandr
exit
;;
"multi-monitor") multimon ;; "multi-monitor") multimon ;;
*) onescreen "$chosen" ;; *) onescreen "$chosen" ;;
esac esac
postrun postrun

View File

@ -4,18 +4,21 @@
# some choice programs to use to open it. # some choice programs to use to open it.
feed="${1:-$(printf "%s" | dmenu -p 'Paste URL or file path')}" 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 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 ;; "copy url") echo "$feed" | xclip -selection clipboard ;;
mpv) setsid -f mpv -quiet "$feed" >/dev/null 2>&1 ;; mpv) setsid -f mpv -quiet "$feed" > /dev/null 2>&1 ;;
"mpv loop") setsid -f mpv -quiet --loop "$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 ;; "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") 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 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 ;; "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 ;; 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 ;; 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 ;; 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 ;; setbg)
browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 ;; curl -L "$feed" > $XDG_CACHE_HOME/pic
lynx) lynx "$feed" >/dev/null 2>&1 ;; 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 esac

View File

@ -5,33 +5,38 @@
# be prompted to give a mountpoint from already existsing directories. If you # be prompted to give a mountpoint from already existsing directories. If you
# input a novel directory, it will prompt you to create that directory. # input a novel directory, it will prompt you to create that directory.
getmount() { \ getmount() {
[ -z "$chosen" ] && exit 1 [ -z "$chosen" ] && exit 1
# shellcheck disable=SC2086 # shellcheck disable=SC2086
mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1 mp="$(find $1 2> /dev/null | dmenu -i -p "Type in mount point.")" || exit 1
[ "$mp" = "" ] && exit 1 [ "$mp" = "" ] && exit 1
if [ ! -d "$mp" ]; then if [ ! -d "$mp" ]; then
mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 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") [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
fi fi
} }
mountusb() { \ mountusb() {
chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1 chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1
chosen="$(echo "$chosen" | awk '{print $1}')" chosen="$(echo "$chosen" | awk '{print $1}')"
sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 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}') 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" getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted"
partitiontype="$(lsblk -no "fstype" "$chosen")" partitiontype="$(lsblk -no "fstype" "$chosen")"
case "$partitiontype" in case "$partitiontype" in
"vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; "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)";; "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";; *)
sudo -A mount "$chosen" "$mp"
user="$(whoami)"
ug="$(groups | awk '{print $1}')"
sudo -A chown "$user":"$ug" "$mp"
;;
esac esac
notify-send "💻 USB mounting" "$chosen mounted to $mp." notify-send "💻 USB mounting" "$chosen mounted to $mp."
} }
mountandroid() { \ mountandroid() {
chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1 chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1
chosen="$(echo "$chosen" | cut -d : -f 1)" chosen="$(echo "$chosen" | cut -d : -f 1)"
getmount "$HOME -maxdepth 3 -type d" getmount "$HOME -maxdepth 3 -type d"
@ -39,17 +44,17 @@ mountandroid() { \
echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 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" simple-mtpfs --device "$chosen" "$mp"
notify-send "🤖 Android Mounting" "Android device mounted to $mp." notify-send "🤖 Android Mounting" "Android device mounted to $mp."
} }
asktype() { \ asktype() {
choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 choice="$(printf 'USB\nAndroid' | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1
case $choice in case $choice in
USB) mountusb ;; USB) mountusb ;;
Android) mountandroid ;; Android) mountandroid ;;
esac esac
} }
anddrives=$(simple-mtpfs -l 2>/dev/null) 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}')" usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')"
if [ -z "$usbdrives" ]; then if [ -z "$usbdrives" ]; then

View File

@ -13,7 +13,8 @@ share2mnt=//"$srvname".local/"$share"
sharemount() { sharemount() {
mounted=$(mount -v | grep "$share2mnt") || ([ ! -d /mnt/"$share" ] && sudo mkdir /mnt/"$share") 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 [ -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 notify-send "Netshare $share already mounted"
exit 1
} }
sharemount sharemount

View File

@ -9,10 +9,10 @@
# #
# If there is already a running instance, user will be prompted to end it. # If there is already a running instance, user will be prompted to end it.
updateicon() { \ updateicon() {
echo "$1" > /tmp/recordingicon echo "$1" > /tmp/recordingicon
pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"
} }
killrecording() { killrecording() {
recpid="$(cat /tmp/recordingpid)" recpid="$(cat /tmp/recordingpid)"
@ -25,9 +25,9 @@ killrecording() {
sleep 3 sleep 3
kill -9 "$recpid" kill -9 "$recpid"
exit exit
} }
screencast() { \ screencast() {
ffmpeg -y \ ffmpeg -y \
-f x11grab \ -f x11grab \
-framerate 60 \ -framerate 60 \
@ -39,9 +39,10 @@ screencast() { \
"$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
echo $! > /tmp/recordingpid echo $! > /tmp/recordingpid
updateicon "⏺️🎙️" updateicon "⏺️🎙️"
} }
video() { ffmpeg \ video() {
ffmpeg \
-f x11grab \ -f x11grab \
-s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \ -s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
-i "$DISPLAY" \ -i "$DISPLAY" \
@ -49,55 +50,55 @@ video() { ffmpeg \
"$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > /tmp/recordingpid echo $! > /tmp/recordingpid
updateicon "⏺️" updateicon "⏺️"
} }
webcamhidef() { ffmpeg \ webcamhidef() {
ffmpeg \
-f v4l2 \ -f v4l2 \
-i /dev/video0 \ -i /dev/video0 \
-video_size 1920x1080 \ -video_size 1920x1080 \
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > /tmp/recordingpid echo $! > /tmp/recordingpid
updateicon "🎥" updateicon "🎥"
} }
webcam() { ffmpeg \ webcam() {
ffmpeg \
-f v4l2 \ -f v4l2 \
-i /dev/video0 \ -i /dev/video0 \
-video_size 640x480 \ -video_size 640x480 \
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > /tmp/recordingpid echo $! > /tmp/recordingpid
updateicon "🎥" updateicon "🎥"
} }
audio() {
audio() { \
ffmpeg \ ffmpeg \
-f alsa -i default \ -f alsa -i default \
-c:a flac \ -c:a flac \
"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
echo $! > /tmp/recordingpid echo $! > /tmp/recordingpid
updateicon "🎙️" updateicon "🎙️"
} }
askrecording() { \ askrecording() {
choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:") choice=$(printf 'screencast\nvideo\nvideo selected\naudio\nwebcam\nwebcam (hi-def)' | dmenu -i -p "Select recording style:")
case "$choice" in case "$choice" in
screencast) screencast;; screencast) screencast ;;
audio) audio;; audio) audio ;;
video) video;; video) video ;;
*selected) videoselected;; *selected) videoselected ;;
webcam) webcam;; webcam) webcam ;;
"webcam (hi-def)") webcamhidef;; "webcam (hi-def)") webcamhidef ;;
esac esac
} }
asktoend() { \ asktoend() {
response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") && response=$(printf 'No\nYes' | dmenu -i -p "Recording still active. End recording?") \
[ "$response" = "Yes" ] && killrecording && [ "$response" = "Yes" ] && killrecording
} }
videoselected() videoselected() {
{
slop -f "%x %y %w %h" > /tmp/slop slop -f "%x %y %w %h" > /tmp/slop
read -r X Y W H < /tmp/slop read -r X Y W H < /tmp/slop
rm /tmp/slop rm /tmp/slop
@ -114,10 +115,10 @@ videoselected()
} }
case "$1" in case "$1" in
screencast) screencast;; screencast) screencast ;;
audio) audio;; audio) audio ;;
video) video;; video) video ;;
*selected) videoselected;; *selected) videoselected ;;
kill) killrecording;; kill) killrecording ;;
*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording ;;
esac esac

View File

@ -10,21 +10,21 @@ unmountusb() {
chosen="$(echo "$chosen" | awk '{print $1}')" chosen="$(echo "$chosen" | awk '{print $1}')"
[ -z "$chosen" ] && exit [ -z "$chosen" ] && exit
sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted."
} }
unmountandroid() { \ unmountandroid() {
chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1
[ -z "$chosen" ] && exit [ -z "$chosen" ] && exit
sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted."
} }
asktype() { \ asktype() {
choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 choice="$(printf 'USB\nAndroid' | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1
case "$choice" in case "$choice" in
USB) unmountusb ;; USB) unmountusb ;;
Android) unmountandroid ;; Android) unmountandroid ;;
esac esac
} }
drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')
@ -33,8 +33,7 @@ if ! grep simple-mtpfs /etc/mtab; then
echo "Unmountable USB drive detected." echo "Unmountable USB drive detected."
unmountusb unmountusb
else else
if [ -z "$drives" ] if [ -z "$drives" ]; then
then
echo "Unmountable Android device detected." echo "Unmountable Android device detected."
unmountandroid unmountandroid
else else

View File

@ -8,25 +8,25 @@
while getopts "hc" o; do case "${o}" in while getopts "hc" o; do case "${o}" in
c) extracthere="True" ;; c) extracthere="True" ;;
*) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit 1 ;; *) printf 'Options:\n -c: Extract archive into current directory rather than a new one.\n' && exit 1 ;;
esac done esac; done
if [ -z "$extracthere" ]; then if [ -z "$extracthere" ]; then
archive="$(readlink -f "$*")" && archive="$(readlink -f "$*")" \
directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" && && directory="$(echo "$archive" | sed 's/\.[^\/.]*$//')" \
mkdir -p "$directory" && && mkdir -p "$directory" \
cd "$directory" || exit 1 && cd "$directory" || exit 1
else else
archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2>/dev/null)" archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)" 2> /dev/null)"
fi fi
[ -z "$archive" ] && printf "Give archive to extract as argument.\\n" && exit 1 [ -z "$archive" ] && printf 'Give archive to extract as argument.\n' && exit 1
if [ -f "$archive" ] ; then if [ -f "$archive" ]; then
case "$archive" in case "$archive" in
*.tar.bz2|*.tbz2) tar xvjf "$archive" ;; *.tar.bz2 | *.tbz2) tar xvjf "$archive" ;;
*.tar.xz) tar -xf "$archive" ;; *.tar.xz) tar -xf "$archive" ;;
*.tar.gz|*.tgz) tar xvzf "$archive" ;; *.tar.gz | *.tgz) tar xvzf "$archive" ;;
*.tar.zst) tar -I zstd -xf "$archive" ;; *.tar.zst) tar -I zstd -xf "$archive" ;;
*.lzma) unlzma "$archive" ;; *.lzma) unlzma "$archive" ;;
*.bz2) bunzip2 "$archive" ;; *.bz2) bunzip2 "$archive" ;;
@ -41,5 +41,5 @@ if [ -f "$archive" ] ; then
*) printf "extract: '%s' - unknown archive method\\n" "$archive" ;; *) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
esac esac
else else
printf "File \"%s\" not found.\\n" "$archive" printf 'File "%s" not found.\n' "$archive"
fi fi

View File

@ -3,12 +3,12 @@
if [ -f "$1" ]; then if [ -f "$1" ]; then
# Try to get DOI from pdfinfo or pdftotext output. # Try to get DOI from pdfinfo or pdftotext output.
doi=$(pdfinfo "$1" | grep -io "doi:.*") || doi=$(pdfinfo "$1" | grep -io "doi:.*") \
doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi:.*" -m 1) || || doi=$(pdftotext "$1" - 2> /dev/null | grep -io "doi:.*" -m 1) \
exit 1 || exit 1
else else
doi="$1" doi="$1"
fi fi
# Check crossref.org for the bib citation. # Check crossref.org for the bib citation.
curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n" curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w '\n'

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
cat "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys/"$1" 2>/dev/null && exit 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:" echo "Run command with one of the following arguments for info about that program:"
ls "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys ls "${XDG_DATA_HOME:-$HOME/.local/share}"/larbs/getkeys

View File

@ -5,7 +5,7 @@
# it informs the user that they need that command to continue. This is used in # it informs the user that they need that command to continue. This is used in
# various other scripts for clarity's sake. # various other scripts for clarity's sake.
for x in "$@";do for x in "$@"; do
pacman -Qq "$x" >/dev/null 2>&1 || pacman -Qq "$x" > /dev/null 2>&1 \
{ notify-send "📦 $x" "must be installed for this function." && exit 1 ;} || { notify-send "📦 $x" "must be installed for this function." && exit 1; }
done done

View File

@ -7,17 +7,25 @@
# otherwise it opens link in browser. # otherwise it opens link in browser.
# If no url given. Opens browser. For using script as $BROWSER. # If no url given. Opens browser. For using script as $BROWSER.
[ -z "$1" ] && { "$BROWSER"; exit; } [ -z "$1" ] && {
"$BROWSER"
exit
}
case "$1" in case "$1" in
*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*) *mkv | *webm | *mp4 | *youtube.com/watch* | *youtube.com/playlist* | *youtu.be* | *hooktube.com* | *bitchute.com* | *videos.lukesmith.xyz*)
setsid -f mpv -quiet "$1" >/dev/null 2>&1 ;; 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 & ;; *png | *jpg | *jpe | *jpeg | *gif)
*pdf|*cbz|*cbr) 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 &
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*) *pdf | *cbz | *cbr)
qndl "$1" 'curl -LO' >/dev/null 2>&1 ;; 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 [ -f "$1" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$1" > /dev/null 2>&1 || setsid -f "$BROWSER" "$1" > /dev/null 2>&1
;;
esac esac

View File

@ -4,7 +4,7 @@
# choose the kind of screenshot to take, including copying the image or even # choose the kind of screenshot to take, including copying the image or even
# highlighting an area to copy. scrotcucks on suicidewatch right now. # 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 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" ;; "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" ;; "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" ;; "full screen") maim pic-full-"$(date '+%y%m%d-%H%M-%S').png" ;;

View File

@ -7,7 +7,7 @@
basename="$(echo "${*}" | sed 's/\.[^\/.]*$//')" basename="$(echo "${*}" | sed 's/\.[^\/.]*$//')"
case "${*}" in case "${*}" in
*.tex|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) setsid -f xdg-open "$basename".pdf >/dev/null 2>&1 ;; *.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 ;; *.html) setsid -f "$BROWSER" "$basename".html > /dev/null 2>&1 ;;
*.sent) setsid -f sent "$1" >/dev/null 2>&1 ;; *.sent) setsid -f sent "$1" > /dev/null 2>&1 ;;
esac esac

View File

@ -6,5 +6,5 @@
# (with other things) by default and is used in some other places. # (with other things) by default and is used in some other places.
for i in $(ls /tmp/mpvSockets/*); do for i in $(ls /tmp/mpvSockets/*); do
echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"; echo '{ "command": ["set_property", "pause", true] }' | socat - "$i"
done done

View File

@ -4,4 +4,4 @@
[ "$(pgrep -x "$(basename "$0")" | wc -l)" -gt 2 ] && exit [ "$(pgrep -x "$(basename "$0")" | wc -l)" -gt 2 ] && exit
echo "${XDG_DATA_HOME:-$HOME/.local/share}"/newsboat/queue | entr -p queueandnotify 2>/dev/null echo "${XDG_DATA_HOME:-$HOME/.local/share}"/newsboat/queue | entr -p queueandnotify 2> /dev/null

View File

@ -5,4 +5,4 @@
# For example: # For example:
# `./prompt "Do you want to shutdown?" "shutdown -h now"` # `./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 [ "$(printf 'No\nYes' | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray)" = "Yes" ] && $2

View File

@ -6,7 +6,8 @@ xset r rate 300 50
# Map the caps lock key to super... # Map the caps lock key to super...
setxkbmap -option caps:super setxkbmap -option caps:super
# But when it is pressed only once, treat it as escape. # But when it is pressed only once, treat it as escape.
killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' killall xcape 2> /dev/null
xcape -e 'Super_L=Escape'
# Map the menu button to right super as well. # Map the menu button to right super as well.
xmodmap -e 'keycode 135 = Super_R' xmodmap -e 'keycode 135 = Super_R'
# Turn off the caps lock if on since there is no longer a key for it. # Turn off the caps lock if on since there is no longer a key for it.

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
! echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" >/dev/null && ! echo "$1" | grep "https*://\S\+\.[A-Za-z]\+\S*" > /dev/null \
notify-send "That doesn't look like a full URL." && exit && notify-send "That doesn't look like a full URL." && exit
RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls" RSSFILE="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls"
if awk '{print $1}' "$RSSFILE" | grep "^$1$" >/dev/null; then if awk '{print $1}' "$RSSFILE" | grep "^$1$" > /dev/null; then
notify-send "You already have this RSS feed." notify-send "You already have this RSS feed."
else else
echo "$1" >> "$RSSFILE" && notify-send "RSS feed added." echo "$1" >> "$RSSFILE" && notify-send "RSS feed added."

View File

@ -9,16 +9,19 @@
# Location of link to wallpaper link. # Location of link to wallpaper link.
bgloc="${XDG_DATA_HOME:-$HOME/.local/share/}/bg" bgloc="${XDG_DATA_HOME:-$HOME/.local/share/}/bg"
trueloc="$(readlink -f "$1")" && trueloc="$(readlink -f "$1")" \
case "$(file --mime-type -b "$trueloc")" in && case "$(file --mime-type -b "$trueloc")" in
image/* ) ln -sf "$(readlink -f "$1")" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..." ;; 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." ;; 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 notify-send "Error" "Not a valid image."
exit 1
;;
esac
# If pywal is installed, use it. # If pywal is installed, use it.
command -v wal >/dev/null 2>&1 && command -v wal > /dev/null 2>&1 \
wal -i "$trueloc" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" >/dev/null 2>&1 && && wal -i "$trueloc" -o "${XDG_CONFIG_HOME:-$HOME/.config}/wal/postrun" > /dev/null 2>&1 \
pidof dwm >/dev/null && xdotool key super+F12 && pidof dwm > /dev/null && xdotool key super+F12
xwallpaper --zoom "$bgloc" xwallpaper --zoom "$bgloc"

View File

@ -12,14 +12,14 @@ fish_shortcuts="/dev/null"
vifm_shortcuts="/dev/null" vifm_shortcuts="/dev/null"
# Remove, prepare files # Remove, prepare files
rm -f "$ranger_shortcuts" "$qute_shortcuts" "$zsh_named_dirs" 2>/dev/null rm -f "$ranger_shortcuts" "$qute_shortcuts" "$zsh_named_dirs" 2> /dev/null
printf "# vim: filetype=sh\\n" > "$fish_shortcuts" printf '# vim: filetype=sh\n' > "$fish_shortcuts"
printf "# vim: filetype=sh\\nalias " > "$shell_shortcuts" printf '# vim: filetype=sh\nalias ' > "$shell_shortcuts"
printf "\" vim: filetype=vim\\n" > "$vifm_shortcuts" printf '" vim: filetype=vim\n' > "$vifm_shortcuts"
# Format the `directories` file in the correct syntax and sent it to all three configs. # Format the `directories` file in the correct syntax and sent it to all three configs.
eval "echo \"$(cat "$bmdirs")\"" | \ eval "echo \"$(cat "$bmdirs")\"" \
awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
printf(\"%s=\42cd %s && ls -a\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; printf(\"%s=\42cd %s && ls -a\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ;
printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; 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(\"abbr %s \42cd %s; and ls -a\42\n\",\$1,\$2) >> \"$fish_shortcuts\" ;
@ -28,8 +28,8 @@ awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
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 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\" }"
# Format the `files` file in the correct syntax and sent it to both configs. # Format the `files` file in the correct syntax and sent it to both configs.
eval "echo \"$(cat "$bmfiles")\"" | \ eval "echo \"$(cat "$bmfiles")\"" \
awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\"); | awk "!/^\s*#/ && !/^\s*\$/ {gsub(\"\\\s*#.*$\",\"\");
printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ; printf(\"%s=\42\$EDITOR %s\42 \\\\\n\",\$1,\$2) >> \"$shell_shortcuts\" ;
printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ; printf(\"hash -d %s=%s \n\",\$1,\$2) >> \"$zsh_named_dirs\" ;
printf(\"abbr %s \42\$EDITOR %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ; printf(\"abbr %s \42\$EDITOR %s\42 \n\",\$1,\$2) >> \"$fish_shortcuts\" ;

View File

@ -19,14 +19,18 @@ while getopts "hvrpi:c:a:o:d:f:t:e:x:" o; do case "${o}" in
r) redo="$OPTARG" ;; r) redo="$OPTARG" ;;
s) ppt="$OPTARG" ;; s) ppt="$OPTARG" ;;
e) endtime="$OPTARG" ;; e) endtime="$OPTARG" ;;
x) res="$OPTARG" x)
echo "$res" | grep -qv "^[0-9]\+x[0-9]\+$" && res="$OPTARG"
echo "Resolution must be dimensions separated by a 'x': 1280x720, etc." && echo "$res" | grep -qv "^[0-9]\+x[0-9]\+$" \
exit 1 ;; && echo "Resolution must be dimensions separated by a 'x': 1280x720, etc." \
p) echo "Purge old build files in $cache? [y/N]" && exit 1
;;
p)
echo "Purge old build files in $cache? [y/N]"
read -r confirm read -r confirm
echo "$confirm" | grep -iq "^y$" && rm -rf "$cache" && echo "Done." echo "$confirm" | grep -iq "^y$" && rm -rf "$cache" && echo "Done."
exit ;; exit
;;
v) verbose=True ;; v) verbose=True ;;
*) echo "$(basename "$0") usage: *) echo "$(basename "$0") usage:
-i input timecode list (required) -i input timecode list (required)
@ -40,32 +44,35 @@ while getopts "hvrpi:c:a:o:d:f:t:e:x:" o; do case "${o}" in
-d tmp directory -d tmp directory
-r rerun imagemagick commands even if done previously (in case files or background has changed) -r rerun imagemagick commands even if done previously (in case files or background has changed)
-p purge old build files instead of running -p purge old build files instead of running
-v be verbose" && exit 1 -v be verbose" && exit 1 ;;
esac done esac; done
# Check that the input file looks like it should. # Check that the input file looks like it should.
{ head -n 1 "$file" 2>/dev/null | grep -q "^00:00:00 " ;} || { { head -n 1 "$file" 2> /dev/null | grep -q "^00:00:00 "; } || {
echo "Give an input file with -i." && echo "Give an input file with -i." \
echo "The file should look as this example: && echo "The file should look as this example:
00:00:00 first_image.jpg 00:00:00 first_image.jpg
00:00:03 otherdirectory/next_image.jpg 00:00:03 otherdirectory/next_image.jpg
00:00:09 this_image_starts_at_9_seconds.jpg 00:00:09 this_image_starts_at_9_seconds.jpg
etc... etc...
Timecodes and filenames must be separated by Tabs." && Timecodes and filenames must be separated by Tabs." \
exit 1 && exit 1
} }
if [ -n "${audio+x}" ]; then if [ -n "${audio+x}" ]; then
# Check that the audio file looks like an actual audio file. # Check that the audio file looks like an actual audio file.
case "$(file --dereference --brief --mime-type -- "$audio")" in case "$(file --dereference --brief --mime-type -- "$audio")" in
audio/*) ;; audio/*) ;;
*) echo "That doesn't look like an audio file."; exit 1 ;; *)
echo "That doesn't look like an audio file."
exit 1
;;
esac esac
totseconds="$(date '+%s' -d $(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//))" totseconds="$(date '+%s' -d $(ffmpeg -i "$audio" 2>&1 | awk '/Duration/ {print $2}' | sed s/,//))"
endtime="$((totseconds-seconds))" endtime="$((totseconds - seconds))"
fi fi
prepdir="${prepdir:-$cache/$file}" prepdir="${prepdir:-$cache/$file}"
@ -76,8 +83,7 @@ prepfile="$prepdir/$file.prep"
mkdir -p "$prepdir" mkdir -p "$prepdir"
{ {
while read -r x; while read -r x; do
do
# Get the time from the first column. # Get the time from the first column.
time="${x%% *}" time="${x%% *}"
seconds="$(date '+%s' -d "$time")" seconds="$(date '+%s' -d "$time")"
@ -92,11 +98,11 @@ do
if [ -f "$content" ]; then if [ -f "$content" ]; then
# If images have already been made in a previous run, do not recreate # If images have already been made in a previous run, do not recreate
# them unless -r was given. # them unless -r was given.
{ [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ]; } \
convert -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base" && convert -size "${res:-1920x1080}" canvas:"${bgc:-black}" -gravity center "$content" -resize 1920x1080 -composite "$prepdir/$base"
else else
{ [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ] ;} && { [ ! -f "$prepdir/$base" ] || [ -n "${redo+x}" ]; } \
convert -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -pointsize "${ppt:-150}" -gravity center label:"$content" "$prepdir/$base" && convert -size "${res:-1920x1080}" -background "${bgc:-black}" -fill "${fgc:-white}" -pointsize "${ppt:-150}" -gravity center label:"$content" "$prepdir/$base"
fi fi
# If the first line, do not write yet. # If the first line, do not write yet.
@ -107,9 +113,9 @@ duration $duration"
prevbase="$base" prevbase="$base"
prevtime="$time" prevtime="$time"
prevseconds="$(date '+%s' -d "$prevtime")" prevseconds="$(date '+%s' -d "$prevtime")"
done < "$file" done < "$file"
# Do last file which must be given twice as follows # Do last file which must be given twice as follows
echo "file '$base' echo "file '$base'
duration ${endtime:-5} duration ${endtime:-5}
file '$base'" file '$base'"
} > "$prepfile" } > "$prepfile"

View File

@ -32,5 +32,6 @@ for battery in /sys/class/power_supply/BAT?*; do
# Will make a warn variable if discharging and low # Will make a warn variable if discharging and low
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗" [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
# Prints the info # Prints the info
printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn printf "%s%s%d%%" "$status" "$warn" "$capacity"
unset warn
done && exit 0 done && exit 0

View File

@ -11,7 +11,7 @@ cache=/tmp/cpubarscache
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
2) setsid -f "$TERMINAL" -e htop ;; 2) setsid -f "$TERMINAL" -e htop ;;
3) notify-send "🪨 CPU load module" "Each bar represents 3) notify-send "🪨 CPU load module" "Each bar represents
one CPU core";; one CPU core" ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac esac
@ -30,15 +30,16 @@ echo "$stats" | while read -r row; do
printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \
id="$id" total="$total" idle="$idle")" in id="$id" total="$total" idle="$idle")" in
"0") printf "▁";; "0") printf "▁" ;;
"1") printf "▂";; "1") printf "▂" ;;
"2") printf "▃";; "2") printf "▃" ;;
"3") printf "▄";; "3") printf "▄" ;;
"4") printf "▅";; "4") printf "▅" ;;
"5") printf "▆";; "5") printf "▆" ;;
"6") printf "▇";; "6") printf "▇" ;;
"7") printf "█";; "7") printf "█" ;;
"8") printf "█";; "8") printf "█" ;;
esac esac
done; printf "\\n" done
printf '\n'
echo "$stats" > "$cache" echo "$stats" > "$cache"

View File

@ -15,9 +15,9 @@ case $BLOCK_BUTTON in
esac esac
case "$location" in case "$location" in
"/home"* ) icon="🏠" ;; "/home"*) icon="🏠" ;;
"/mnt"* ) icon="💾" ;; "/mnt"*) icon="💾" ;;
*) icon="🖥";; *) icon="🖥" ;;
esac esac
printf "%s: %s\n" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" printf "%s: %s\n" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')"

View File

@ -7,14 +7,16 @@
# You could set up a shell alias to view the full file in a pager in the # 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. # terminal if desired. This function will only be run once a day when needed.
weatherreport="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" weatherreport="${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport"
getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;} getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1; }
# Some very particular and terse stream manipulation. We get the maximum # Some very particular and terse stream manipulation. We get the maximum
# precipitation chance and the daily high and low from the downloaded file and # precipitation chance and the daily high and low from the downloaded file and
# display them with coresponding emojis. # display them with coresponding emojis.
showweather() { printf "%s" "$(sed '16q;d' "$weatherreport" | showweather() {
grep -wo "[0-9]*%" | sort -rn | sed "s/^/☔/g;1q" | tr -d '\n')" printf "%s" "$(sed '16q;d' "$weatherreport" \
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 "°"}' ;} | 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 case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;; 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;;
@ -29,7 +31,7 @@ esac
# The test if our forcecast is updated to the day. If it isn't download a new # 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. # weather report from wttr.in with the above function.
[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || [ "$(stat -c %y "$weatherreport" 2> /dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] \
getforecast || getforecast
showweather showweather

View File

@ -3,10 +3,10 @@
# The clickable help menu. Middle click to restart wm. # The clickable help menu. Middle click to restart wm.
# If dwm is running, use dwm's readme and restart. # If dwm is running, use dwm's readme and restart.
pidof dwm >/dev/null && pidof dwm > /dev/null \
READMEFILE=/usr/local/share/dwm/larbs.mom && READMEFILE=/usr/local/share/dwm/larbs.mom
restartwm() { pkill -HUP dwm ;} || restartwm() { pkill -HUP dwm; } \
restartwm() { i3 restart ;} || restartwm() { i3 restart; }
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) groff -mom "${READMEFILE:-${XDG_DATA_HOME:-$HOME/.local/share}/larbs/readme.mom}" -Tpdf | zathura - ;; 1) groff -mom "${READMEFILE:-${XDG_DATA_HOME:-$HOME/.local/share}/larbs/readme.mom}" -Tpdf | zathura - ;;
@ -14,4 +14,5 @@ case $BLOCK_BUTTON in
3) notify-send "❓ Help module" "\- Left click to open LARBS guide. 3) notify-send "❓ Help module" "\- Left click to open LARBS guide.
- Middle click to refresh window manager." ;; - Middle click to refresh window manager." ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac; echo "❓" esac
echo "❓"

View File

@ -5,7 +5,10 @@
# Show 🔒 if a vpn connection is active # Show 🔒 if a vpn connection is active
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;; 1)
"$TERMINAL" -e nmtui
pkill -RTMIN+4 dwmblocks
;;
3) notify-send "🌐 Internet module" "\- Click to connect 3) notify-send "🌐 Internet module" "\- Click to connect
📡: no wifi connection 📡: no wifi connection
📶: wifi connection with quality 📶: wifi connection with quality
@ -16,9 +19,9 @@ case $BLOCK_BUTTON in
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac esac
case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in case "$(cat /sys/class/net/w*/operstate 2> /dev/null)" in
down) wifiicon="📡 " ;; down) wifiicon="📡 " ;;
up) wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;; up) wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;;
esac esac
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)" 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)"

View File

@ -6,5 +6,5 @@
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/ # https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
ifinstalled "geoip" || exit ifinstalled "geoip" || exit
addr="$(curl ifconfig.me 2>/dev/null)" || 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/;.*//" grep "flag: " "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji" | grep "$(geoiplookup "$addr" | sed 's/.*, //')" | sed "s/flag: //;s/;.*//"

View File

@ -4,12 +4,14 @@
kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1 kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1
case $BLOCK_BUTTON in 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)" 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}')" kb="$(echo "$kb_choice" | awk '{print $3}')"
setxkbmap "$kb" setxkbmap "$kb"
pkill -RTMIN+30 "${STATUSBAR:-dwmblocks}";; pkill -RTMIN+30 "${STATUSBAR:-dwmblocks}"
;;
3) notify-send "⌨ Keyboard/language module" "$(printf "%s" "\- Current layout: $(setxkbmap -query | grep -oP 'layout:\s*\K\w+')") 3) notify-send "⌨ Keyboard/language module" "$(printf "%s" "\- Current layout: $(setxkbmap -query | grep -oP 'layout:\s*\K\w+')")
- Left click to change keyboard.";; - Left click to change keyboard." ;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac esac

View File

@ -5,7 +5,7 @@
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e neomutt ;; 1) setsid -f "$TERMINAL" -e neomutt ;;
2) setsid -f mw sync >/dev/null ;; 2) setsid -f mw sync > /dev/null ;;
3) notify-send "📬 Mail module" "\- Shows unread mail 3) notify-send "📬 Mail module" "\- Shows unread mail
- Shows 🔃 if syncing mail - Shows 🔃 if syncing mail
- Left click opens neomutt - Left click opens neomutt
@ -13,8 +13,8 @@ case $BLOCK_BUTTON in
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac esac
unread="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l 2>/dev/null)" 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="🔃" pidof mbsync > /dev/null 2>&1 && icon="🔃"
[ "$unread" = "0" ] && [ "$icon" = "" ] || echo "📬$unread$icon" [ "$unread" = "0" ] && [ "$icon" = "" ] || echo "📬$unread$icon"

View File

@ -4,8 +4,8 @@
moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase" moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase"
[ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || [ "$(stat -c %y "$moonfile" 2> /dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] \
{ curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;} || { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1; }
icon="$(cat "$moonfile")" icon="$(cat "$moonfile")"

View File

@ -3,6 +3,6 @@
# This loop will update the mpd statusbar module whenever a command changes the # 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. # music player's status. mpd must be running on X's start for this to work.
while : ; do while :; do
mpc idle >/dev/null && kill -45 "$(pidof "${STATUSBAR:-dwmblocks}")" || break mpc idle > /dev/null && kill -45 "$(pidof "${STATUSBAR:-dwmblocks}")" || break
done done

View File

@ -1,19 +1,28 @@
#!/bin/sh #!/bin/sh
filter() { mpc | sed "/^volume:/d;s/\\&/&amp;/g;s/\\[paused\\].*/⏸/g;/\\[playing\\].*/d" | paste -sd ' ' -;} filter() { mpc | sed '/^volume:/d;s/\&/&amp;/g;s/\[paused\].*/⏸/g;/\[playing\].*/d' | paste -sd ' ' -; }
pidof -x sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & pidof -x sb-mpdup > /dev/null 2>&1 || sb-mpdup > /dev/null 2>&1 &
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) mpc status | filter ; setsid -f "$TERMINAL" -e ncmpcpp ;; # right click, pause/unpause 1)
mpc status | filter
setsid -f "$TERMINAL" -e ncmpcpp
;; # right click, pause/unpause
2) mpc toggle | filter ;; # right click, pause/unpause 2) mpc toggle | filter ;; # right click, pause/unpause
3) mpc status | filter ; notify-send "🎵 Music module" "\- Shows mpd song playing. 3)
mpc status | filter
notify-send "🎵 Music module" "\- Shows mpd song playing.
- ⏸ when paused. - ⏸ when paused.
- Left click opens ncmpcpp. - Left click opens ncmpcpp.
- Middle click pauses. - Middle click pauses.
- Scroll changes track.";; # right click, pause/unpause - Scroll changes track."
;; # right click, pause/unpause
4) mpc prev | filter ;; # scroll up, previous 4) mpc prev | filter ;; # scroll up, previous
5) mpc next | filter ;; # scroll down, next 5) mpc next | filter ;; # scroll down, next
6) mpc status | filter ; "$TERMINAL" -e "$EDITOR" "$0" ;; 6)
mpc status | filter
"$TERMINAL" -e "$EDITOR" "$0"
;;
*) mpc status | filter ;; *) mpc status | filter ;;
esac esac

View File

@ -15,15 +15,15 @@ update() {
sum=0 sum=0
for arg; do for arg; do
read -r i < "$arg" read -r i < "$arg"
sum=$(( sum + i )) sum=$((sum + i))
done done
cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/} cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/}
[ -f "$cache" ] && read -r old < "$cache" || old=0 [ -f "$cache" ] && read -r old < "$cache" || old=0
printf %d\\n "$sum" > "$cache" printf %d\\n "$sum" > "$cache"
printf %d\\n $(( sum - old )) printf %d\\n $((sum - old))
} }
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
printf "🔻%4sB 🔺%4sB\\n" $(numfmt --to=iec $rx) $(numfmt --to=iec $tx) printf '🔻%4sB 🔺%4sB\n' $(numfmt --to=iec $rx) $(numfmt --to=iec $tx)

View File

@ -5,7 +5,7 @@
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e newsboat ;; 1) setsid "$TERMINAL" -e newsboat ;;
2) setsid -f newsup >/dev/null exit ;; 2) setsid -f newsup exit > /dev/null ;;
3) notify-send "📰 News module" "\- Shows unread news items 3) notify-send "📰 News module" "\- Shows unread news items
- Shows 🔃 if updating with \`newsup\` - Shows 🔃 if updating with \`newsup\`
- Left click opens newsboat - Left click opens newsboat
@ -14,4 +14,4 @@ case $BLOCK_BUTTON in
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac 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)" 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)"

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
printf "Beginning upgrade.\\n" printf 'Beginning upgrade.\n'
yay -Syu yay -Syu
pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}" pkill -RTMIN+8 "${STATUSBAR:-dwmblocks}"
printf "\\nUpgrade complete.\\nPress <Enter> to exit window.\\n\\n" printf '\nUpgrade complete.\nPress <Enter> to exit window.\n\n'
read -r _ read -r _

View File

@ -11,27 +11,31 @@ dir="${XDG_DATA_HOME:-$HOME/.local/share}/crypto-prices"
pricefile="$dir/$1" pricefile="$dir/$1"
chartfile="$dir/$1-chart" chartfile="$dir/$1-chart"
updateprice() { ping -q -c 1 example.org >/dev/null 2>&1 && updateprice() { ping -q -c 1 example.org > /dev/null 2>&1 \
curl -s "rate.sx/1$1" > "$pricefile" && && curl -s "rate.sx/1$1" > "$pricefile" \
curl -s "rate.sx/$1$interval" > "$chartfile" ;} && curl -s "rate.sx/$1$interval" > "$chartfile"; }
[ -d "$dir" ] || mkdir -p "$dir" [ -d "$dir" ] || mkdir -p "$dir"
[ "$(stat -c %x "$pricefile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] && [ "$(stat -c %x "$pricefile" 2> /dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ] \
updateprice "$1" && updateprice "$1"
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;; 1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
2) notify-send -u low "$3 Updating..." "Updating $2 price..." 2)
notify-send -u low "$3 Updating..." "Updating $2 price..."
updateprice "$1" && notify-send "$3 Update complete." "$2 price is now updateprice "$1" && notify-send "$3 Update complete." "$2 price is now
\$$(cat "$pricefile")" ;; \$$(cat "$pricefile")"
3) uptime="$(date -d "$(stat -c %x "$pricefile")" '+%D at %T' | sed "s|$(date '+%D')|Today|")" ;;
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> notify-send "$3 $2 module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
- Left click for chart of changes. - Left click for chart of changes.
- Middle click to update. - Middle click to update.
- Shows 🔃 if updating prices. - Shows 🔃 if updating prices.
- <b>Last updated: - <b>Last updated:
$uptime</b>" ;; $uptime</b>"
;;
6) "$TERMINAL" -e "$EDITOR" "$0" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac esac

View File

@ -16,5 +16,5 @@ case $BLOCK_BUTTON in
2) $EDITOR "$0" ;; # Middle click 2) $EDITOR "$0" ;; # Middle click
esac esac
[ "$num" != "0(0)" ] && [ "$num" != "0(0)" ] \
echo "🤖$num" && echo "🤖$num"

View File

@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
transmission-remote -l | grep % | transmission-remote -l | grep % \
sed " # The letters are for sorting and will not appear. | sed " # The letters are for sorting and will not appear.
s/.*Stopped.*/A 🛑/; s/.*Stopped.*/A 🛑/;
s/.*Seeding.*/Z 🌱/; s/.*Seeding.*/Z 🌱/;
s/.*100%.*/N ✅/; s/.*100%.*/N ✅/;
s/.*Idle.*/B 🕰️/; s/.*Idle.*/B 🕰️/;
s/.*Uploading.*/L ⬆️/; s/.*Uploading.*/L ⬆️/;
s/.*%.*/M ⬇️/" | s/.*%.*/M ⬇️/" \
sort -h | uniq -c | awk '{print $3 $1}' | paste -sd ' ' - | sort -h | uniq -c | awk '{print $3 $1}' | paste -sd ' ' -
case $BLOCK_BUTTON in case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e tremc ;; 1) setsid -f "$TERMINAL" -e tremc ;;

View File

@ -5,7 +5,10 @@
# For non-systemd init systems. # For non-systemd init systems.
case "$(readlink -f /sbin/init)" in case "$(readlink -f /sbin/init)" in
*runit*) hib="sudo -A zzz" ;; *runit*) hib="sudo -A zzz" ;;
*openrc*) reb="sudo -A openrc-shutdown -r"; shut="sudo -A openrc-shutdown -p" ;; *openrc*)
reb="sudo -A openrc-shutdown -r"
shut="sudo -A openrc-shutdown -p"
;;
esac esac
cmds="\ cmds="\
@ -18,4 +21,4 @@ cmds="\
choice="$(echo "$cmds" | cut -d' ' -f 1 | dmenu)" || exit 1 choice="$(echo "$cmds" | cut -d' ' -f 1 | dmenu)" || exit 1
`echo "$cmds" | grep "^$choice " | cut -d ' ' -f2-` $(echo "$cmds" | grep "^$choice " | cut -d ' ' -f2-)

View File

@ -11,7 +11,7 @@ Options:
-d: year of publication -d: year of publication
-g: genre -g: genre
-c: comment -c: comment
You will be prompted for title, artist, album and track if not given." && exit 1 ;} 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 while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in
a) artist="${OPTARG}" ;; a) artist="${OPTARG}" ;;
@ -23,8 +23,8 @@ while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in
g) genre="${OPTARG}" ;; g) genre="${OPTARG}" ;;
c) comment="${OPTARG}" ;; c) comment="${OPTARG}" ;;
f) file="${OPTARG}" ;; f) file="${OPTARG}" ;;
*) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; *) printf 'Invalid option: -%s\n' "$OPTARG" && err ;;
esac done esac; done
shift $((OPTIND - 1)) shift $((OPTIND - 1))

View File

@ -2,11 +2,10 @@
# If transmission-daemon is running, will ask to kill, else will ask to start. # If transmission-daemon is running, will ask to kill, else will ask to start.
if pidof transmission-daemon >/dev/null ; if pidof transmission-daemon > /dev/null; then
then [ "$(printf 'No\nYes' | dmenu -i -p "Turn off transmission-daemon?")" = "Yes" ] && killall transmission-da && notify-send "transmission-daemon disabled."
[ "$(printf "No\\nYes" | dmenu -i -p "Turn off transmission-daemon?")" = "Yes" ] && killall transmission-da && notify-send "transmission-daemon disabled."
else else
ifinstalled transmission-cli || exit ifinstalled transmission-cli || exit
[ "$(printf "No\\nYes" | dmenu -i -p "Turn on transmission daemon?")" = "Yes" ] && transmission-daemon && notify-send "tranmission-daemon enabled." [ "$(printf 'No\nYes' | dmenu -i -p "Turn on transmission daemon?")" = "Yes" ] && transmission-daemon && notify-send "tranmission-daemon enabled."
fi fi
sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" sleep 3 && pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}"

View File

@ -11,6 +11,5 @@ case "$1" in
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 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)" rm -rdf "$dir/_minted-$(basename -- $base)"
;; ;;
*) printf "Give .tex file as argument.\\n" ;; *) printf 'Give .tex file as argument.\n' ;;
esac esac

View File

@ -2,6 +2,7 @@
ifinstalled tremc-git transmission-cli || exit ifinstalled tremc-git transmission-cli || exit
! pidof transmission-daemon >/dev/null && transmission-daemon && notify-send "Starting torrent daemon..." ! pidof transmission-daemon > /dev/null && transmission-daemon && notify-send "Starting torrent daemon..."
$TERMINAL -e tremc; pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}" $TERMINAL -e tremc
pkill -RTMIN+7 "${STATUSBAR:-dwmblocks}"

View File

@ -4,6 +4,6 @@
# transmission-daemon sometimes fails to take remote requests in its first moments, hence the sleep. # 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}") 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." transmission-remote -a "$@" && notify-send "🔽 Torrent added."