Renombrado de scripts

Se ha añadido la extensión .sh para poder identificar que se tratan de script de shell
This commit is contained in:
Tuxliban Torvalds 2023-05-05 18:50:15 -06:00
parent 93d6e98e6c
commit 379798d954
58 changed files with 2081 additions and 518 deletions

View File

@ -1,31 +0,0 @@
#!/bin/sh
## Script de notificación para la bateria
restante=$(acpi | awk '{print $5}')
#estado=$(acpi | awk '{print $3}' | cut -d"," -f1)
estado=$(cat /sys/class/power_supply/BAT1/capacity_level)
porcentaje=$(cat /sys/class/power_supply/BAT1/capacity)
# Si el porcentaje de bateria es menor o igual a 30 y mayor a 25, mostrar el mensaje
if [ "$porcentaje" -le 30 ] && [ "$porcentaje" -gt 25 ]; then
notify-send --urgency=normal -i $HOME/.icons/status/battery_low.png "Conectar el cargador" "Tiempo de bateria disponible $restante"
fi
# Si el porcentaje de bateria es igual o menor a 25, mostrar el siguiente mensaje y...
# 1. Si se conecta el cargador no suspender el equipo
# 2. Si no se conecta el cargador suspender el equipo
if [ "$porcentaje" -le 25 ]; then
notify-send --urgency=critical -i $HOME/.icons/status/battery_critical.png "Batería crítica" "Activando modo de ahorro de \nenergia en 30 segundos..."
sleep 30 &&
if [ "$estado" = "Charging" ]; then
notify-send --urgency=normal "Cargando bateria"
else
doas zzz
fi
fi
# Si el porcentaje de la bateria es igual al 100% mostrar el siguiente mensaje
#if [ "$porcentaje" -eq "100" ]; then
# notify-send --urgency=normal -i $HOME/.icons/status/battery_charged.png "Bateria cargada" "Puede desconectar el cargador"
#fi

View File

@ -1,6 +1,12 @@
#!/bin/sh
# Script para buscar enlaces simbólicos rotos en el directorio actual
# Si se desea buscar en todo el sistema cambiar ./ por /
#
# Dependencias: find
#
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
set -e # Si hay un error, salir inmediatamente
find ./ -type l > tmp
while IFS= read -r file

19
varios/check_script.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
# Script que revisa la sintaxis en busca de bashismos y que sea compatible con el estándar POSIX
#
# Dependencias: shellcheck, checkbashisms
#
# Uso:
# check_script filepath
#
# Shell: POSIX compliant
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
if ! command -v shellcheck >/dev/null; then
printf '%b' "\033[31;5m[ERROR] Instale el paquete 'shellcheck'\033[0m\n"
elif ! command -v checkbashisms >/dev/null; then
printf '%b' "\033[31;5m[ERROR] Instale el paquete 'checkbashisms'\033[0m\n"
fi
glibc shellcheck "$1"
checkbashisms "$1"

View File

@ -1,4 +0,0 @@
#!/bin/sh
CIUDAD=foo
CLIMA=$(curl -s wttr.in/$CIUDAD?format=1 | grep -o "[0-9].*")
echo " $CLIMA" > /tmp/weather

9
varios/clima.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
# Scrip que muestra la temperatura climática de la ciudad especificada
# Dependencias: curl
#
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
CIUDAD=foo
CLIMA=$(curl -s wttr.in/$CIUDAD?format=1 | grep -o "[0-9].*")
echo "$CLIMA" > /tmp/weather

View File

@ -1,51 +0,0 @@
#!/bin/sh
# Colores tipo bold
printf '%b' "\033[30;1mGris\033[0m\n"
printf '%b' "\033[31;1mRojo\033[0m\n"
printf '%b' "\033[32;1mVerde\033[0m\n"
printf '%b' "\033[33;1mAmarillo\033[0m\n"
printf '%b' "\033[34;1mAzul\033[0m\n"
printf '%b' "\033[35;1mRosa\033[0m\n"
printf '%b' "\033[36;1mAqua\033[0m\n"
printf '%b' "\033[37;1mBlanco\033[0m\n"
printf "\n"
# Colores claros
printf '%b' "\033[31;2mRojo\033[0m\n"
printf '%b' "\033[32;2mVerde\033[0m\n"
printf '%b' "\033[33;2mAmarillo\033[0m\n"
printf '%b' "\033[34;2mAzul\033[0m\n"
printf '%b' "\033[35;2mRosa\033[0m\n"
printf '%b' "\033[36;2mAqua\033[0m\n"
printf '%b' "\033[37;2mBlanco\033[0m\n"
printf "\n"
# Colores letra cursiva
printf '%b' "\033[31;3mRojo\033[0m\n"
printf '%b' "\033[32;3mVerde\033[0m\n"
printf '%b' "\033[33;3mAmarillo\033[0m\n"
printf '%b' "\033[34;3mAzul\033[0m\n"
printf '%b' "\033[35;3mRosa\033[0m\n"
printf '%b' "\033[36;3mAqua\033[0m\n"
printf '%b' "\033[37;3mBlanco\033[0m\n"
printf "\n"
# Colores letra subrayada
printf '%b' "\033[31;4mRojo\033[0m\n"
printf '%b' "\033[32;4mVerde\033[0m\n"
printf '%b' "\033[33;4mAmarillo\033[0m\n"
printf '%b' "\033[34;4mAzul\033[0m\n"
printf '%b' "\033[35;4mRosa\033[0m\n"
printf '%b' "\033[36;4mAqua\033[0m\n"
printf '%b' "\033[37;4mBlanco\033[0m\n"
printf "\n"
# Colores y texto parpadeando
printf '%b' "\033[31;5mRojo\033[0m\n"
printf '%b' "\033[32;5mVerde\033[0m\n"
printf '%b' "\033[33;5mAmarillo\033[0m\n"
printf '%b' "\033[34;5mAzul\033[0m\n"
printf '%b' "\033[35;5mRosa\033[0m\n"
printf '%b' "\033[36;5mAqua\033[0m\n"
printf '%b' "\033[37;5mBlanco\033[0m\n"

View File

