New aliases

This commit is contained in:
Sebastian Lenzlinger
2024-05-08 15:06:26 +02:00
parent 14dfa6a57e
commit b95d071caa
12 changed files with 423 additions and 27 deletions

View File

@@ -0,0 +1,19 @@
#! /usr/bin/env bash
filename=$1
rmpattern=$2
suffix=$3
dstFolder="${PWD}/arranged"
newFilename="${filename%${rmpattern}}${suffix}.pdf"
# Make destination folder
mkdir -p ${dstFolder}
pdfjam --nup 2x2 \
--landscape \
--clip 'true' \
--delta '0cm 0cm' \
--offset '1cm 0cm' \
--outfile ${newFilename} ${filename}
mv ${newFilename} ${dstFolder}
# unused
# --trim '0.7cm 0cm 0.7cm 0cm' \

13
bash/scripts/scripts/arrangefai Executable file
View File

@@ -0,0 +1,13 @@
#! /usr/bin/env bash
file=$1
outfile="${file%'handout.pdf'}jam4.pdf"
dst=${PWD}/jammed
mkdir -p ${dst}
pdfjam --nup 2x2 --column false \
--landscape --offset '1.2cm 0cm' \
--outfile ${outfile} --scale 0.95 \
--frame true \
$1
mv ${outfile} ${dst}

195
bash/scripts/scripts/chatroom Executable file
View File

