nix-configuration/.zsh/dingleberry/09-zsh_aliases.zsh
2025-01-04 00:08:37 +01:00

126 lines
3.4 KiB
Bash
Executable File

# Docker
alias drone="source /self/storage/.circuitry/.secret/drone.shinc && /usr/local/bin/drone"
alias drone-ys="source /self/storage/.circuitry/.secret/drone-ys.shinc && /usr/local/bin/drone@1"
alias gitPruneRemote="~/circuitry/scripts/pruneGit remote"
alias gitPruneLocal="~/circuitry/scripts/pruneGit local"
#
# LVM
#
lvBackup() {
if [[ $(sudo lvs | grep root | wc -l) -gt 1 ]]; then
echo "There are several mentions of root volume"
return
fi
DEVICE=$(sudo lvs | grep root | awk '{print $2}')
VOL_NAME=$(sudo lvs | grep root | awk '{print $1}')
if [[ ${DEVICE} != "" ]]; then
sudo lvcreate -s -n backup -L4.75G /dev/${DEVICE}/${VOL_NAME}
else
echo "Could not find the root device"
fi
}
lvBackupRemove() {
if [[ $(sudo lvs | grep backup | wc -l) -gt 1 ]]; then
echo "There are several mentions of backup volume"
return
fi
DEVICE=$(sudo lvs | grep backup | awk '{print $2}')
VOL_NAME=$(sudo lvs | grep backup | awk '{print $1}')
if [[ ${DEVICE} != "" ]]; then
sudo lvremove /dev/${DEVICE}/${VOL_NAME}
else
echo "Could not find the backup device"
fi
}
convertSubtitles() {
local subtitleFile="${1}"
iconv -f windows-1250 -t utf-8 "${subtitleFile}" > "${subtitleFile}.utf8" && \
rm "${subtitleFile}" && \
mv "${subtitleFile}.utf8" "${subtitleFile}"
}
function scanMultiPdf() {
local keepScanning=1
local scanNumber=1
local filename="$1"
local inputFilenames=()
local prefix=$(dd if=/dev/urandom count=1 bs=128 status=none | md5sum -b | cut -d ' ' -f 1)
local currentFile
if [[ "${filename}" == "" ]]; then
echo "You must provide a filename as first argument"
return 1
fi
# This initializes devices if freshly connected
echo "Scanning for devices, please wait..."
scanimage --list-devices > /dev/null 2>&1
while [[ 1 ]]; do
currentFile="/tmp/scan.${prefix}.${scanNumber}.pdf"
scanToPdf "${currentFile}"
if [[ ! -f "${currentFile}" ]]; then
echo "Failed to scan, try again? [(y)/n]"
read CONTINUE
if [[ "${CONTINUE}" != "" ]] && [[ "${CONTINUE}" != "y" ]]; then
break
fi
continue
fi
inputFilenames+=("${currentFile}")
echo "Continue scanning? [(y)/n]"
read CONTINUE
if [[ "${CONTINUE}" != "" ]] && [[ "${CONTINUE}" != "y" ]]; then
break
fi
scanNumber=$((scanNumber+1))
done
if [[ ${#inputFilenames[@]} -gt 0 ]]; then
pdfunite ${inputFilenames[@]} "${filename}"
fi
rm -f "/tmp/scan.${prefix}."*
}
function scanToPdf()
{
local output=$1
local tempOutput="/tmp/scan.pnm"
if [[ $output == "" ]]; then
output="scan.pdf"
fi
# scan and rotate to fix the scanner rotation using pnmrotate and pnmcut
scanimage -x 216 -y 297 > "${tempOutput}" && \
#pnmrotate -1 "${tempOutput}" > "${tempOutput}.rotated" && \
#pnmcut -top=42 -bottom=-45 -left=62 -right=-64 "${tempOutput}.rotated" > "${tempOutput}" && \
convertPnmToPdf "${tempOutput}" && \
mv output.pdf ${output}
rm -f "${tempOutput}.rotated"
rm -f "${tempOutput}"
}
function convertPnmToPdf()
{
local tempOutput="/tmp/concat.pdf"
convert $@ "${tempOutput}" && \
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf "${tempOutput}"
rm -f "${tempOutput}"
}