@ -9,6 +9,8 @@
#
# If there is already a running instance, user will be prompted to end it.
RES=$(sed 's/,/x/g' /sys/class/graphics/fb?/virtual_size)
updateicon() { \
echo "$1" > /tmp/recordingicon
pkill -RTMIN+9 "${STATUSBAR:?}"
@ -31,13 +33,13 @@ screencast() { \
ffmpeg -y \
-f x11grab \
-framerate 24 \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i $DISPLAY \
# -f alsa -i default \
-f sndio -i snd/0 \
-s "$RES" \
-i "$DISPLAY" \
-f alsa -i default \
# -f sndio -i snd/0 \
-r 24 -async 1 -vsync -1 \
-c:v libx264rgb -crf 0 -preset ultrafast -c:a aac \
# -preset ultrafast -c:a libvorbis \
-preset ultrafast -c:a libvorbis \
"$HOME/screencast-$(date '+%y%m%d-%H%M%S').mkv" &
echo $! > /tmp/recordingpid
updateicon "⏺️🎙️"
@ -47,8 +49,8 @@ screencastmobile() { \
ffmpeg -y \
-f x11grab \
-framerate 60 \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i $DISPLAY \
-s "$RES" \
-i "$DISPLAY" \
-f alsa -i default \
-r 30 \
-c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p -loglevel panic -c:a aac \
@ -59,8 +61,8 @@ screencastmobile() { \
video() { ffmpeg \
-f x11grab \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i $DISPLAY \
-s "$RES" \
-i "$DISPLAY" \
-c:v libx264 -qp 0 -r 30 \
"$HOME/video-$(date '+%y%m%d-%H%M%S').mkv" &
echo $! > /tmp/recordingpid
@ -71,8 +73,8 @@ videomobile() { \
ffmpeg -y \
-f x11grab \
-framerate 60 \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i $DISPLAY \
-s "$RES" \
-i "$DISPLAY" \
-r 30 \
-c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p -loglevel panic\
"$HOME/video-$(date '+%y%m%d-%H%M%S').mp4" &
@ -108,7 +110,7 @@ audio() { \
}
askrecording() { \
choice=$(printf "screencast\\nvideo\\naudio\\nwebcam\\nscreencastmobile\\nvideomobile" | dmenu -i -sb "#4D4270" -p "Seleccione el modo de grabación:")
choice=$(printf "screencast\\nwebcam\\nscreencastmobile\\nvideomobile" | dmenu -i -sb "#4D4270" -p "Seleccione el modo de grabación:")
case "$choice" in
screencast) screencast;;
audio) audio;;

View File

@ -9,7 +9,7 @@
# do_script filepath
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
# Validar que el archivo proporcionado como argumento existe y es válido
if [ ! -f "$1" ]; then

View File

@ -4,7 +4,7 @@
# Dependencias xelatex, pandoc
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
# Nombre del script usando la sustitución de parámetros
@ -20,7 +20,7 @@ elif ! command -v pandoc > /dev/null; then
fi
ayuda() {
cat << EOF
printf %s "\
Convierte documentos docx a formato PDF.
Uso: $script <arg> <directorio o archivo>
@ -28,7 +28,7 @@ Uso: $script <arg> <directorio o archivo>
$script --conv /path/foo.docx Convierte archivo especificado
$script -c /path/ Convierte archivos compatibles del directorio especificado
EOF
"
}
case $1 in

View File

@ -1,2 +0,0 @@
#!/bin/sh
aplay "$HOME/Dropbox/Gitea/linux_dots/config/dunst/beep.wav"

2
varios/dunst_sound.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
aplay "$HOME/Dropbox/Gitea/linux_dots/home/config/dunst/beep.wav"

View File

@ -6,7 +6,7 @@
# escript filepath
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
# Buscar el archivo en el PATH del sistema
FILE_PATH=$(command -v "$1" 2>/dev/null)

6
varios/facecam.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# Abre una ventana de streaming de la cámara web.
# Requiere de ffplay (dependencia de ffmpeg)
ffplay -i /dev/video0

View File

@ -1,13 +1,19 @@
#!/bin/sh
# Script que muestra notificaciones de paquetes nuevos en el repositorio remoto,
# actualizaciones remotas y actualizaciones disponibles para el sistema
# actualizaciones remotas y actualizaciones disponibles para el sistema.
#
# Dependencias: rstail
#
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
if command -v rsstail; then
rsstail -1 -u https://github.com/void-linux/void-packages/commits/master.atom > /tmp/feed
updatedpkgs="$(grep -E "Update|update" /tmp/feed | wc -l)"
newpkgs="$(grep -E "New|new" /tmp/feed | wc -l)"
sysupdates="$(xbps-install -Mnu | wc -l)"
if ! command -v rsstail >/dev/null; then
printf "\033[31;5m[ERROR] Este script requiere del paquete: 'rsstail'\033[0m\n"
exit 1;
elif command -v rsstail >/dev/null; then
rsstail -1 -u https://github.com/void-linux/void-packages/commits/master.atom > /tmp/feed
updatedpkgs="$(grep -E "Update|update" /tmp/feed | wc -l)"
newpkgs="$(grep -E "New|new" /tmp/feed | wc -l)"
sysupdates="$(xbps-install -Mnu | wc -l)"
# Notificación emergente
notify-send --urgency=critical """CAMBIOS EN EL REPOSITORIO:
@ -27,10 +33,4 @@ printf "\n"
printf "\033[32;1mACTUALIZACIONES DE SISTEMA:\033[0m\n"
printf "\033[33;5m Disponible actualmente: \033[0m"${sysupdates}
printf "\n"
# En caso de existir errores
elif ! command -v rsstail; then
printf "\033[31;5m[ERROR] Este script requiere del paquete: 'rsstail'\033[0m\n"
exit 0;
fi

View File

@ -5,9 +5,10 @@
# 3 - Operación exitosa, pero no se seleccionó un archivo
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
_PATH="$HOME"
#_PATH="$HOME"
_PATH="$PWD"
book=$(find "$_PATH" -name '*.pdf' -printf '%f\n' | dmenu -l 10 -p "Library")
_book=$(find "$_PATH" -name "$book")

6
varios/fstrim.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# Script para darle mantemiento al SSD
#doas fstrim /
#doas fstrim --quiet-unsupported /home
doas fstrim --all || true

7
varios/get_info.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
## Scrip para obtener información de las ventanas activas: class, instance
## Dependencias xprop
xprop | awk '
/^WM_CLASS/{sub(/.* =/, "instance:"); sub(/,/,"\nclass:"); print}
/^WN_NAME/{sub(/.* =/, "title:"); print}'

View File

@ -4,7 +4,7 @@
# Dependencias: moc
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
if [ "$(mocp -Q %state)" != "STOP" ];then
SONG=$(mocp -Q %song)

View File

@ -1,5 +1,5 @@
#!/bin/sh
# V0.3.1
# V0.3.2
# Script para descargar una lista personalizada con direcciones para bloquearlas
# a través del fichero hosts. Para automatizar este proceso se recomienda crear
# una tarea (crontab) y ajustarla a las necesidades del usuario (diario, semanal
@ -7,8 +7,7 @@
#
# Dependencias: dzen2, wget
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
msg() {
dzen2 -p '10' -fn 'JetBrains Mono:size=8:style=bold' -ta '5' \
@ -16,7 +15,7 @@ msg() {
}
which_sudo() {
if [ "$(id -u)" = "0" ]; then
if [ "$(id -u)" -eq 0 ]; then
return
elif command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then
echo sudo
@ -31,17 +30,20 @@ SUDO=$(which_sudo)
# Realizar copia de seguridad del fichero hosts en caso de no existir
if [ ! -f /etc/hosts.bak ]; then
printf '%b' "\033[32;1mCreando copia de seguridad del fichero hosts...\033[0m\n";
$SUDO cp /etc/hosts /etc/hosts.bak && sleep 1s; printf "\033[33;1mCopia finalizada\033[0m\n"
printf '%b' "\033[32;1mCreando copia de seguridad del fichero hosts...\033[0m\n"
$SUDO cp /etc/hosts /etc/hosts.bak
printf "\033[33;1mCopia finalizada\033[0m\n"
else
printf '%b' "\033[35;5mYa existe copia de seguridad del fichero hosts\033[0m\n"
fi
# Descargar actualización más reciente del fichero hosts
printf '%b' "\033[32;1mDescargando y copiando lista actualizada para fichero hosts...\033[0m\n" &&
wget -O /tmp/hosts http://sbc.io/hosts/alternates/fakenews-gambling-porn/hosts && "$HOME"/.local/bin/custom_sites
$SUDO mv /tmp/hosts /etc/hosts && "$HOME"/.local/bin/dunst_sound &
printf '%b' "\033[32;1mDescargando y copiando lista actualizada para fichero hosts...\033[0m\n"
wget -O /tmp/hosts http://sbc.io/hosts/alternates/fakenews-gambling-porn/hosts
"$HOME"/.local/bin/custom_sites
$SUDO mv /tmp/hosts /etc/hosts
"$HOME"/.local/bin/dunst_sound 2>/dev/null
# Notificacion de actualizacion del fichero
printf '%b' "\033[36;1mFichero hosts actualizado.\033[0m\n";
printf '%b' "\033[36;1mFichero hosts actualizado.\033[0m\n"
printf '%s\n' "Lista de fichero hosts actualizado" | msg &

View File

@ -1,11 +1,11 @@
#!/bin/sh
# v0.2
# v0.3
# Dependencias:ImageMagick, xclip, dzen2, xdotool
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
: "${script:="${0##*/}"}"
script="${0##*/}"
DIR="$HOME"/Datos/Capturas
DATE="$(date +%Y%m%d-%H%M%S)"
@ -36,7 +36,7 @@ elif ! command -v xdotool > /dev/null; then
fi
ayuda() {
cat << EOF
printf %s "\
Script para realizar capturas de pantalla utilizando ImageMagick.
Modo de uso:
@ -49,7 +49,7 @@ Modo de uso:
-F Guardar captura de pantalla de ventana activa en el disco duro
--help | -h Mostrar este mensaje de ayuda
EOF
"
}
msg() {
@ -68,25 +68,19 @@ case "$1" in
import -window "$(xdotool getwindowfocus)" png:- | xclip -t 'image/png' -selection 'clipboard' -i
;;
-g)
if [ ! -d "$DIR" ]; then
mkdir "$DIR"
fi
[ ! -d "$DIR" ] && mkdir "$DIR"
import -format png -window root "$DIR/$DATE.png"
"$HOME"/.local/bin/dunst_sound
printf '%s\n' "CAPTURA DE PANTALLA" "Guardando en: ~/Datos/Capturas" | msg
;;
-S)
if [ ! -d "$DIR/Select" ]; then
mkdir -p "$DIR/Select"
fi
[ ! -d "$DIR/Select" ] && mkdir -p "$DIR/Select"
sleep 1 && import -format png "$DIR/Select/select-$DATE.png"
"$HOME"/.local/bin/dunst_sound
printf '%s\n' "ÁREA SELECCIONADA" "Guardando en: ~/Datos/Capturas/select" | msg
;;
-F)
if [ ! -d "$DIR/Select" ]; then
mkdir -p "$DIR/Select"
fi
[ ! -d "$DIR/Select" ] && mkdir -p "$DIR/Select"
import -window "$(xdotool getwindowfocus)" -format png "$DIR/Select/window-$DATE.png"
;;
--help|-h|*)

View File

@ -2,12 +2,12 @@
# Dependencias: xinput
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
: "${script:="${0##*/}"}"
script="${0##*/}"
ayuda(){
cat << EOF
printf %s "\
Script para desactivar teclado interno en portátiles mientras se está en el servidor gráfico.
Uso: $script [arg]
@ -16,7 +16,7 @@ Uso: $script [arg]
$script off Desactiva teclado interno
$script --help, -h Muestra este mensaje de ayuda
EOF
"
}
# Salir si existe un error

View File

@ -1,26 +0,0 @@
#!/bin/sh
## V0.2
# Para poder utilizar la siguiente configuración se necesita de los siguiente:
# 1. i3lock
# 2. scrot
# 3. imagemagick
# 4. xautolock (opcional)
## Realizar captura de pantalla
#scrot /tmp/screenshot.png;
## Aplicar efecto difuso a imagen con ayuda de imagemagick
#convert /tmp/screenshot.png -blur 0x4 /tmp/screenshotblur.png;
## Utilizar imagen previa con i3lock
#i3lock -i /tmp/screenshotblur.png
## Para configurar el bloqueo automático de la pantalla se utiliza xautolock
xautolock -time 10 locker lock
#-------------------------------------------------------------------------------------------------------------------------
## Esta configuración funciona con i3lock-color
sleep 1; i3lock -k -B --blur --veriftext=Revisando --wrongtext=Incorrecto --keylayout 1 --insidevercolor=00ff38ff --insidewrongcolor=c10000ff --insidecolor=ffffff40 --ringvercolor=0020ffff --ringwrongcolor=e8df02ff --ringcolor=404090ff --linecolor=ffffffff --keyhlcolor=30ccccff --bshlcolor=ff8000ff --timecolor=000000ff

View File

@ -1,26 +0,0 @@
#!/bin/sh
## V0.2
# Para poder utilizar la siguiente configuración se necesita de los siguiente:
# 1. i3lock
# 2. scrot
# 3. imagemagick
# 4. xautolock (opcional)
## Realizar captura de pantalla
#scrot /tmp/screenshot.png;
## Aplicar efecto difuso a imagen con ayuda de imagemagick
#convert /tmp/screenshot.png -blur 0x4 /tmp/screenshotblur.png;
## Utilizar imagen previa con i3lock
#i3lock -i /tmp/screenshotblur.png
## Para configurar el bloqueo automático de la pantalla se utiliza xautolock
#xautolock -time 10 locker lock
#-------------------------------------------------------------------------------------------------------------------------
## Esta configuración funciona con i3lock-color
sleep 1; i3lock -k -B --blur=sigma --veriftext=Revisando --wrongtext=Incorrecto --keylayout 1 --insidevercolor=00ff38ff --insidewrongcolor=c10000ff --insidecolor=ffffff40 --ringvercolor=0020ffff --ringwrongcolor=e8df02ff --ringcolor=404090ff --linecolor=ffffffff --keyhlcolor=30ccccff --bshlcolor=ff8000ff --timecolor=000000ff

8
varios/lua/basename.lua Normal file
View File

@ -0,0 +1,8 @@
-- Copyright 2011-2014, Gianluca Fiore © <forod.g@gmail.com>
--- Function equivalent to basename in POSIX systems
--@param str the path string
function basename(str)
local name = string.gsub(str, "(.*/)(.*)", "%2")
return name
end

12
varios/lua/dirname.lua Normal file
View File

@ -0,0 +1,12 @@
-- Copyright 2011-2014, Gianluca Fiore © <forod.g@gmail.com>
--- Function equivalent to dirname in POSIX systems
--@param str the path string
function dirname(str)
if str:match(".-/.-") then
local name = string.gsub(str, "(.*/)(.*)", "%1")
return name
else
return ''
end
end

View File

@ -3,7 +3,7 @@
#
# Dependencias: dmenu, xdotool
#
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
RET=$(printf "Apagar\nReiniciar\nBloquear\nSuspender\nHibernar\nlogout\nCancelar" | dmenu -l 7 -p " Menu")

View File

@ -1,38 +0,0 @@
#!/bin/sh
## NOTA: este script aún está en fase de pruebas
## Convertir audio ogg a aac
#ffmpeg -i input.ogg -strict experimental -acodec aac output.aac
## Añadir audio a video
#ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a copy videoconaudio.mp4
## Cortar video
## Con -ss 00:01:30.0 le estoy diciendo que tome el video a partir del minuto 1:30 y
## luego con -t 00:00:10.0 le digo que tome los 10 segundos que siguen, es decir me
## creara un video de 10 segundos
#ffmpeg -i input.mp4 -ss 00:01:30 -t 00:00:10 -c copy output.mp4
## Para quitar audio a un video hacerlo del siguiente modo:
#ffmpeg -i $input_file -c copy -an $output_file
cd "$HOME" || exit
audio(){
if [ -f "$(find ./* -prune -name "audio*.ogg")" ]; then
mv audio*.ogg input.ogg
ffmpeg -i input.ogg -strict experimental -acodec aac audio.aac
fi
}
video(){
if [ -f "$(find ./* -prune -name "video*.mp4")" ]; then
mv video*.mp4 input.mp4
ffmpeg -i input.mp4 -i audio.aac -c:v copy -c:a copy final.mp4
fi
}
convert(){
audio && video
if [ -f "$HOME/final.mp4" ]; then
mv input.* audio.aac "$HOME/.local/share/Trash/files"
fi
}
convert && exit

70
varios/merge-video.sh Executable file
View File

@ -0,0 +1,70 @@
#!/bin/sh
#
# NOTA: este script aún está en fase de pruebas
# Convertir audio ogg a aac
# ffmpeg -i input.ogg -strict experimental -acodec aac output.aac
#
# Añadir audio a video
# ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a copy videoconaudio.mp4
#
# Cortar video
# Con -ss estoy indicando que tome el video a partir del minuto 00:05:10 y luego
# con -to 00:15:30 indico que relice un corte de video con duración de 10 minutos
# y 20 segundos
# ffmpeg -i input.mp4 -ss 00:05:10 -to 00:15:30 -c:v copy -c:a copy output2.mp4
#
# Para quitar audio a un video hacerlo del siguiente modo:
# ffmpeg -i $input_file -c copy -an $output_file
#
# Para unir videos primero crear un archivo de texto con el nombre de los videos a unir:
# vim lista.txt
# file 1.mp4
# file 2.mp4
#
# Unir los videos:
# ffmpeg -f concat -i lista.txt -c copy output.mp4
#
# Dependencias: ffmpeg, find
#
# Shell: POSIX compliant
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
script="${0##*/}"
ayuda() {
printf %s "\
Modo de uso: $script [OPCIÓN] [FICHERO, /path]
Ejemplos:
$script -c /path/file START END
$script --merge /path
Selección e interpretación de opciones:
-c, --cut Crea un clip cuya duaración estará basada en el punto de inicio y el punto final que
se indique del video de origen.
-m, --merge Fusiona audio y video
-h, --help Muestra esta ayuda y sale.
NOTA: Los argumentos START y END espeficarlos en formato de tiempo, ejemplo: 00:10:15 (horas, minutos y segundos)
"
}
case "$1" in
--cut|-c)
ffmpeg -i "$2" -ss "$3" -to "$4" -c:v copy -c:a copy "$(date '+%y%m%d_%H%M%S').mp4"
;;
--merge|-m)
if [ -n "$(count $2/*.oga)" ] && [ -n "$(count $2/*.mp4)" ]; then
cd $2 || exit
mv ./*.oga input.oga && mv video*.mp4 input.mp4
ffmpeg -i input.oga -strict experimental -acodec aac audio.aac
ffmpeg -i input.mp4 -i audio.aac -c:v copy -c:a copy "$(date '+%y%m%d_%H%M%S').mp4"
mv input.* audio.aac "$HOME"/.local/share/Trash/files
fi
;;
--help|-h|*)
ayuda
esac

View File

@ -1,21 +0,0 @@
#!/bin/ksh
# Finlandia
1() {
a=$(ping -c 3 -q alpha.de.repo.voidlinux.org | sed -n 5p | cut -d "/" -f 4)
echo "Finlandia $a"
}
# Chicago
2() {
b=$(ping -c 3 -q mirrors.servercentral.com | sed -n 5p | cut -d "/" -f 4)
echo "Chicago $b"
}
# Kansas City
3() {
c=$(ping -c 3 -q alpha.us.repo.voidlinux.org | sed -n 5p | cut -d "/" -f 4)
echo "Kansas City $c"
}
1;2;3

View File

@ -35,7 +35,7 @@ gcc -O3 -DNORL -DNOMOUSE -std=c11 -Wall -Wextra -Wshadow -I./netbsd-curses/libcu
src/nnn.c -Wl,-Bsymbolic-functions -lpthread -L./nnn-libs -lcurses -lterminfo -lfts -static
# Despojar binario de símbolos de depuración
strip nnn-static
strip "$BIN"
doas xbps-remove -Ry pkgconf gcc libtool automake
doas rm -r netbsd-curses musl-fts

View File

@ -2,9 +2,9 @@
# Dependencias sdhcp, wpa_supplicant, dzen2, sudo, doas (opcional)
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
: "${script:="${0##*/}"}"
script="${0##*/}"
deps() {
if ! command -v sdhcp; then
@ -20,7 +20,7 @@ deps() {
}
ayuda(){
cat << EOF
printf %s "\
Script para asignar ip dinámicamente usando sdhcp para establecer conexión a internet.
Uso: $script [interface]
@ -28,7 +28,7 @@ Uso: $script [interface]
$script eth0
$script wlan0
EOF
"
}
admin() {

View File

@ -2,9 +2,9 @@
# Dependencias iproute, wpa_supplicant, dzen2, sudo, doas (opcional)
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
: "${script:="${0##*/}"}"
script="${0##*/}"
deps() {
if ! command -v wpa_supplicant; then
@ -18,14 +18,15 @@ fi
ayuda(){
cat << EOF
printf %s "\
Script para establecer conexión a internet usando una dirección ip estática.
Uso: $script [interface]
Ejemplo:
$script eth0
$script wlan0
EOF
"
}
admin() {

553
varios/nuke-custom.sh Executable file
View File

@ -0,0 +1,553 @@
#!/bin/sh
# Description: Sample script to play files in apps by file type or mime
#
# Shell: POSIX compliant
# Usage: nuke filepath
#
# Integration with nnn:
# 1. Export the required config:
# export NNN_OPENER=/absolute/path/to/nuke
# # Otherwise, if nuke is in $PATH
# # export NNN_OPENER=nuke
# 2. Run nnn with the program option to indicate a CLI opener
# nnn -c
# # The -c program option overrides option -e
# 3. nuke can use nnn plugins (e.g. mocq is used for audio), $PATH is updated.
#
# Details:
# Inspired by ranger's scope.sh, modified for usage with nnn.
#
# Guards against accidentally opening mime types like executables, shared libs etc.
#
# Tries to play 'file' (1st argument) in the following order:
# 1. by extension
# 2. by mime (image, video, audio, pdf)
# 3. by mime (other file types)
# 4. by mime (prompt and run executables)
#
# Modification tips:
# 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps.
# 2. PAGER is "less -R".
# 3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required.
# 4. Some CLI utilities are piped to the $PAGER, to wait and quit uniformly.
# 5. If the output cannot be paged use "read -r _" to wait for user input.
# 6. On a DE, try 'xdg-open' or 'open' in handle_fallback() as last resort.
#
# Feel free to change the utilities to your favourites and add more mimes.
#
# Defaults:
# By extension (only the enabled ones):
# most archives: list with atool, bsdtar
# rar: list with unrar
# 7-zip: list with bsdtar
# pdf: zathura (GUI), pdftotext, mutool, exiftool
# audio: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool
# avi|mkv|mp4: mplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool
# log: vi
# torrent: rtorrent, transmission-show
# odt|ods|odp|sxw: odt2txt
# md: glow (https://github.com/charmbracelet/glow), lowdown (https://kristaps.bsd.lv/lowdown)
# htm|html|xhtml: w3m, lynx, elinks
# json: jq, python (json.tool module)
# Multimedia by mime:
# image/*: imv/sxiv/nsxiv (GUI), viu (https://github.com/atanunq/viu), img2txt, exiftool
# video/*: mplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool
# audio/*: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool
# application/pdf: zathura (GUI), pdftotext, mutool, exiftool
# Other mimes:
# text/troff: man -l
# text/* | */xml: vi
# image/vnd.djvu): djvutxt, exiftool
#
# TODO:
# 1. Adapt, test and enable all mimes
# 2. Clean-up the unnecessary exit codes
# set to 1 to enable GUI apps and/or BIN execution
GUI="${GUI:-0}"
BIN="${BIN:-0}"
set -euf -o noclobber -o noglob -o nounset
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
PATH=$PATH:"${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins"
IMAGE_CACHE_PATH="${1%/*}"/.thumbs
FPATH="$1"
FNAME="${1##*/}"
EDITOR="${VISUAL:-${EDITOR:-vi}}"
PAGER="${PAGER:-less -R}"
ext="${FNAME##*.}"
if [ -n "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi
is_mac() {
uname | grep -q "Darwin"
}
handle_pdf() {
if [ "$GUI" -ne 0 ]; then
if is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
elif type zathura >/dev/null 2>&1; then
nohup zathura "${FPATH}" >/dev/null 2>&1 &
else
return
fi
elif type pdftotext >/dev/null 2>&1; then
## Preview as text conversion
pdftotext -nopgbrk -q -- "${FPATH}" - | eval "$PAGER"
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | eval "$PAGER"
else
return
fi
exit 0
}
handle_audio() {
if type mocp >/dev/null 2>&1 && type mocq >/dev/null 2>&1; then
mocq "${FPATH}" "opener" >/dev/null 2>&1
elif type mpv >/dev/null 2>&1; then
mpv "${FPATH}" >/dev/null 2>&1 &
elif type mediainfo >/dev/null 2>&1; then
mediainfo "${FPATH}" | eval "$PAGER"
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}"| eval "$PAGER"
else
return
fi
exit 0
}
handle_video() {
if [ "$GUI" -ne 0 ]; then
if is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
elif type mplayer >/dev/null 2>&1; then
nohup mplayer "${FPATH}" >/dev/null 2>&1 &
elif type mpv >/dev/null 2>&1; then
nohup mpv "${FPATH}" >/dev/null 2>&1 &
else
return
fi
elif type ffmpegthumbnailer >/dev/null 2>&1; then
# Thumbnail
[ -d "/tmp/skynet/cache" ] || mkdir "/tmp/skynet/cache"
ffmpegthumbnailer -i "${FPATH}" -o "/tmp/skynet/cache/${FNAME}.jpg" -s 0
sxiv "/tmp/skynet/cache/${FNAME}.jpg" | eval "$PAGER"
#viu "/tmp/skynet/cache/${FNAME}.jpg" | eval "$PAGER"
elif type mediainfo >/dev/null 2>&1; then
mediainfo "${FPATH}" | eval "$PAGER"
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}"| eval "$PAGER"
else
return
fi
exit 0
}
# handle this extension and exit
handle_extension() {
case "${ext}" in
## Archive
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
if type atool >/dev/null 2>&1; then
atool --list -- "${FPATH}" | eval "$PAGER"
exit 0
elif type bsdtar >/dev/null 2>&1; then
bsdtar --list --file "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
rar)
if type unrar >/dev/null 2>&1; then
## Avoid password prompt by providing empty password
unrar lt -p- -- "${FPATH}" | eval "$PAGER"
fi
exit 1;;
7z)
## Avoid password prompt by providing empty password
if type bsdtar >/dev/null 2>&1; then
bsdtar --list --file "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
## PDF
pdf)
handle_pdf
exit 1;;
## Audio
aac|flac|m4a|mid|midi|mpa|mp2|mp3|ogg|wav|wma)
handle_audio
exit 1;;
## Video
avi|mkv|mp4)
handle_video
exit 1;;
## Log files
log)
"$EDITOR" "${FPATH}"
exit 0;;
## BitTorrent
torrent)
if type rtorrent >/dev/null 2>&1; then
rtorrent "${FPATH}"
exit 0
elif type transmission-show >/dev/null 2>&1; then
transmission-show -- "${FPATH}"
exit 0
fi
exit 1;;
## OpenDocument
odt|ods|odp|sxw)
if type odt2txt >/dev/null 2>&1; then
## Preview as text conversion
odt2txt "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
## Markdown
md)
if type glow >/dev/null 2>&1; then
glow -sdark "${FPATH}" | eval "$PAGER"
exit 0
elif type lowdown >/dev/null 2>&1; then
lowdown -Tterm "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
## HTML
htm|html|xhtml)
## Preview as text conversion
if type w3m >/dev/null 2>&1; then
w3m -dump "${FPATH}" | eval "$PAGER"
exit 0
elif type lynx >/dev/null 2>&1; then
lynx -dump -- "${FPATH}" | eval "$PAGER"
exit 0
elif type elinks >/dev/null 2>&1; then
elinks -dump "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
## JSON
json)
if type jq >/dev/null 2>&1; then
jq --color-output . "${FPATH}" | eval "$PAGER"
exit 0
elif type python >/dev/null 2>&1; then
python -m json.tool -- "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
esac
}
# sets the variable abs_target, this should be faster than calling printf
abspath() {
case "$1" in
/*) abs_target="$1";;
*) abs_target="$PWD/$1";;
esac
}
# storing the result to a tmp file is faster than calling listimages twice
listimages() {
find -L "///${1%/*}" -maxdepth 1 -type f -print0 |
grep -izZE '\.(jpe?g|png|gif|webp|tiff|bmp|ico|svg)$' |
sort -z | tee "$tmp"
}
load_dir() {
abspath "$2"
tmp="${TMPDIR:-/tmp}/nuke_$$"
trap 'rm -f $tmp' EXIT
count="$(listimages "$abs_target" | grep -a -m 1 -ZznF "$abs_target" | cut -d: -f1)"
if [ -n "$count" ]; then
if [ "$GUI" -ne 0 ]; then
xargs -0 nohup "$1" -n "$count" -- < "$tmp"
else
xargs -0 "$1" -n "$count" -- < "$tmp"
fi
else
shift
"$1" -- "$@" # fallback
fi
}
handle_multimedia() {
## Size of the preview if there are multiple options or it has to be
## rendered from vector graphics. If the conversion program allows
## specifying only one dimension while keeping the aspect ratio, the width
## will be used.
# local DEFAULT_SIZE="1920x1080"
mimetype="${1}"
case "${mimetype}" in
## SVG
# image/svg+xml|image/svg)
# convert -- "${FPATH}" "${IMAGE_CACHE_PATH}" && exit 6
# exit 1;;
## DjVu
# image/vnd.djvu)
# ddjvu -format=tiff -quality=90 -page=1 -size="${DEFAULT_SIZE}" \
# - "${IMAGE_CACHE_PATH}" < "${FPATH}" \
# && exit 6 || exit 1;;
## Image
image/*)
if [ "$GUI" -ne 0 ]; then
if is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type imv >/dev/null 2>&1; then
load_dir imv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type imvr >/dev/null 2>&1; then
load_dir imvr "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type sxiv >/dev/null 2>&1; then
load_dir sxiv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type nsxiv >/dev/null 2>&1; then
load_dir nsxiv "${FPATH}" >/dev/null 2>&1 &
exit 0
fi
elif type viu >/dev/null 2>&1; then
viu -n "${FPATH}" | eval "$PAGER"
exit 0
elif type img2txt >/dev/null 2>&1; then
img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER"
exit 0
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
# local orientation
# orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FPATH}" )"
## If orientation data is present and the image actually
## needs rotating ("1" means no rotation)...
# if [[ -n "$orientation" && "$orientation" != 1 ]]; then
## ...auto-rotate the image according to the EXIF data.
# convert -- "${FPATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
# fi
## `w3mimgdisplay` will be called for all images (unless overridden
## as above), but might fail for unsupported types.
exit 7;;
## PDF
application/pdf)
handle_pdf
exit 1;;
## Audio
audio/*)
handle_audio
exit 1;;
## Video
video/*)
handle_video
exit 1;;
# pdftoppm -f 1 -l 1 \
# -scale-to-x "${DEFAULT_SIZE%x*}" \
# -scale-to-y -1 \
# -singlefile \
# -jpeg -tiffcompression jpeg \
# -- "${FPATH}" "${IMAGE_CACHE_PATH%.*}" \
# && exit 6 || exit 1;;
## ePub, MOBI, FB2 (using Calibre)
# application/epub+zip|application/x-mobipocket-ebook|\
# application/x-fictionbook+xml)
# # ePub (using https://github.com/marianosimone/epub-thumbnailer)
# epub-thumbnailer "${FPATH}" "${IMAGE_CACHE_PATH}" \
# "${DEFAULT_SIZE%x*}" && exit 6
# ebook-meta --get-cover="${IMAGE_CACHE_PATH}" -- "${FPATH}" \
# >/dev/null && exit 6
# exit 1;;
## Font
# application/font*|application/*opentype)
# preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png"
# if fontimage -o "${preview_png}" \
# --pixelsize "120" \
# --fontname \
# --pixelsize "80" \
# --text " ABCDEFGHIJKLMNOPQRSTUVWXYZ " \
# --text " abcdefghijklmnopqrstuvwxyz " \
# --text " 0123456789.:,;(*!?') ff fl fi ffi ffl " \
# --text " The quick brown fox jumps over the lazy dog. " \
# "${FPATH}";
# then
# convert -- "${preview_png}" "${IMAGE_CACHE_PATH}" \
# && rm "${preview_png}" \
# && exit 6
# else
# exit 1
# fi
# ;;
## Preview archives using the first image inside.
## (Very useful for comic book collections for example.)
# application/zip|application/x-rar|application/x-7z-compressed|\
# application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar)
# local fn=""; local fe=""
# local zip=""; local rar=""; local tar=""; local bsd=""
# case "${mimetype}" in
# application/zip) zip=1 ;;
# application/x-rar) rar=1 ;;
# application/x-7z-compressed) ;;
# *) tar=1 ;;
# esac
# { [ "$tar" ] && fn=$(tar --list --file "${FPATH}"); } || \
# { fn=$(bsdtar --list --file "${FPATH}") && bsd=1 && tar=""; } || \
# { [ "$rar" ] && fn=$(unrar lb -p- -- "${FPATH}"); } || \
# { [ "$zip" ] && fn=$(zipinfo -1 -- "${FPATH}"); } || return
#
# fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \
# [ print(l, end='') for l in sys.stdin if \
# (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\
# sort -V | head -n 1)
# [ "$fn" = "" ] && return
# [ "$bsd" ] && fn=$(printf '%b' "$fn")
#
# [ "$tar" ] && tar --extract --to-stdout \
# --file "${FPATH}" -- "$fn" > "${IMAGE_CACHE_PATH}" && exit 6
# fe=$(echo -n "$fn" | sed 's/[][*?\]/\\\0/g')
# [ "$bsd" ] && bsdtar --extract --to-stdout \
# --file "${FPATH}" -- "$fe" > "${IMAGE_CACHE_PATH}" && exit 6
# [ "$bsd" ] || [ "$tar" ] && rm -- "${IMAGE_CACHE_PATH}"
# [ "$rar" ] && unrar p -p- -inul -- "${FPATH}" "$fn" > \
# "${IMAGE_CACHE_PATH}" && exit 6
# [ "$zip" ] && unzip -pP "" -- "${FPATH}" "$fe" > \
# "${IMAGE_CACHE_PATH}" && exit 6
# [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}"
# ;;
esac
}
handle_mime() {
mimetype="${1}"
case "${mimetype}" in
## Manpages
text/troff)
man -l "${FPATH}"
exit 0;;
## Text
text/* | */xml)
"$EDITOR" "${FPATH}"
exit 0;;
## Syntax highlight
# if [[ "$( stat --printf='%s' -- "${FPATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
# exit 2
# fi
# if [[ "$( tput colors )" -ge 256 ]]; then
# local pygmentize_format='terminal256'
# local highlight_format='xterm256'
# else
# local pygmentize_format='terminal'
# local highlight_format='ansi'
# fi
# env HIGHLIGHT_OPTIONS="${HIGHLIGHT_OPTIONS}" highlight \
# --out-format="${highlight_format}" \
# --force -- "${FPATH}" && exit 5
# pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}"\
# -- "${FPATH}" && exit 5
# exit 2;;
## DjVu
image/vnd.djvu)
if type djvutxt >/dev/null 2>&1; then
## Preview as text conversion (requires djvulibre)
djvutxt "${FPATH}" | eval "$PAGER"
exit 0
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
esac
}
handle_fallback() {
if [ "$GUI" -ne 0 ]; then
if type xdg-open >/dev/null 2>&1; then
nohup xdg-open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type open >/dev/null 2>&1; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
fi
fi
echo '----- File details -----' && file --dereference --brief -- "${FPATH}"
exit 1
}
handle_blocked() {
case "${MIMETYPE}" in
application/x-sharedlib)
exit 0;;
application/x-shared-library-la)
exit 0;;
application/x-executable)
exit 0;;
application/x-shellscript)
exit 0;;
application/octet-stream)
exit 0;;
esac
}
handle_bin() {
case "${MIMETYPE}" in
application/x-executable|application/x-shellscript)
clear
echo '-------- Executable File --------' && file --dereference --brief -- "${FPATH}"
printf "Run executable (y/N/'a'rgs)? "
read -r answer
case "$answer" in
[Yy]* ) exec "${FPATH}";;
[Aa]* )
printf "args: "
read -r args
exec "${FPATH}" "$args";;
[Nn]* ) exit;;
esac
esac
}
MIMETYPE="$( file -bL --mime-type -- "${FPATH}" )"
handle_extension
handle_multimedia "${MIMETYPE}"
handle_mime "${MIMETYPE}"
[ "$BIN" -ne 0 ] && [ -x "${FPATH}" ] && handle_bin
handle_blocked "${MIMETYPE}"
handle_fallback
exit 1

555
varios/nuke.sh Normal file
View File

@ -0,0 +1,555 @@
#!/usr/bin/env sh
# Description: Sample script to play files in apps by file type or mime
#
# Shell: POSIX compliant
# Usage: nuke filepath
#
# Integration with nnn:
# 1. Export the required config:
# export NNN_OPENER=/absolute/path/to/nuke
# # Otherwise, if nuke is in $PATH
# # export NNN_OPENER=nuke
# 2. Run nnn with the program option to indicate a CLI opener
# nnn -c
# # The -c program option overrides option -e
# 3. nuke can use nnn plugins (e.g. mocq is used for audio), $PATH is updated.
#
# Details:
# Inspired by ranger's scope.sh, modified for usage with nnn.
#
# Guards against accidentally opening mime types like executables, shared libs etc.
#
# Tries to play 'file' (1st argument) in the following order:
# 1. by extension
# 2. by mime (image, video, audio, pdf)
# 3. by mime (other file types)
# 4. by mime (prompt and run executables)
#
# Modification tips:
# 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps.
# 2. PAGER is "less -R".
# 3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required.
# 4. Some CLI utilities are piped to the $PAGER, to wait and quit uniformly.
# 5. If the output cannot be paged use "read -r _" to wait for user input.
# 6. On a DE, try 'xdg-open' or 'open' in handle_fallback() as last resort.
#
# Feel free to change the utilities to your favourites and add more mimes.
#
# Defaults:
# By extension (only the enabled ones):
# most archives: list with atool, bsdtar
# rar: list with unrar
# 7-zip: list with 7z
# pdf: zathura (GUI), pdftotext, mutool, exiftool
# audio: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool
# avi|mkv|mp4: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool
# log: vi
# torrent: rtorrent, transmission-show
# odt|ods|odp|sxw: odt2txt
# md: glow (https://github.com/charmbracelet/glow), lowdown (https://kristaps.bsd.lv/lowdown)
# htm|html|xhtml: w3m, lynx, elinks
# json: jq, python (json.tool module)
# Multimedia by mime:
# image/*: imv/sxiv/nsxiv (GUI), viu (https://github.com/atanunq/viu), img2txt, exiftool
# video/*: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool
# audio/*: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool
# application/pdf: zathura (GUI), pdftotext, mutool, exiftool
# Other mimes:
# text/troff: man -l
# text/* | */xml: vi
# image/vnd.djvu): djvutxt, exiftool
#
# TODO:
# 1. Adapt, test and enable all mimes
# 2. Clean-up the unnecessary exit codes
# set to 1 to enable GUI apps and/or BIN execution
GUI="${GUI:-0}"
BIN="${BIN:-0}"
set -euf -o noclobber -o noglob -o nounset
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
PATH=$PATH:"${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins"
IMAGE_CACHE_PATH="$(dirname "$1")"/.thumbs
FPATH="$1"
FNAME=$(basename "$1")
EDITOR="${VISUAL:-${EDITOR:-vi}}"
PAGER="${PAGER:-less -R}"
ext="${FNAME##*.}"
if [ -n "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi
is_mac() {
uname | grep -q "Darwin"
}
handle_pdf() {
if [ "$GUI" -ne 0 ]; then
if is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
elif type zathura >/dev/null 2>&1; then
nohup zathura "${FPATH}" >/dev/null 2>&1 &
else
return
fi
elif type pdftotext >/dev/null 2>&1; then
## Preview as text conversion
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER"
elif type mutool >/dev/null 2>&1; then
mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER"
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | eval "$PAGER"
else
return
fi
exit 0
}
handle_audio() {
if type mocp >/dev/null 2>&1 && type mocq >/dev/null 2>&1; then
mocq "${FPATH}" "opener" >/dev/null 2>&1
elif type mpv >/dev/null 2>&1; then
mpv "${FPATH}" >/dev/null 2>&1 &
elif type media_client >/dev/null 2>&1; then
media_client play "${FPATH}" >/dev/null 2>&1 &
elif type mediainfo >/dev/null 2>&1; then
mediainfo "${FPATH}" | eval "$PAGER"
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}"| eval "$PAGER"
else
return
fi
exit 0
}
handle_video() {
if [ "$GUI" -ne 0 ]; then
if is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
elif type smplayer >/dev/null 2>&1; then
nohup smplayer "${FPATH}" >/dev/null 2>&1 &
elif type mpv >/dev/null 2>&1; then
nohup mpv "${FPATH}" >/dev/null 2>&1 &
else
return
fi
elif type ffmpegthumbnailer >/dev/null 2>&1; then
# Thumbnail
[ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}"
ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0
viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER"
elif type mediainfo >/dev/null 2>&1; then
mediainfo "${FPATH}" | eval "$PAGER"
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}"| eval "$PAGER"
else
return
fi
exit 0
}
# handle this extension and exit
handle_extension() {
case "${ext}" in
## Archive
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
if type atool >/dev/null 2>&1; then
atool --list -- "${FPATH}" | eval "$PAGER"
exit 0
elif type bsdtar >/dev/null 2>&1; then
bsdtar --list --file "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
rar)
if type unrar >/dev/null 2>&1; then
## Avoid password prompt by providing empty password
unrar lt -p- -- "${FPATH}" | eval "$PAGER"
fi
exit 1;;
7z)
if type 7z >/dev/null 2>&1; then
## Avoid password prompt by providing empty password
7z l -p -- "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
## PDF
pdf)
handle_pdf
exit 1;;
## Audio
aac|flac|m4a|mid|midi|mpa|mp2|mp3|ogg|wav|wma)
handle_audio
exit 1;;
## Video
avi|mkv|mp4)
handle_video
exit 1;;
## Log files
log)
"$EDITOR" "${FPATH}"
exit 0;;
## BitTorrent
torrent)
if type rtorrent >/dev/null 2>&1; then
rtorrent "${FPATH}"
exit 0
elif type transmission-show >/dev/null 2>&1; then
transmission-show -- "${FPATH}"
exit 0
fi
exit 1;;
## OpenDocument
odt|ods|odp|sxw)
if type odt2txt >/dev/null 2>&1; then
## Preview as text conversion
odt2txt "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
## Markdown
md)
if type glow >/dev/null 2>&1; then
glow -sdark "${FPATH}" | eval "$PAGER"
exit 0
elif type lowdown >/dev/null 2>&1; then
lowdown -Tterm "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
## HTML
htm|html|xhtml)
## Preview as text conversion
if type w3m >/dev/null 2>&1; then
w3m -dump "${FPATH}" | eval "$PAGER"
exit 0
elif type lynx >/dev/null 2>&1; then
lynx -dump -- "${FPATH}" | eval "$PAGER"
exit 0
elif type elinks >/dev/null 2>&1; then
elinks -dump "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
## JSON
json)
if type jq >/dev/null 2>&1; then
jq --color-output . "${FPATH}" | eval "$PAGER"
exit 0
elif type python >/dev/null 2>&1; then
python -m json.tool -- "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
esac
}
# sets the variable abs_target, this should be faster than calling printf
abspath() {
case "$1" in
/*) abs_target="$1";;
*) abs_target="$PWD/$1";;
esac
}
# storing the result to a tmp file is faster than calling listimages twice
listimages() {
find -L "///${1%/*}" -maxdepth 1 -type f -print0 |
grep -izZE '\.(jpe?g|png|gif|webp|tiff|bmp|ico|svg)$' |
sort -z | tee "$tmp"
}
load_dir() {
abspath "$2"
tmp="${TMPDIR:-/tmp}/nuke_$$"
trap 'rm -f $tmp' EXIT
count="$(listimages "$abs_target" | grep -a -m 1 -ZznF "$abs_target" | cut -d: -f1)"
if [ -n "$count" ]; then
if [ "$GUI" -ne 0 ]; then
xargs -0 nohup "$1" -n "$count" -- < "$tmp"
else
xargs -0 "$1" -n "$count" -- < "$tmp"
fi
else
shift
"$1" -- "$@" # fallback
fi
}
handle_multimedia() {
## Size of the preview if there are multiple options or it has to be
## rendered from vector graphics. If the conversion program allows
## specifying only one dimension while keeping the aspect ratio, the width
## will be used.
# local DEFAULT_SIZE="1920x1080"
mimetype="${1}"
case "${mimetype}" in
## SVG
# image/svg+xml|image/svg)
# convert -- "${FPATH}" "${IMAGE_CACHE_PATH}" && exit 6
# exit 1;;
## DjVu
# image/vnd.djvu)
# ddjvu -format=tiff -quality=90 -page=1 -size="${DEFAULT_SIZE}" \
# - "${IMAGE_CACHE_PATH}" < "${FPATH}" \
# && exit 6 || exit 1;;
## Image
image/*)
if [ "$GUI" -ne 0 ]; then
if is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type imv >/dev/null 2>&1; then
load_dir imv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type imvr >/dev/null 2>&1; then
load_dir imvr "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type sxiv >/dev/null 2>&1; then
load_dir sxiv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type nsxiv >/dev/null 2>&1; then
load_dir nsxiv "${FPATH}" >/dev/null 2>&1 &
exit 0
fi
elif type viu >/dev/null 2>&1; then
viu -n "${FPATH}" | eval "$PAGER"
exit 0
elif type img2txt >/dev/null 2>&1; then
img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER"
exit 0
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
# local orientation
# orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FPATH}" )"
## If orientation data is present and the image actually
## needs rotating ("1" means no rotation)...
# if [[ -n "$orientation" && "$orientation" != 1 ]]; then
## ...auto-rotate the image according to the EXIF data.
# convert -- "${FPATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
# fi
## `w3mimgdisplay` will be called for all images (unless overridden
## as above), but might fail for unsupported types.
exit 7;;
## PDF
application/pdf)
handle_pdf
exit 1;;
## Audio
audio/*)
handle_audio
exit 1;;
## Video
video/*)
handle_video
exit 1;;
# pdftoppm -f 1 -l 1 \
# -scale-to-x "${DEFAULT_SIZE%x*}" \
# -scale-to-y -1 \
# -singlefile \
# -jpeg -tiffcompression jpeg \
# -- "${FPATH}" "${IMAGE_CACHE_PATH%.*}" \
# && exit 6 || exit 1;;
## ePub, MOBI, FB2 (using Calibre)
# application/epub+zip|application/x-mobipocket-ebook|\
# application/x-fictionbook+xml)
# # ePub (using https://github.com/marianosimone/epub-thumbnailer)
# epub-thumbnailer "${FPATH}" "${IMAGE_CACHE_PATH}" \
# "${DEFAULT_SIZE%x*}" && exit 6
# ebook-meta --get-cover="${IMAGE_CACHE_PATH}" -- "${FPATH}" \
# >/dev/null && exit 6
# exit 1;;
## Font
# application/font*|application/*opentype)
# preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png"
# if fontimage -o "${preview_png}" \
# --pixelsize "120" \
# --fontname \
# --pixelsize "80" \
# --text " ABCDEFGHIJKLMNOPQRSTUVWXYZ " \
# --text " abcdefghijklmnopqrstuvwxyz " \
# --text " 0123456789.:,;(*!?') ff fl fi ffi ffl " \
# --text " The quick brown fox jumps over the lazy dog. " \
# "${FPATH}";
# then
# convert -- "${preview_png}" "${IMAGE_CACHE_PATH}" \
# && rm "${preview_png}" \
# && exit 6
# else
# exit 1
# fi
# ;;
## Preview archives using the first image inside.
## (Very useful for comic book collections for example.)
# application/zip|application/x-rar|application/x-7z-compressed|\
# application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar)
# local fn=""; local fe=""
# local zip=""; local rar=""; local tar=""; local bsd=""
# case "${mimetype}" in
# application/zip) zip=1 ;;
# application/x-rar) rar=1 ;;
# application/x-7z-compressed) ;;
# *) tar=1 ;;
# esac
# { [ "$tar" ] && fn=$(tar --list --file "${FPATH}"); } || \
# { fn=$(bsdtar --list --file "${FPATH}") && bsd=1 && tar=""; } || \
# { [ "$rar" ] && fn=$(unrar lb -p- -- "${FPATH}"); } || \
# { [ "$zip" ] && fn=$(zipinfo -1 -- "${FPATH}"); } || return
#
# fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \
# [ print(l, end='') for l in sys.stdin if \
# (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\
# sort -V | head -n 1)
# [ "$fn" = "" ] && return
# [ "$bsd" ] && fn=$(printf '%b' "$fn")
#
# [ "$tar" ] && tar --extract --to-stdout \
# --file "${FPATH}" -- "$fn" > "${IMAGE_CACHE_PATH}" && exit 6
# fe=$(echo -n "$fn" | sed 's/[][*?\]/\\\0/g')
# [ "$bsd" ] && bsdtar --extract --to-stdout \
# --file "${FPATH}" -- "$fe" > "${IMAGE_CACHE_PATH}" && exit 6
# [ "$bsd" ] || [ "$tar" ] && rm -- "${IMAGE_CACHE_PATH}"
# [ "$rar" ] && unrar p -p- -inul -- "${FPATH}" "$fn" > \
# "${IMAGE_CACHE_PATH}" && exit 6
# [ "$zip" ] && unzip -pP "" -- "${FPATH}" "$fe" > \
# "${IMAGE_CACHE_PATH}" && exit 6
# [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}"
# ;;
esac
}
handle_mime() {
mimetype="${1}"
case "${mimetype}" in
## Manpages
text/troff)
man -l "${FPATH}"
exit 0;;
## Text
text/* | */xml)
"$EDITOR" "${FPATH}"
exit 0;;
## Syntax highlight
# if [[ "$( stat --printf='%s' -- "${FPATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
# exit 2
# fi
# if [[ "$( tput colors )" -ge 256 ]]; then
# local pygmentize_format='terminal256'
# local highlight_format='xterm256'
# else
# local pygmentize_format='terminal'
# local highlight_format='ansi'
# fi
# env HIGHLIGHT_OPTIONS="${HIGHLIGHT_OPTIONS}" highlight \
# --out-format="${highlight_format}" \
# --force -- "${FPATH}" && exit 5
# pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}"\
# -- "${FPATH}" && exit 5
# exit 2;;
## DjVu
image/vnd.djvu)
if type djvutxt >/dev/null 2>&1; then
## Preview as text conversion (requires djvulibre)
djvutxt "${FPATH}" | eval "$PAGER"
exit 0
elif type exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
esac
}
handle_fallback() {
if [ "$GUI" -ne 0 ]; then
if type xdg-open >/dev/null 2>&1; then
nohup xdg-open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif type open >/dev/null 2>&1; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
fi
fi
echo '----- File details -----' && file --dereference --brief -- "${FPATH}"
exit 1
}
handle_blocked() {
case "${MIMETYPE}" in
application/x-sharedlib)
exit 0;;
application/x-shared-library-la)
exit 0;;
application/x-executable)
exit 0;;
application/x-shellscript)
exit 0;;
application/octet-stream)
exit 0;;
esac
}
handle_bin() {
case "${MIMETYPE}" in
application/x-executable|application/x-shellscript)
clear
echo '-------- Executable File --------' && file --dereference --brief -- "${FPATH}"
printf "Run executable (y/N/'a'rgs)? "
read -r answer
case "$answer" in
[Yy]* ) exec "${FPATH}";;
[Aa]* )
printf "args: "
read -r args
exec "${FPATH}" "$args";;
[Nn]* ) exit;;
esac
esac
}
MIMETYPE="$( file -bL --mime-type -- "${FPATH}" )"
handle_extension
handle_multimedia "${MIMETYPE}"
handle_mime "${MIMETYPE}"
[ "$BIN" -ne 0 ] && [ -x "${FPATH}" ] && handle_bin
handle_blocked "${MIMETYPE}"
handle_fallback
exit 1

View File

@ -1,41 +0,0 @@
#!/bin/sh
BAR_HEIGHT=22 # polybar height
BORDER_SIZE=1 # border size from your wm settings
YAD_WIDTH=222 # 222 is minimum possible value
YAD_HEIGHT=193 # 193 is minimum possible value
DATE="$(date +"%a %d/%b/%Y - %R")"
case "$1" in
--popup)
if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
exit 0
fi
eval "$(xdotool getmouselocation --shell)"
eval "$(xdotool getdisplaygeometry --shell)"
# X
if [ "$((X + YAD_WIDTH / 2 + BORDER_SIZE))" -gt "$WIDTH" ]; then #Right side
: $((pos_x = WIDTH - YAD_WIDTH - BORDER_SIZE))
elif [ "$((X - YAD_WIDTH / 2 - BORDER_SIZE))" -lt 0 ]; then #Left side
: $((pos_x = BORDER_SIZE))
else #Center
: $((pos_x = X - YAD_WIDTH / 2))
fi
# Y
if [ "$Y" -gt "$((HEIGHT / 2))" ]; then #Bottom
: $((pos_y = HEIGHT - YAD_HEIGHT - BAR_HEIGHT - BORDER_SIZE))
else #Top
: $((pos_y = BAR_HEIGHT + BORDER_SIZE))
fi
yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \
--width=$YAD_WIDTH --height=$YAD_HEIGHT --posx=$pos_x --posy=$pos_y \
--title="yad-calendar" --borders=0 >/dev/null &
;;
*)
echo "$DATE"
;;
esac

216
varios/preview-tabbed-custom.sh Executable file
View File

@ -0,0 +1,216 @@
#!/usr/bin/env bash
# Description: tabbed/xembed based file previewer
#
# Dependencies:
# - tabbed (https://tools.suckless.org/tabbed): xembed host
# - xterm (or urxvt or st) : xembed client for text-based preview
# - mpv (https://mpv.io): xembed client for video/audio
# - sxiv (https://github.com/muennich/sxiv): xembed client for images
# - zathura (https://pwmt.org/projects/zathura): xembed client for PDF
# - nnn's nuke plugin for text preview and fallback
# nuke is a fallback for 'mpv', 'sxiv', and 'zathura', but has its
# own dependencies, see the script for more information
# - vim (or any editor/pager really)
# - file
# - mktemp
# - xdotool (optional, to keep main window focused)
#
# Usage:
# - Install the dependencies. Then set a NNN_FIFO
# and set a key for the plugin, then start `nnn`:
# $ NNN_FIFO=/tmp/nnn.fifo nnn
# - Launch the plugin with the designated key from nnn
#
# Notes:
# 1. This plugin needs a "NNN_FIFO" to work. See man.
# 2. If the same NNN_FIFO is used in multiple nnn instances, there will be one
# common preview window. With different FIFO paths, they will be independent.
#
# How it works:
# We use `tabbed` [1] as a xembed [2] host, to have a single window
# owning each previewer window. So each previewer must be a xembed client.
# For text previewers, this is not an issue, as there are a lot of
# xembed-able terminal emulator (we default to `xterm`, but examples are
# provided for `urxvt` and `st`). For graphic preview this can be trickier,
# but a few popular viewers are xembed-able, we use:
# - `mpv`: multimedia player, for video/audio preview
# - `sxiv`: image viewer
# - `zathura`: PDF viewer
# - but we always fallback to `nuke` plugin
#
# [1]: https://tools.suckless.org/tabbed/
# [2]: https://specifications.freedesktop.org/xembed-spec/xembed-spec-latest.html
#
# Shell: Bash (job control is weakly specified in POSIX)
# Author: Léo Villeveygoux
XDOTOOL_TIMEOUT=2
PAGER=${PAGER:-"vim -R"}
NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
if type urxvt >/dev/null 2>&1 ; then
TERMINAL="urxvt -embed"
elif type st >/dev/null 2>&1 ; then
TERMINAL="st -w"
else
echo "No xembed term found" >&2
fi
term_nuke () {
# $1 -> $XID, $2 -> $FILE
$TERMINAL "$1" -e "$NUKE" "$2" &
}
start_tabbed () {
FIFO="$(mktemp -u)"
mkfifo "$FIFO"
tabbed > "$FIFO" &
jobs # Get rid of the "Completed" entries
TABBEDPID="$(jobs -p %%)"
if [ -z "$TABBEDPID" ] ; then
echo "Can't start tabbed"
exit 1
fi
read -r XID < "$FIFO"
rm "$FIFO"
}
get_viewer_pid () {
VIEWERPID="$(jobs -p %%)"
}
kill_viewer () {
if [ -n "$VIEWERPID" ] && jobs -p | grep "$VIEWERPID" ; then
kill "$VIEWERPID"
fi
}
sigint_kill () {
kill_viewer
kill "$TABBEDPID"
exit 0
}
previewer_loop () {
unset -v NNN_FIFO
# mute from now
exec >/dev/null 2>&1
MAINWINDOW="$(xdotool getactivewindow)"
start_tabbed
trap sigint_kill SIGINT
xdotool windowactivate "$MAINWINDOW"
# Bruteforce focus stealing prevention method,
# works well in floating window managers like XFCE
# but make interaction with the preview window harder
# (uncomment to use):
#xdotool behave "$XID" focus windowactivate "$MAINWINDOW" &
while read -r FILE ; do
jobs # Get rid of the "Completed" entries
if ! jobs | grep tabbed ; then
break
fi
if [ ! -e "$FILE" ] ; then
continue
fi
kill_viewer
MIME="$(file -bL --mime-type "$FILE")"
case "$MIME" in
video/*)
if type mpv >/dev/null 2>&1 ; then
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
elif type ffplay >/dev/null 2>&1; then
ffplay -window_title preview -loop 0 "$FILE" &
elif type mplayer >/dev/null 2>&1 ; then
mplayer -nocache -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all -loop 0 -wid "$XID" "$FILE" &
elif type vlc >/dev/null 2>&1 ; then
vlc --loop --drawable-xid="$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
audio/*)
if type mpv >/dev/null 2>&1 ; then
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
elif type mplayer >/dev/null 2>&1 ; then
mplayer -loop 0 -wid "$XID" "$FILE" &
elif type vlc >/dev/null 2>&1 ; then
vlc --loop --drawable-xid="$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
image/*)
if type sxiv >/dev/null 2>&1 ; then
sxiv -ae "$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
application/pdf)
if type zathura >/dev/null 2>&1 ; then
zathura -e "$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
inode/directory)
$TERMINAL "$XID" -e nnn "$FILE" &
;;
text/*)
if [ -x "$NUKE" ] ; then
term_nuke "$XID" "$FILE"
else
# shellcheck disable=SC2086
$TERMINAL "$XID" -e $PAGER "$FILE" &
fi
;;
*)
if [ -x "$NUKE" ] ; then
term_nuke "$XID" "$FILE"
else
$TERMINAL "$XID" -e sh -c "file '$FILE' | $PAGER -" &
fi
;;
esac
get_viewer_pid
# following lines are not needed with the bruteforce xdotool method
ACTIVE_XID="$(xdotool getactivewindow)"
if [ $((ACTIVE_XID == XID)) -ne 0 ] ; then
xdotool windowactivate "$MAINWINDOW"
else
timeout "$XDOTOOL_TIMEOUT" xdotool behave "$XID" focus windowactivate "$MAINWINDOW" &
fi
done
kill "$TABBEDPID"
kill_viewer
}
if [ ! -r "$NNN_FIFO" ] ; then
echo "Can't read \$NNN_FIFO ('$NNN_FIFO')"
exit 1
fi
previewer_loop < "$NNN_FIFO" &
disown

216
varios/preview-tabbed.sh Normal file
View File

@ -0,0 +1,216 @@
#!/usr/bin/env bash
# Description: tabbed/xembed based file previewer
#
# Dependencies:
# - tabbed (https://tools.suckless.org/tabbed): xembed host
# - xterm (or urxvt or st) : xembed client for text-based preview
# - mpv (https://mpv.io): xembed client for video/audio
# - sxiv (https://github.com/muennich/sxiv) or,
# - nsxiv (https://codeberg.org/nsxiv/nsxiv) : xembed client for images
# - zathura (https://pwmt.org/projects/zathura): xembed client for PDF
# - nnn's nuke plugin for text preview and fallback
# nuke is a fallback for 'mpv', 'sxiv'/'nsxiv', and 'zathura', but has its
# own dependencies, see the script for more information
# - vim (or any editor/pager really)
# - file
# - mktemp
# - xdotool (optional, to keep main window focused)
#
# Usage:
# - Install the dependencies. Then set a NNN_FIFO
# and set a key for the plugin, then start `nnn`:
# $ NNN_FIFO=/tmp/nnn.fifo nnn
# - Launch the plugin with the designated key from nnn
#
# Notes:
# 1. This plugin needs a "NNN_FIFO" to work. See man.
# 2. If the same NNN_FIFO is used in multiple nnn instances, there will be one
# common preview window. With different FIFO paths, they will be independent.
# 3. This plugin only works on X, not on Wayland.
#
# How it works:
# We use `tabbed` [1] as a xembed [2] host, to have a single window
# owning each previewer window. So each previewer must be a xembed client.
# For text previewers, this is not an issue, as there are a lot of
# xembed-able terminal emulator (we default to `xterm`, but examples are
# provided for `urxvt` and `st`). For graphic preview this can be trickier,
# but a few popular viewers are xembed-able, we use:
# - `mpv`: multimedia player, for video/audio preview
# - `sxiv`/`nsxiv`: image viewer
# - `zathura`: PDF viewer
# - but we always fallback to `nuke` plugin
#
# [1]: https://tools.suckless.org/tabbed/
# [2]: https://specifications.freedesktop.org/xembed-spec/xembed-spec-latest.html
#
# Shell: Bash (job control is weakly specified in POSIX)
# Author: Léo Villeveygoux
XDOTOOL_TIMEOUT=2
PAGER=${PAGER:-"vim -R"}
NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
if [ -n "$WAYLAND_DISPLAY" ] ; then
echo "Wayland is not supported in preview-tabbed, this plugin could freeze your session!" >&2
exit 1
fi
if type xterm >/dev/null 2>&1 ; then
TERMINAL="xterm -into"
elif type urxvt >/dev/null 2>&1 ; then
TERMINAL="urxvt -embed"
elif type st >/dev/null 2>&1 ; then
TERMINAL="st -w"
else
echo "No xembed term found" >&2
fi
term_nuke () {
# $1 -> $XID, $2 -> $FILE
$TERMINAL "$1" -e "$NUKE" "$2" &
}
start_tabbed () {
FIFO="$(mktemp -u)"
mkfifo "$FIFO"
tabbed > "$FIFO" &
jobs # Get rid of the "Completed" entries
TABBEDPID="$(jobs -p %%)"
if [ -z "$TABBEDPID" ] ; then
echo "Can't start tabbed"
exit 1
fi
read -r XID < "$FIFO"
rm "$FIFO"
}
get_viewer_pid () {
VIEWERPID="$(jobs -p %%)"
}
kill_viewer () {
if [ -n "$VIEWERPID" ] && jobs -p | grep "$VIEWERPID" ; then
kill "$VIEWERPID"
fi
}
sigint_kill () {
kill_viewer
kill "$TABBEDPID"
exit 0
}
previewer_loop () {
unset -v NNN_FIFO
# mute from now
exec >/dev/null 2>&1
MAINWINDOW="$(xdotool getactivewindow)"
start_tabbed
trap sigint_kill SIGINT
xdotool windowactivate "$MAINWINDOW"
# Bruteforce focus stealing prevention method,
# works well in floating window managers like XFCE
# but make interaction with the preview window harder
# (uncomment to use):
#xdotool behave "$XID" focus windowactivate "$MAINWINDOW" &
while read -r FILE ; do
jobs # Get rid of the "Completed" entries
if ! jobs | grep tabbed ; then
break
fi
if [ ! -e "$FILE" ] ; then
continue
fi
kill_viewer
MIME="$(file -bL --mime-type "$FILE")"
case "$MIME" in
video/*)
if type mpv >/dev/null 2>&1 ; then
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
audio/*)
if type mpv >/dev/null 2>&1 ; then
mpv --force-window=immediate --loop-file --wid="$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
image/*)
if type sxiv >/dev/null 2>&1 ; then
sxiv -ae "$XID" "$FILE" &
elif type nsxiv >/dev/null 2>&1 ; then
nsxiv -ae "$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
application/pdf)
if type zathura >/dev/null 2>&1 ; then
zathura -e "$XID" "$FILE" &
else
term_nuke "$XID" "$FILE"
fi
;;
inode/directory)
$TERMINAL "$XID" -e nnn "$FILE" &
;;
text/*)
if [ -x "$NUKE" ] ; then
term_nuke "$XID" "$FILE"
else
# shellcheck disable=SC2086
$TERMINAL "$XID" -e $PAGER "$FILE" &
fi
;;
*)
if [ -x "$NUKE" ] ; then
term_nuke "$XID" "$FILE"
else
$TERMINAL "$XID" -e sh -c "file '$FILE' | $PAGER -" &
fi
;;
esac
get_viewer_pid
# following lines are not needed with the bruteforce xdotool method
ACTIVE_XID="$(xdotool getactivewindow)"
if [ $((ACTIVE_XID == XID)) -ne 0 ] ; then
xdotool windowactivate "$MAINWINDOW"
else
timeout "$XDOTOOL_TIMEOUT" xdotool behave "$XID" focus windowactivate "$MAINWINDOW" &
fi
done
kill "$TABBEDPID"
kill_viewer
}
if [ ! -r "$NNN_FIFO" ] ; then
echo "Can't read \$NNN_FIFO ('$NNN_FIFO')"
exit 1
fi
previewer_loop < "$NNN_FIFO" &
disown

107
varios/purge_pkgs.sh Executable file
View File

@ -0,0 +1,107 @@
#!/bin/sh
#
# Script que elimina paquetes de la caché que ya no están instalados en el sistema
#
# NOTA: En caso de usar doas, es necesario que en el archivo de configuración se
# tenga configurada la persistencia, de lo contrario por cada archivo por eliminar
# será necesario confirmar introduciendo lo contraseña.
#
# Lista de códigos de salida
# 0 - éxito
# 9 - operación exitosa, pero no se encontraron archivos para eliminar
# 10 - operación exitosa, pero no se eliminaron los archivos encontrados
# 11 - respuesta seleccionada inválida
# 12 - mensaje de ayuda mostrado
#
# Shell: POSIX compliant
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
script="${0##*/}"
ayuda () {
printf %s "\
$script ayuda a eliminar definitivamente aquellos paquetes que quedan guardados en la caché del sistema.
Modo de uso:
$script <argumento>
--list | -l Muestra una lista de los paquetes que la no están en uso
--help | -h Muestra este mensaje de ayuda
"
}
# Identificar cómo escalar permisos de administrador
admin () {
if command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then
echo sudo
elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then
echo doas
elif [ "$(id -u)" != 0 ]; then
echo su
fi
}
cache_dir=/var/cache/xbps
_arch=$(xbps-uhelper arch) # Obtener arquitectura
lista () {
# Obtener lista de paquetes instalados en el sistema
xbps-query -l | awk '{print $2}' > /tmp/installed.txt
# Obtener lista de paquetes en la caché del sistema
for package in /var/cache/xbps/*.xbps; do
base=${package##*/}
echo "${base%."$_arch".xbps}"
done > /tmp/cache.txt
_diff=$(diff /tmp/cache.txt /tmp/installed.txt | awk '/</ {print $2}')
if [ -n "$_diff" ]; then
# Mostrar lista de paquetes que no están en la caché y que no se encuentran instalados
printf '%s\n' "Los siguiente paquetes ya no se encuentran instalados en el sistema:"
printf '%s\n' "$_diff" | column
else
printf '%s\n' "No hay paquetes por eliminar"
exit 9
fi
}
case $1 in
-l|--list)
lista
printf '\n%s\n' "¿Deseas eliminar los paquetes? s/n"
read -r respuesta
case "$respuesta" in
[sS])
diff /tmp/cache.txt /tmp/installed.txt | awk '/</ {print $2}' > /tmp/delete.txt
echo "Ingrese la contraseña de administrador:"
echo "Eliminando los paquetes..."
while read -r pkg; do
cmd=$(admin)
if [ "$cmd" = "sudo" ]; then
sudo rm -fv "${cache_dir}/${pkg}.${_arch}.xbps"
elif [ "$cmd" = "doas" ]; then
doas rm -fv "${cache_dir}/${pkg}.${_arch}.xbps"
elif [ "$cmd" = "su" ]; then
su -c "rm -fv ${cache_dir}/${pkg}.${_arch}.xbps"
fi
done < /tmp/delete.txt
rm -f /tmp/*.txt
exit 0
;;
[nN])
rm -f /tmp/*.txt
exit 10
;;
*)
echo "Respuesta inválida."
rm -f /tmp/*.txt
exit 11
esac
;;
-h|--help|*)
ayuda
exit 12
esac

View File

@ -1,31 +0,0 @@
#!/bin/sh
## Script que aleatoriza wallpaper
## Dependencias: ImageMagick
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
deps() {
if ! command -v magick >/dev/null; then
printf '%s\n' "ImageMagick no disponible, instálelo"
return 1
fi
}
DIR_WALL="$HOME/Datos/Imágenes/Wallpapers"
RES=$(sed 's/,/x/g' /sys/class/graphics/fb?/virtual_size)
list() {
for file in "$DIR_WALL"/*; do
[ -f "$file" ] || continue
printf '%s\n' "$file"
done
}
WALLPAPER=$(list | grep -E '(jpeg|jpg|png)$' | sort -R | tail -1)
if deps; then
# Al añadir ! cuando se define la resolución, si la imagen
# tiene resolución pequeña la ajusta para ocupar toda la pantalla
# de tal forma que la imagen no quede en mosaico
display -resize "!$RES" -window root "$WALLPAPER"
fi

View File

@ -3,12 +3,12 @@
# Script para realizar capturas de pantalla
# Dependencias: scrot, xclip, dzen2
#
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
: "${script:="${0##*/}"}"
script="${0##*/}"
ayuda() {
cat << EOF
printf %s "\
Script para realizar capturas de pantalla.
Modo de uso:
$script [-PSgsh]
@ -20,7 +20,7 @@ Opciones:
-s: Guardar captura de pantalla de área seleccionada en disco duro
-h: Mostrar ayuda
EOF
"
}
msg() {

View File

@ -1,4 +1,8 @@
#!/bin/ksh
#!/bin/sh
# Script que muestra un panel con información del sistema
# Dependencias: xsetroot, alsa-utils, moc
#
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
while true;
do

View File

@ -12,7 +12,7 @@
# 13 - error no categorizado de otra manera
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
set -u # salir si una variable no ha sido declarada

View File

@ -1,19 +0,0 @@
#!/bin/sh
case $1 in
--toggle)
if [ "$(pgrep dropbox)" ]; then
pkill -f dropbox &
herbe "Dropbox ha sido apagado"
else
glibc dropbox &
herbe "Abriendo Dropbox"
fi
;;
*)
if [ "$(pgrep dropbox)" ]; then
herbe "Dropbpox ya está funcionando"
else
herbe "Dropbox desactivado"
fi;;
esac

View File

@ -1,3 +0,0 @@
#!/bin/sh
## Buscar en el directorio actual de forma no recursiva
find ~/.local/share/Trash/files/ -maxdepth 1 | wc -l

View File

@ -1,40 +0,0 @@
#!/bin/sh
# Script que revisa si existen actualizaciones disponibles para el sistema
# Dependencas: dzen2
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
set -u
TMP_UPDATES=/tmp/updates_void
[ -d "${TMP_UPDATES}" ] || mkdir "${TMP_UPDATES}"
xbps-install -nuM 1>"${TMP_UPDATES}"/updates 2>"${TMP_UPDATES}"/error
UPDATES="$(awk 'END {print NR}' "${TMP_UPDATES}"/updates)"
BROKEN="$(grep -c broken "${TMP_UPDATES}"/error)"
PKGS="$(awk '{print $1"\t"$2}' "${TMP_UPDATES}"/updates | column -t)"
deps() {
if ! command -v dzen2; then
printf '%b\n' "Dependencia no satisfecha:\n\tInstale dzen2\n"
exit 1
fi
}
msg() {
dzen2 -p -fn 'JetBrains Mono:size=8:style=bold' -ta 5 \
-w 260 -x 1100 -y 25 -l 10
}
if deps; then
if [ "$BROKEN" = 0 ] && [ "$UPDATES" -ge 1 ]; then
"$HOME"/Dropbox/Gitea/scripts/varios/dunst_sound
printf '%s\n' "ACTUALIZACIONES DISPONIBLES: $UPDATES" "$PKGS" | msg &
elif [ "$BROKEN" -ge 1 ]; then
printf '%s\n' "HAY PAQUETES ROTOS" "$(cut -d " " -f 1,5 "${TMP_UPDATES}"/error)" | msg &
fi
fi
exit 0

50
varios/updates-void.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/sh
# Script que revisa si existen actualizaciones disponibles para el sistema
# Dependencas: dzen2
#
# Lista de códigos de salida
# 0 - Operación exitosa
# 1 - Dependencia no cumplida
# 3 - Paquetes rotos
# 4 - Operación exitosa, pero no hubo cambios
#
# Shell: POSIX compliant
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
set -u
TMP_UPDATES=$(mktemp -d /tmp/updates_void.XXXX)
xbps-install -nuM 1>"${TMP_UPDATES}"/updates 2>"${TMP_UPDATES}"/error
UPDATES="$(awk 'END {print NR}' "${TMP_UPDATES}"/updates)"
BROKEN="$(grep -c broken "${TMP_UPDATES}"/error)"
PKGS="$(awk '{printf "%-30s %s\n", $1, $2}' "${TMP_UPDATES}"/updates)"
deps() {
if ! command -v dzen2 >/dev/null; then
printf '%b\n' "Dependencia no satisfecha:\n\tInstale dzen2\n"
exit 1
fi
}
msg() {
dzen2 -p -fn 'JetBrains Mono:size=8:style=bold' -ta 5 \
-w 260 -x 1100 -y 25 -l 10
}
if deps; then
if [ "$BROKEN" = 0 ] && [ "$UPDATES" -ge 1 ]; then
"$HOME"/Dropbox/Gitea/scripts/varios/dunst_sound
printf '%s\n' "ACTUALIZACIONES DISPONIBLES: $UPDATES" "$PKGS" | msg &
rm -r "${TMP_UPDATES}"
exit 0
elif [ "$BROKEN" -ge 1 ]; then
printf '%s\n' "HAY PAQUETES ROTOS" "$(awk '{printf "%-30s %s\n", $1, $5}' \
"${TMP_UPDATES}"/error)" | msg &
rm -r "${TMP_UPDATES}"
exit 3
else
[ -z "$UPDATES" ] || rm -r "${TMP_UPDATES}"
exit 4
fi
fi

View File

@ -1,95 +0,0 @@
#!/bin/sh
# Dependencias: udevil, dzen2
ayuda() {
cat << EOF
usb v2.0 (28/04/2022)
Modo de uso:
usb [-muUh]
Script para montar y desmontar dispositivos a través de devmon
Opciones:
-m Montar dispositivo extraible
-u Desmontar dispositivo extraible
-U Desmontar último pendrive insertado
-h Mostrar ayuda
EOF
}
admin(){
if [ "$(id -u)" = "0" ]; then
return
elif command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then
echo sudo
elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then
echo doas
else
echo su
fi
}
do_install() {
if [ "$SUDO" = su ]; then
su root -c 'xbps-install "$@"' -- sh "$@"
else
$SUDO xbps-install "$@"
fi
}
SUDO=$(admin)
if ! command -v udevil; then
printf '%b' "\033[31;5m[ERROR] No se encontró instalado el paquete 'udevil'\033[0m\n"
printf '%b' "\033[31;1mPreparándose para instalar el paquete 'udevil'...\033[0m\n"
do_install -Sy udevil
elif ! command -v dzen2; then
printf '%b' "\033[31;5m[ERROR] No se encontró instalado el paquete 'udevil'\033[0m\n"
printf '%b' "\033[31;1mPreparándose para instalar el paquete 'udevil'...\033[0m\n"
do_install -Sy dzen2
fi
msg() {
dzen2 -p 8 -e 'onstart=uncollapse' -fn 'JetBrains Mono:size=8:style=bold' -ta c \
-sa c -w 260 -x 1100 -y 25 -l 1
}
while :;
do
case $1 in
-m)
# Montar dispositivo extraible
devmon --sync --exec-on-drive "printf '%s\n' 'DISPOSITIVO USB' 'Listo para utilizarse'" | msg
break
;;
-u)
# Desmontar dispositivo
devmon --unmount /media/"$USER"/* && pkill -9 devmon
sleep 2; printf '%s\n' "DISPOSITIVO USB" "Puede retirarlo con seguridad" | msg
break
;;
-U)
# Desmontar último pendrive insertado
devmon --unmount-recent && sleep 2; printf '%s\n' "DISPOSITIVO USB" "Puede retirarlo con seguridad" | msg
break
;;
-h|--help)
ayuda
break
;;
*)
printf '%b' "\033[31;5mOpción inválida\033[0m\n"
printf '%b' "\033[37;2mOpciones disponibles:\033[0m\n"
printf '%b' "\033[32;1m-m: \033[36;2mMontar dispositivo extraible\033[0m\\033[0m\n"
printf '%b' "\033[32;1m-u: \033[36;2mDesmontar dispositivo\033[0m\\033[0m\n"
printf '%b' "\033[32;1m-U: \033[36;2mDesmontar último pendrive insertado\033[0m\\033[0m\n"
printf '%b' "\033[32;1m-h: \033[36;2mMostrar ayuda\033[0m\\033[0m\n\n"
return
esac
done
exit 0;

87
varios/usb.sh Executable file
View File

@ -0,0 +1,87 @@
#!/bin/sh
#usb v2.1
# Dependencias: udevil, dzen2
#
# Shell: POSIX compliant
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
script="${0##*/}"
ayuda() {
printf %s "\
Script para montar y desmontar dispositivos a través de devmon
Modo de uso:
$script [-muUh]
Opciones:
-m Montar dispositivo extraible
-u Desmontar dispositivo extraible
-U Desmontar último pendrive insertado
-h Mostrar ayuda
"
}
admin(){
if [ "$(id -u)" = "0" ]; then
return
elif command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then
echo sudo
elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then
echo doas
else
echo su
fi
}
do_install() {
if [ "$SUDO" = su ]; then
su root -c 'xbps-install "$@"' -- sh "$@"
else
$SUDO xbps-install "$@"
fi
}
SUDO=$(admin)
if ! command -v udevil >/dev/null; then
printf '%b' "\033[31;5m[ERROR] No se encontró instalado el paquete 'udevil'\033[0m\n"
printf '%b' "\033[31;1mPreparándose para instalar el paquete 'udevil'...\033[0m\n"
do_install -Sy udevil
elif ! command -v dzen2 >/dev/null; then
printf '%b' "\033[31;5m[ERROR] No se encontró instalado el paquete 'udevil'\033[0m\n"
printf '%b' "\033[31;1mPreparándose para instalar el paquete 'udevil'...\033[0m\n"
do_install -Sy dzen2
fi
msg() {
dzen2 -p 8 -e 'onstart=uncollapse' -fn 'JetBrains Mono:size=8:style=bold' -ta c \
-sa c -w 260 -x 1100 -y 25 -l 1
}
case $1 in
-m)
# Montar dispositivo extraible
devmon --sync --exec-on-device %f "printf '%s\n' 'Dispositivo USB' 'Listo para usarse'" | msg &
# if [ -d /media/"$USER"/* ]; then
# devmon --sync --exec-on-drive "printf '%s\n' 'DISPOSITIVO USB' 'Listo para utilizarse'" | msg &
# fi
break
;;
-u)
# Desmontar dispositivo
devmon --unmount /media/"$USER"/* && pkill -9 udevil
sleep 2; printf '%s\n' "DISPOSITIVO USB" "Puede retirarlo con seguridad" | msg &
break
;;
-U)
# Desmontar último pendrive insertado
devmon --unmount-recent && sleep 2; printf '%s\n' "DISPOSITIVO USB" "Puede retirarlo con seguridad" | msg &
break
;;
-h|--help|*)
ayuda
esac
exit 0

View File

@ -4,7 +4,7 @@
# Dependencias: alsa-utils
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
STATUS=$(amixer get Master | awk -F'[][]' 'END{ print $6 }')
LEVEL=$(amixer get Master | awk -F'[][]' 'END{ print $2 }')

View File

@ -2,32 +2,36 @@
# Alternar estado de conexión wifi
# Mac fc:01:7c:9a:bb:d9 corresponde a la tarjeta interna
# Mac 50:3e:aa:2c:70:d0 corresponde a la tarjeta externa
# Dependencias: dzen2, wpa_supplicant
#
# Shell: POSIX compliant
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
read -r state < /sys/class/net/wlan0/operstate
read -r STATE < /sys/class/net/wlan0/operstate
msg() {
dzen2 -p 8 -e -fn 'JetBrains Mono:size=8:style=bold' -ta c \
-w 260 -x 1100 -y 25
dzen2 -p 8 -e -fn 'JetBrains Mono:size=8:style=bold' -ta 5 \
-w 260 -x 1100 -y 25
}
case "$1" in
--toggle)
if [ "$(pgrep wpa_supplicant)" ]; then
doas pkill -f wpa_supplicant
printf '%s\n' "Wifi desactivado" | msg
printf '%s\n' "Wifi desactivado" | msg &
else
if [ "$state" = "down" ]; then
if [ "$STATE" = "down" ]; then
#doas wpa_supplicant -B -D wext -c /etc/wpa_supplicant/wpa_supplicant-wlan0.conf -i wlan1
doas wpa_supplicant -B -D wext -c /etc/wpa_supplicant/wpa_supplicant-wlan0.conf -i wlan0
sleep 2; printf '%s\n' "Activando wifi..." | msg
sleep 2; printf '%s\n' "Activando wifi..." | msg &
fi
fi
;;
*)
if [ "$(pgrep wpa_supplicant)" ]; then
printf '%s\n' "Wifi activado" | msg
printf '%s\n' "Wifi activado" | msg &
else
printf '%s\n' "Wifi desactivado" | msg
printf '%s\n' "Wifi desactivado" | msg &
fi
esac

View File

@ -4,13 +4,12 @@
# Dependencias: xbps-src, xtools, dzen2
#
# Shell: POSIX compliant
# Autor: Tuxliban Torvalds <o-sanchez@linuxmail.org>
# Autor: O. Sánchez <o-sanchez@linuxmail.org>
set -u
set -x
unset POSIXLY_CORRECT
TMP_DIR=/tmp/xpkglocal
TMP_DIR=$(mktemp /tmp/xpkglocal.XXXXXXXXXX)
mkdir "${TMP_DIR}"
which_sudo() {
@ -56,7 +55,7 @@ if [ ! -f "$HOME/void-packages/xbps-src" ]; then
fi
# Crear lista de actualizaciones disponibles
touch "${TMP_DIR}"/releases
:> "${TMP_DIR}"/releases
cd "$HOME"/void-packages || exit
for package in $(xpkg -m); do

55
varios/xrankmirrors.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
## credits to https://paste.sh/1QS8Tgf6#aHTfRy1dOG4rcA5x_6kauwq3
pkg=current/xbps-0.59.1_6.x86_64.xbps
file="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-results"
mirrormsg() { printf '%s\n' "getting mirrors from void-docs..." ; }
get() {
rm "$file"
while read -r syntax mirror _ loc; do
case $syntax in
\|)
case $mirror in
Repository) ;;
*)
mirror="${mirror#<}"
mirror="${mirror%>}"
loc="${loc% |}"
loc="${loc%%,*}"
[ -n "${REGION}" ] && {
[ "${REGION}" = get ] && printf '%s\n' "$loc" && continue
[ ! "${loc%%:*}" = "${REGION}" ] && continue
}
printf '%s\n' "$mirror"
dlspeed="$(curl -Y 1048576 -# -w "%{speed_download}" "$mirror/$pkg" -o/dev/null)"
connect=$(printf "%.2fs" "$(curl --connect-timeout 2 -sw "%{time_appconnect}" "$mirror" -o/dev/null)")
echo "${mirror},${loc},${dlspeed},${connect}" >> "$file"
;;
esac
;;
esac
done <<< "$(curl -# https://raw.githubusercontent.com/void-linux/void-docs/master/src/xbps/repositories/mirrors/index.md)"
#echo "finished writing results of mirrors to $file"
}
format() {
sort -t, -nrk3 < "$file" | numfmt -d , --field 3 --to=iec-i --suffix=B/s | sed '1s/^/mirror,location,dlspeed,connect\n/' | column -s, -t
}
case "$1" in
-g) mirrormsg && get ;;
-f) format ;;
-r) REGION="$2"; mirrormsg && get ;;
-p) REGION="get"; mirrormsg && get | sed '1s/^/region: location\n/' | column -s: -t ;;
*) cat <<EOF
usage: ${0##*/} [-g] [-f]
-g get results and write to file
-f format results file
-r get results from specific region if available
-p print available regions and locations
file: $file
EOF
esac