@@ -0,0 +1,195 @@
#!/usr/bin/env bash
################################################################################
## Author: Sebastian Lenzlinger
## EMail: eswer@eswo.ch
################################################################################
################################################################################
# TIPP: source this file so functions are available directly in the command line
################################################################################
initialize () {
if [[ $# -ne 1 ]]; then
echo "Usage: initialize '<name>'"
echo "Please only supply your name as a single string"
echo "This will be used as the branch name."
return
fi
usrnm=$1
# Create repo 'usrnm' with branch 'usrnm'
git init -b "${usrnm}" "${usrnm}" && cd "${usrnm}"
echo "Initialized git repo ${usrnm} with branch ${usrnm}"
git config --local user.name "${usrnm}"
git config --local user.email "${usrnm}@gitchat.local"
# Establish tree object
treeroot=$(git write-tree)
echo "Tree written at ref "${treeroot}"."
# Create initial commit without parent commits
initcommit="$(echo "${usrnm} has joined the chatroom." | git commit-tree "${treeroot}")"
echo "Initial commit "${initcommit}" with message "$(git cat-file -p ${initcommit})"."
#Set HEAD of usrnm branch to first commit
git update-ref "$(git symbolic-ref HEAD)" "${initcommit}"
}
post() {
if ! [[ -d "${PWD}/.git" ]]; then
echo "You must be in a git repo root to use this command!"
return
fi
# Single quotes so can use any spacial characters that bash would expand.
if [[ $# -ne 1 ]]; then
echo "Please supply you message in single quotes!"
echo "Usage: post '<msg>'"
return
fi
msg=$1
# this seems to be the way; assuming there is one tree
roottreeref=$(git log --pretty=format:%T -n 1)
if [[ -z "${roottreeref}" ]]; then
echo "NO TREE: Couldnt find tree object."
return
fi
echo "Root trees ref "${roottreeref}""
parents=
for p in $(git for-each-ref --format='%(objectname)' refs/heads/); do
parents+="-p ${p} "
done
echo "Parent commits ${parents}"
# This didn't work!!!
# roottreeref=($(git cat-file --batch-all-objects --batch-check | grep tree))
# Put message at end so last whitespace is ignored, doesn't lead to issues
commitref="$(git commit-tree ${roottreeref} ${parents} -m "${msg}")"
echo "Current commits ref ${commitref}"
git update-ref "$(git symbolic-ref HEAD)" "${commitref}"
echo
echo "Posted message:"
echo "${msg}"
unset roottreeref
unset parents
unset commitref
unset msg
}
show() {
if ! [[ -d "${PWD}/.git" ]]; then
echo "You must be in a git repo root to use this command!"
return
fi
# This is not correct, only follow local branches, not remote branches.
#for b in $(git branch --format '%(refname:short)'); do
#git log $b --pretty=format:'%C(bold)%an (%ar):%C(reset) %s' --reverse
#done
if [[ $# -gt 1 ]];then
echo "There is only one OPTIONAL argument: -g"
return
fi
gopt=
if [[ $1 = "-g" ]]; then gopt="--graph";
fi
git log --pretty=format:'%C(bold)%Cred%an (%Cgreen%cd):%Creset %s' \
--date=format:'%d-%m-%y--%H:%M' ${gopt}
}
# $usrto is the remote name. $usrfrom is a branch name.
disseminate () {
if ! [[ -d "${PWD}/.git" ]]; then
echo "You must be in a git repo root to use this command!"
return
fi
if [[ $# -ne 1 ]]; then
echo "Usage: disseminate <remote-user-name>"
echo "Please supply the name of the user you wish to send your message to!"
return
fi
usrfrom="$(git branch --show-current)"
usrto="$1"
# Ensure remote exists
if ! git remote get-url "$usrto" > /dev/null 2>&1; then
echo "No such remote. You must first add a remote for ${usrto}"
echo "How to add: git remote add $usrto <Repo-Url>"
return
fi
if ! git push "${usrto}" "${usrfrom}"; then
echo "Failed to push to ${usrto}. Check permissions or network issues."
return
fi
}
################################################################################
# Don't use described commands. Not sure if safe.
fetch-peers() {
echo "Example to fetch all branches from a remote 'bob':"
echo "git fetch bob"
}
pull-remote() {
echo "Example to pull changes from a specific branch on 'bob' remote:"
echo "git pull bob <branch-name>"
}
info() {
echo "================================================="
echo "Adding a remote:"
echo "================================================="
echo "git remote add <remote-name> <url-of-remote>"
echo "Note that <remote-name> can be chosen arbitrarily"
echo
echo "================================================="
echo "PUSHing to remote branch:"
echo "================================================="
echo "git push <remote-name> <the-local-branch-to-push>"
echo "Example: Push branch 'Carol' to remote 'bob'"
echo "git push bob Carol"
echo "After this the remote 'bob' will have everything from your branch 'Carol' also on a branch called 'Carol'"
echo
echo "WARNING: Do not use 'git push Bob Carol' if you added remote 'bob' like this: 'git remote add bob ../Bob'"
echo "This only means that you are adding a remote in .git/refs/remote, not a branch on your part."
echo
echo "================================================="
echo "Some others:"
echo "================================================="
fetch-peers
echo
echo
pull-remote
echo
echo "END INFO"
}
echo "To use the functions, source this file from the command line:"
echo "'source path/to/chatroom' or just 'source chatroom' if it is in the same directory."
echo "After this the functions are available for the duration of your bash session as if they where built-in commands!"
echo "That means to call the initialize function just type 'initialize' NOT './initialize'"
echo "You will see this message again when you source the file."
################################################################################
# Useful for debugging
################################################################################
alias glog="git log --oneline --graph"
alias gloga="git log --oneline --graph --all"

View File

@@ -0,0 +1,9 @@
#! /usr/bin/bash
filename=$1
arrangedFolder=${PWD}/arranged
newFilename=${filename:0:3}db23-arranged.pdf
echo "Arranging $filename"
/usr/bin/pdfjam --nup 2x2 --landscape --outfile $newFilename $filename
echo "Moving $new-filename to $arranged-folder"
mv $newFilename $arrangedFolder
echo "Done"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
qpdf --empty --pages $(ls -l | grep -v '^d' | sort) -- "$1.pdf"

37
bash/scripts/scripts/mergepdfs Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Check if qpdf is installed
if ! command -v qpdf &> /dev/null; then
echo "Error: qpdf could not be found. Please install qpdf."
exit 1
fi
# Target PDF filename
output_pdf="$1.pdf"
if [[ -z "$1" ]]; then
echo "Usage: $0 <output-file-base-name>"
exit 1
fi
# Prepare an array to hold the PDF files
pdf_files=()
shopt -s nullglob
for file in *.pdf; do
pdf_files+=("$file")
done
# Check if we found any PDF files
if [[ ${#pdf_files[@]} -eq 0 ]]; then
echo "No PDF files found in the current directory."
exit 1
fi
# Sort files just in case
IFS=$'\n' pdf_files=($(sort <<<"${pdf_files[*]}"))
unset IFS
# Run qpdf to combine PDF files
qpdf --empty --pages "${pdf_files[@]}" -- "$output_pdf"
echo "PDF files combined into $output_pdf"

View File

@@ -0,0 +1,10 @@
#! /usr/bin/bash
filename=$1
arrangedFolder=${PWD}/arranged
newFilename=${filename}-pr23-arranged.pdf
echo "Arranging $filename"
/usr/bin/pdfjam --nup 2x1 --landscape --outfile $newFilename $filename
echo "Moving $newFilename to $arrangedFolder"
mv $newFilename $arrangedFolder
echo "Done"